]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/AsyncCall.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / base / AsyncCall.cc
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "AsyncCall.h"
11 #include "base/AsyncCall.h"
12 #include "base/AsyncCallQueue.h"
13 #include "cbdata.h"
14 #include "Debug.h"
15 #include <ostream>
16
17 InstanceIdDefinitions(AsyncCall, "call");
18
19 /* AsyncCall */
20
21 AsyncCall::AsyncCall(int aDebugSection, int aDebugLevel,
22 const char *aName): name(aName), debugSection(aDebugSection),
23 debugLevel(aDebugLevel), theNext(0), isCanceled(NULL)
24 {
25 debugs(debugSection, debugLevel, "The AsyncCall " << name << " constructed, this=" << this <<
26 " [" << id << ']');
27 }
28
29 AsyncCall::~AsyncCall()
30 {
31 assert(!theNext); // AsyncCallQueue must clean
32 }
33
34 void
35 AsyncCall::make()
36 {
37 debugs(debugSection, debugLevel, HERE << "make call " << name <<
38 " [" << id << ']');
39 if (canFire()) {
40 fire();
41 return;
42 }
43
44 if (!isCanceled) // we did not cancel() when returning false from canFire()
45 isCanceled = "unknown reason";
46
47 debugs(debugSection, debugLevel, HERE << "will not call " << name <<
48 " [" << id << ']' << " because of " << isCanceled);
49 }
50
51 bool
52 AsyncCall::cancel(const char *reason)
53 {
54 debugs(debugSection, debugLevel, HERE << "will not call " << name <<
55 " [" << id << "] " << (isCanceled ? "also " : "") <<
56 "because " << reason);
57
58 isCanceled = reason;
59 return false;
60 }
61
62 bool
63 AsyncCall::canFire()
64 {
65 return !isCanceled;
66 }
67
68 /// \todo make this method const by providing a const getDialer()
69 void
70 AsyncCall::print(std::ostream &os)
71 {
72 os << name;
73 if (const CallDialer *dialer = getDialer())
74 dialer->print(os);
75 else
76 os << "(?" << this << "?)";
77 }
78
79 void
80 AsyncCall::dequeue(AsyncCall::Pointer &head, AsyncCall::Pointer &prev)
81 {
82 if (prev != NULL)
83 prev->setNext(Next());
84 else
85 head = Next();
86 setNext(NULL);
87 }
88
89 bool
90 ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
91 {
92 debugs(call->debugSection, call->debugLevel, fileName << "(" << fileLine <<
93 ") will call " << *call << " [" << call->id << ']' );
94 AsyncCallQueue::Instance().schedule(call);
95 return true;
96 }
97