]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
2cd0bda2 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
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. | |
7 | */ | |
8 | ||
c824c43b | 9 | #ifndef SQUID_ASYNC_JOB_H |
10 | #define SQUID_ASYNC_JOB_H | |
11 | ||
882255af | 12 | #include "base/AsyncCall.h" |
52ed047a | 13 | #include "base/InstanceId.h" |
1625e4a1 | 14 | #include "cbdata.h" |
c824c43b | 15 | |
4299f876 AR |
16 | template <class Cbc> |
17 | class CbcPointer; | |
18 | ||
63be0a78 | 19 | /** |
20 | \defgroup AsyncJobAPI Async-Jobs API | |
21 | \par | |
c824c43b | 22 | * AsyncJob is an API and a base for a class that implements a stand-alone |
23 | * "job", "task", or "logical processing thread" which receives asynchronous | |
24 | * calls. | |
c824c43b | 25 | */ |
26 | ||
22c45c7d AR |
27 | // See AsyncJobs.dox for details. |
28 | ||
63be0a78 | 29 | /// \ingroup AsyncJobAPI |
4299f876 | 30 | /// Base class for all asynchronous jobs |
1625e4a1 | 31 | class AsyncJob: public CbdataParent |
c824c43b | 32 | { |
c824c43b | 33 | public: |
4299f876 | 34 | typedef CbcPointer<AsyncJob> Pointer; |
c824c43b | 35 | |
4299f876 | 36 | public: |
c824c43b | 37 | AsyncJob(const char *aTypeName); |
38 | virtual ~AsyncJob(); | |
39 | ||
4299f876 AR |
40 | /// starts a freshly created job (i.e., makes the job asynchronous) |
41 | static Pointer Start(AsyncJob *job); | |
c824c43b | 42 | |
43 | protected: | |
3e5c8cf4 | 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); | |
47 | ||
22c45c7d AR |
48 | // force done() for a reason but continue with the current method |
49 | void mustStop(const char *aReason); | |
c824c43b | 50 | |
22c45c7d | 51 | bool done() const; ///< the job is destroyed in callEnd() when done() |
c824c43b | 52 | |
22c45c7d AR |
53 | virtual void start(); ///< called by AsyncStart; do not call directly |
54 | virtual bool doneAll() const; ///< whether positive goal has been reached | |
55 | virtual void swanSong() {}; ///< internal cleanup; do not call directly | |
56 | virtual const char *status() const; ///< for debugging, starts with space | |
c824c43b | 57 | |
3e5c8cf4 | 58 | public: |
22c45c7d AR |
59 | bool canBeCalled(AsyncCall &call) const; ///< whether we can be called |
60 | void callStart(AsyncCall &call); ///< called just before the called method | |
61 | /// called right after the called job method | |
62 | virtual void callEnd(); ///< called right after the called job method | |
63 | /// called when the job throws during an async call | |
0a8bbeeb | 64 | virtual void callException(const std::exception &e); |
c824c43b | 65 | |
3e5c8cf4 | 66 | protected: |
22c45c7d AR |
67 | const char *stopReason; ///< reason for forcing done() to be true |
68 | const char *typeName; ///< kid (leaf) class name, for debugging | |
69 | AsyncCall::Pointer inCall; ///< the asynchronous call being handled, if any | |
52ed047a | 70 | const InstanceId<AsyncJob> id; ///< job identifier |
3e5c8cf4 | 71 | }; |
72 | ||
c824c43b | 73 | #endif /* SQUID_ASYNC_JOB_H */ |
f53969cc | 74 |