]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/AsyncJob.h
5 #ifndef SQUID_ASYNC_JOB_H
6 #define SQUID_ASYNC_JOB_H
8 #include "base/AsyncCall.h"
11 \defgroup AsyncJobAPI Async-Jobs API
13 * AsyncJob is an API and a base for a class that implements a stand-alone
14 * "job", "task", or "logical processing thread" which receives asynchronous
17 * Implementations should wrap each method receiving an asynchronous call in
18 * a pair of macros: AsyncCallEnter and AsyncCallExit. These macros:
19 * - provide call debugging
20 * - trap exceptions and terminate the task if an exception occurs
21 * - ensure that only one asynchronous call is active per object
22 * Most of the work is done by AsyncJob class methods. Macros just provide
23 * an enter/try/catch/exit framework.
25 * Eventually, the macros can and perhaps should be replaced with call/event
26 * processing code so that individual job classes do not have to wrap all
30 /// \ingroup AsyncJobAPI
35 static AsyncJob
*AsyncStart(AsyncJob
*job
); // use this to start jobs
37 AsyncJob(const char *aTypeName
);
40 virtual void *toCbdata() = 0;
41 void noteStart(); // calls virtual start
44 // XXX: temporary method to replace "delete this" in jobs-in-transition.
45 // Will be replaced with calls to mustStop() when transition is complete.
46 void deleteThis(const char *aReason
);
48 void mustStop(const char *aReason
); // force done() for a reason
50 bool done() const; // the job is destroyed in callEnd() when done()
53 virtual bool doneAll() const; // return true when done
54 virtual void swanSong() {}; // perform internal cleanup
55 virtual const char *status() const; // for debugging
58 // asynchronous call maintenance
59 bool canBeCalled(AsyncCall
&call
) const;
60 void callStart(AsyncCall
&call
);
61 virtual void callException(const std::exception
&e
);
62 virtual void callEnd();
65 const char *stopReason
; // reason for forcing done() to be true
66 const char *typeName
; // kid (leaf) class name, for debugging
67 AsyncCall::Pointer inCall
; // the asynchronous call being handled, if any
68 const unsigned int id
;
71 static unsigned int TheLastId
;
77 * This is a base class for all job call dialers. It does all the job
78 * dialing logic (debugging, handling exceptions, etc.) except for calling
79 * the job method. The latter is not possible without templates and we
80 * want to keep this class simple and template-free. Thus, we add a dial()
81 * virtual method that the JobCallT template below will implement for us,
84 class JobDialer
: public CallDialer
87 JobDialer(AsyncJob
*aJob
);
88 JobDialer(const JobDialer
&d
);
91 virtual bool canDial(AsyncCall
&call
);
92 void dial(AsyncCall
&call
);
95 void *lock
; // job's cbdata
98 virtual void doDial() = 0; // actually calls the job method
101 // not implemented and should not be needed
102 JobDialer
&operator =(const JobDialer
&);
105 #include "base/AsyncJobCalls.h"
107 template <class Dialer
>
109 CallJob(int debugSection
, int debugLevel
, const char *fileName
, int fileLine
,
110 const char *callName
, const Dialer
&dialer
)
112 AsyncCall::Pointer call
= asyncCall(debugSection
, debugLevel
, callName
, dialer
);
113 return ScheduleCall(fileName
, fileLine
, call
);
117 #define CallJobHere(debugSection, debugLevel, job, method) \
118 CallJob((debugSection), (debugLevel), __FILE__, __LINE__, #method, \
119 MemFun((job), &method))
121 #define CallJobHere1(debugSection, debugLevel, job, method, arg1) \
122 CallJob((debugSection), (debugLevel), __FILE__, __LINE__, #method, \
123 MemFun((job), &method, (arg1)))
126 #endif /* SQUID_ASYNC_JOB_H */