]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add Subscription interface
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 11 Sep 2010 03:31:47 +0000 (15:31 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 11 Sep 2010 03:31:47 +0000 (15:31 +1200)
src/base/AsyncCall.cc
src/base/AsyncCall.h
src/base/Makefile.am
src/base/Subscription.h [new file with mode: 0644]

index 9bca17efe87bc72c149fd1fedda0d2c14ceaf472..cb467bcc72b1e91deaee1d1715dda5793fb8b0cd 100644 (file)
@@ -77,4 +77,3 @@ ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
     AsyncCallQueue::Instance().schedule(call);
     return true;
 }
-
index d4df9f64414ed5589fbf6479abeafa0d7b20923e..a1bdaef0c29c2e8c45a84877e412e4208f666dab 100644 (file)
@@ -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
index 7009fb37bee9cefc37e2fc410d5949dd5de94967..a62d84ffa32ce1a014430694fa8752d5e5d5a651 100644 (file)
@@ -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 (file)
index 0000000..4840260
--- /dev/null
@@ -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<Subscription> 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 Call_>
+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<Call_> &aCall) : call(aCall) {};
+    virtual AsyncCall::Pointer callback() { return new Call_(call); };
+//    virtual AsyncCall::Pointer callback() const { return new Call_(call); };
+
+private:
+    RefCount<Call_> call; ///< gets copied to create callback calls
+};
+
+#endif /* _SQUID_BASE_SUBSCRIPTION_H */