]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/base/AsyncCall.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / base / AsyncCall.h
index d4df9f64414ed5589fbf6479abeafa0d7b20923e..b42305da74888032d18b2c196c299b39e501daeb 100644 (file)
@@ -1,13 +1,17 @@
 /*
- * $Id$
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_ASYNCCALL_H
 #define SQUID_ASYNCCALL_H
 
-//#include "cbdata.h"
+#include "base/InstanceId.h"
 #include "event.h"
-//#include "TextException.h"
+#include "RefCount.h"
 
 /**
  \defgroup AsynCallsAPI Async-Calls API
@@ -34,7 +38,7 @@ class AsyncCallQueue;
 
 /**
  \todo add unique call IDs
- \todo CBDATA_CLASS2 kids
+ \todo CBDATA_CLASS kids
  \ingroup AsyncCallsAPI
  */
 class AsyncCall: public RefCountable
@@ -57,6 +61,9 @@ public:
 
     void print(std::ostream &os);
 
+    /// remove us from the queue; we are head unless we are queued after prev
+    void dequeue(AsyncCall::Pointer &head, AsyncCall::Pointer &prev);
+
     void setNext(AsyncCall::Pointer aNext) {
         theNext = aNext;
     }
@@ -69,7 +76,7 @@ public:
     const char *const name;
     const int debugSection;
     const int debugLevel;
-    const unsigned int id;
+    const InstanceId<AsyncCall> id;
 
 protected:
     virtual bool canFire();
@@ -80,7 +87,10 @@ protected:
 
 private:
     const char *isCanceled; // set to the cancelation reason by cancel()
-    static unsigned int TheLastId;
+
+    // not implemented to prevent nil calls from being passed around and unknowingly scheduled, for now.
+    AsyncCall();
+    AsyncCall(const AsyncCall &);
 };
 
 inline
@@ -117,7 +127,13 @@ class AsyncCallT: public AsyncCall
 public:
     AsyncCallT(int aDebugSection, int aDebugLevel, const char *aName,
                const Dialer &aDialer): AsyncCall(aDebugSection, aDebugLevel, aName),
-            dialer(aDialer) {}
+        dialer(aDialer) {}
+
+    AsyncCallT(const AsyncCallT<Dialer> &o):
+        AsyncCall(o.debugSection, o.debugLevel, o.name),
+        dialer(o.dialer) {}
+
+    ~AsyncCallT() {}
 
     CallDialer *getDialer() { return &dialer; }
 
@@ -129,6 +145,9 @@ protected:
     virtual void fire() { dialer.dial(*this); }
 
     Dialer dialer;
+
+private:
+    AsyncCallT & operator=(const AsyncCallT &); // not defined. call assignments not permitted.
 };
 
 template <class Dialer>
@@ -141,10 +160,10 @@ asyncCall(int aDebugSection, int aDebugLevel, const char *aName,
 }
 
 /** Call scheduling helper. Use ScheduleCallHere if you can. */
-extern bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call);
+bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call);
 
 /** Call scheduling helper. */
 #define ScheduleCallHere(call) ScheduleCall(__FILE__, __LINE__, (call))
 
-
 #endif /* SQUID_ASYNCCALL_H */
+