]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/AsyncJob.h
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_ASYNC_JOB_H
10 #define SQUID_ASYNC_JOB_H
12 #include "base/AsyncCall.h"
13 #include "base/InstanceId.h"
19 \defgroup AsyncJobAPI Async-Jobs API
21 * AsyncJob is an API and a base for a class that implements a stand-alone
22 * "job", "task", or "logical processing thread" which receives asynchronous
26 // See AsyncJobs.dox for details.
28 /// \ingroup AsyncJobAPI
29 /// Base class for all asynchronous jobs
33 typedef CbcPointer
<AsyncJob
> Pointer
;
36 AsyncJob(const char *aTypeName
);
39 virtual void *toCbdata() = 0;
41 /// starts a freshly created job (i.e., makes the job asynchronous)
42 static Pointer
Start(AsyncJob
*job
);
45 // XXX: temporary method to replace "delete this" in jobs-in-transition.
46 // Will be replaced with calls to mustStop() when transition is complete.
47 void deleteThis(const char *aReason
);
49 // force done() for a reason but continue with the current method
50 void mustStop(const char *aReason
);
52 bool done() const; ///< the job is destroyed in callEnd() when done()
54 virtual void start(); ///< called by AsyncStart; do not call directly
55 virtual bool doneAll() const; ///< whether positive goal has been reached
56 virtual void swanSong() {}; ///< internal cleanup; do not call directly
57 virtual const char *status() const; ///< for debugging, starts with space
60 bool canBeCalled(AsyncCall
&call
) const; ///< whether we can be called
61 void callStart(AsyncCall
&call
); ///< called just before the called method
62 /// called right after the called job method
63 virtual void callEnd(); ///< called right after the called job method
64 /// called when the job throws during an async call
65 virtual void callException(const std::exception
&e
);
68 const char *stopReason
; ///< reason for forcing done() to be true
69 const char *typeName
; ///< kid (leaf) class name, for debugging
70 AsyncCall::Pointer inCall
; ///< the asynchronous call being handled, if any
71 const InstanceId
<AsyncJob
> id
; ///< job identifier
74 #endif /* SQUID_ASYNC_JOB_H */