From: Amos Jeffries Date: Sat, 11 Sep 2010 03:31:47 +0000 (+1200) Subject: Add Subscription interface X-Git-Tag: take08~55^2~124^2~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc7e9600f1b817528df7aad0d27259b44f5e5bb1;p=thirdparty%2Fsquid.git Add Subscription interface --- diff --git a/src/base/AsyncCall.cc b/src/base/AsyncCall.cc index 9bca17efe8..cb467bcc72 100644 --- a/src/base/AsyncCall.cc +++ b/src/base/AsyncCall.cc @@ -77,4 +77,3 @@ ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call) AsyncCallQueue::Instance().schedule(call); return true; } - diff --git a/src/base/AsyncCall.h b/src/base/AsyncCall.h index d4df9f6441..a1bdaef0c2 100644 --- a/src/base/AsyncCall.h +++ b/src/base/AsyncCall.h @@ -44,6 +44,8 @@ public: friend class AsyncCallQueue; AsyncCall(int aDebugSection, int aDebugLevel, const char *aName); + AsyncCall(); + AsyncCall(const AsyncCall &); virtual ~AsyncCall(); void make(); // fire if we can; handles general call debugging diff --git a/src/base/Makefile.am b/src/base/Makefile.am index 7009fb37be..a62d84ffa3 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -13,5 +13,6 @@ libbase_la_SOURCES = \ AsyncCallQueue.cc \ AsyncCallQueue.h \ CbcPointer.h \ + Subscription.h \ TextException.cc \ TextException.h diff --git a/src/base/Subscription.h b/src/base/Subscription.h new file mode 100644 index 0000000000..4840260b0a --- /dev/null +++ b/src/base/Subscription.h @@ -0,0 +1,38 @@ +#ifndef _SQUID_BASE_SUBSCRIPTION_H +#define _SQUID_BASE_SUBSCRIPTION_H + +#include "RefCount.h" +#include "base/AsyncCall.h" + +/** + * API for classes needing to emit multiple event-driven AsyncCalls. + * A receiver class uses this API to subscribe interest in the + * events being handled or watched for by the API child. + * + * The API child then uses this to create and emit a call as needed. + */ +class Subscription: public RefCountable { +public: + typedef RefCount Pointer; + + /// returns a call object to be used for the next call back + virtual AsyncCall::Pointer callback() = 0; +// virtual AsyncCall::Pointer callback() const = 0; +}; + +/// implements Subscription API using Call's copy constructor +template +class CallSubscription: public Subscription +{ +public: + // cant be const because CommCbFunPtrCallT cant provide a const overload. + // CommCbFunPtrCallT lists why. boils down to Comm IO syncWithComm() existence + CallSubscription(RefCount &aCall) : call(aCall) {}; + virtual AsyncCall::Pointer callback() { return new Call_(call); }; +// virtual AsyncCall::Pointer callback() const { return new Call_(call); }; + +private: + RefCount call; ///< gets copied to create callback calls +}; + +#endif /* _SQUID_BASE_SUBSCRIPTION_H */