]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
582c2af2 | 9 | #include "squid.h" |
314782d4 | 10 | #include "AsyncCall.h" |
882255af AR |
11 | #include "base/AsyncCall.h" |
12 | #include "base/AsyncCallQueue.h" | |
3e5c8cf4 | 13 | #include "cbdata.h" |
582c2af2 | 14 | #include "Debug.h" |
d977f933 AJ |
15 | #include <ostream> |
16 | ||
52ed047a | 17 | InstanceIdDefinitions(AsyncCall, "call"); |
3e5c8cf4 | 18 | |
3e5c8cf4 | 19 | /* AsyncCall */ |
854d4d81 | 20 | |
3e5c8cf4 | 21 | AsyncCall::AsyncCall(int aDebugSection, int aDebugLevel, |
26ac0430 | 22 | const char *aName): name(aName), debugSection(aDebugSection), |
f53969cc | 23 | debugLevel(aDebugLevel), theNext(0), isCanceled(NULL) |
854d4d81 | 24 | { |
3e5c8cf4 | 25 | debugs(debugSection, debugLevel, "The AsyncCall " << name << " constructed, this=" << this << |
52ed047a | 26 | " [" << id << ']'); |
854d4d81 | 27 | } |
28 | ||
3e5c8cf4 | 29 | AsyncCall::~AsyncCall() |
854d4d81 | 30 | { |
3e5c8cf4 | 31 | assert(!theNext); // AsyncCallQueue must clean |
854d4d81 | 32 | } |
33 | ||
3e5c8cf4 | 34 | void |
35 | AsyncCall::make() | |
854d4d81 | 36 | { |
3e5c8cf4 | 37 | debugs(debugSection, debugLevel, HERE << "make call " << name << |
52ed047a | 38 | " [" << id << ']'); |
3e5c8cf4 | 39 | if (canFire()) { |
40 | fire(); | |
41 | return; | |
42 | } | |
854d4d81 | 43 | |
3e5c8cf4 | 44 | if (!isCanceled) // we did not cancel() when returning false from canFire() |
45 | isCanceled = "unknown reason"; | |
854d4d81 | 46 | |
3e5c8cf4 | 47 | debugs(debugSection, debugLevel, HERE << "will not call " << name << |
52ed047a | 48 | " [" << id << ']' << " because of " << isCanceled); |
3e5c8cf4 | 49 | } |
854d4d81 | 50 | |
3e5c8cf4 | 51 | bool |
52 | AsyncCall::cancel(const char *reason) | |
53 | { | |
3b79b74e AR |
54 | debugs(debugSection, debugLevel, HERE << "will not call " << name << |
55 | " [" << id << "] " << (isCanceled ? "also " : "") << | |
56 | "because " << reason); | |
57 | ||
3e5c8cf4 | 58 | isCanceled = reason; |
59 | return false; | |
60 | } | |
854d4d81 | 61 | |
3e5c8cf4 | 62 | bool |
63 | AsyncCall::canFire() | |
64 | { | |
65 | return !isCanceled; | |
66 | } | |
854d4d81 | 67 | |
63be0a78 | 68 | /// \todo make this method const by providing a const getDialer() |
3e5c8cf4 | 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 | } | |
854d4d81 | 78 | |
37cba319 AR |
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 | ||
3e5c8cf4 | 89 | bool |
26ac0430 | 90 | ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call) |
3e5c8cf4 | 91 | { |
92 | debugs(call->debugSection, call->debugLevel, fileName << "(" << fileLine << | |
52ed047a | 93 | ") will call " << *call << " [" << call->id << ']' ); |
3e5c8cf4 | 94 | AsyncCallQueue::Instance().schedule(call); |
95 | return true; | |
854d4d81 | 96 | } |
97 |