From: rousskov <> Date: Wed, 13 Feb 2008 12:51:55 +0000 (+0000) Subject: Merging async-call branch changes to HEAD: X-Git-Tag: BASIC_TPROXY4~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0edbef7e0d045bdafe00ef4bacb0cca71473178a;p=thirdparty%2Fsquid.git Merging async-call branch changes to HEAD: Added file forgotten in the initial merge. --- diff --git a/src/AsyncJobCalls.h b/src/AsyncJobCalls.h new file mode 100644 index 0000000000..efe3c1b4bd --- /dev/null +++ b/src/AsyncJobCalls.h @@ -0,0 +1,87 @@ + +/* + * $Id: AsyncJobCalls.h,v 1.1 2008/02/13 05:51:55 rousskov Exp $ + */ + +#ifndef SQUID_ASYNCJOBCALLS_H +#define SQUID_ASYNCJOBCALLS_H + +#include "ICAP/AsyncJob.h" + +/* + * *MemFunT are member function (i.e., class method) wrappers. They store + * details of a method call in an object so that the call can be delayed + * and executed asynchronously. Details may include the object pointer, + * the handler method pointer, and parameters. To simplify, we require + * all handlers to return void and not be constant. + */ + +/* + * We need one wrapper for every supported member function arity (i.e., + * number of handler arguments). The first template parameter is the class + * type of the handler. That class must be an AsyncJob child. + */ + +// Arity names are from http://en.wikipedia.org/wiki/Arity + +template +class NullaryMemFunT: public JobDialer +{ +public: + typedef void (C::*Method)(); + explicit NullaryMemFunT(C *anObject, Method aMethod): + JobDialer(anObject), object(anObject), method(aMethod) {} + + virtual void print(std::ostream &os) const { os << "()"; } + +public: + C *object; + Method method; + +protected: + virtual void doDial() { (object->*method)(); } +}; + +template +class UnaryMemFunT: public JobDialer +{ +public: + typedef void (C::*Method)(Argument1); + explicit UnaryMemFunT(C *anObject, Method aMethod, const Argument1 &anArg1): + JobDialer(anObject), + object(anObject), method(aMethod), arg1(anArg1) {} + + virtual void print(std::ostream &os) const { os << '(' << arg1 << ')'; } + +public: + C *object; + Method method; + Argument1 arg1; + +protected: + virtual void doDial() { (object->*method)(arg1); } +}; + +// ... add more as needed + + +// Now we add global templated functions that create the member function +// wrappers above. These are for convenience: it is often easier to +// call a templated function than to create a templated object. + +template +NullaryMemFunT +MemFun(C *object, typename NullaryMemFunT::Method method) +{ + return NullaryMemFunT(object, method); +} + +template +UnaryMemFunT +MemFun(C *object, typename UnaryMemFunT::Method method, + Argument1 arg1) +{ + return UnaryMemFunT(object, method, arg1); +} + +#endif /* SQUID_ASYNCJOBCALLS_H */