]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 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 | ||
37dedc58 AJ |
9 | #ifndef SQUID_BASE_ASYNCCBDATACALLS_H |
10 | #define SQUID_BASE_ASYNCCBDATACALLS_H | |
11 | ||
12 | #include "base/AsyncCall.h" | |
13 | #include "base/CbcPointer.h" | |
14 | ||
15 | // dialer to run cbdata callback functions as Async Calls | |
16 | // to ease the transition of these cbdata objects to full Jobs | |
17 | template<class Argument1> | |
18 | class UnaryCbdataDialer : public CallDialer | |
19 | { | |
20 | public: | |
21 | typedef void Handler(Argument1 *); | |
22 | ||
23 | UnaryCbdataDialer(Handler *aHandler, Argument1 *aArg) : | |
f53969cc | 24 | arg1(aArg), |
ced8def3 AJ |
25 | handler(aHandler) |
26 | {} | |
54544731 | 27 | |
ced8def3 AJ |
28 | virtual bool canDial(AsyncCall &) { return arg1.valid(); } |
29 | void dial(AsyncCall &) { handler(arg1.get()); } | |
37dedc58 AJ |
30 | virtual void print(std::ostream &os) const { os << '(' << arg1 << ')'; } |
31 | ||
32 | public: | |
33 | CbcPointer<Argument1> arg1; | |
34 | Handler *handler; | |
35 | }; | |
36 | ||
37 | // helper function to simplify Dialer creation. | |
38 | template <class Argument1> | |
39 | UnaryCbdataDialer<Argument1> | |
40 | cbdataDialer(typename UnaryCbdataDialer<Argument1>::Handler *handler, Argument1 *arg1) | |
41 | { | |
42 | return UnaryCbdataDialer<Argument1>(handler, arg1); | |
43 | } | |
44 | ||
45 | #endif | |
f53969cc | 46 |