]> git.ipfire.org Git - thirdparty/squid.git/blame - src/base/AsyncJob.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / base / AsyncJob.h
CommitLineData
bbc27441
AJ
1/*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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"
c824c43b 14
4299f876
AR
15template <class Cbc>
16class CbcPointer;
17
63be0a78 18/**
19 \defgroup AsyncJobAPI Async-Jobs API
20 \par
c824c43b 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
23 * calls.
c824c43b 24 */
25
22c45c7d
AR
26// See AsyncJobs.dox for details.
27
63be0a78 28/// \ingroup AsyncJobAPI
4299f876 29/// Base class for all asynchronous jobs
c824c43b 30class AsyncJob
31{
c824c43b 32public:
4299f876 33 typedef CbcPointer<AsyncJob> Pointer;
c824c43b 34
4299f876 35public:
c824c43b 36 AsyncJob(const char *aTypeName);
37 virtual ~AsyncJob();
38
3e5c8cf4 39 virtual void *toCbdata() = 0;
4299f876
AR
40
41 /// starts a freshly created job (i.e., makes the job asynchronous)
42 static Pointer Start(AsyncJob *job);
c824c43b 43
44protected:
3e5c8cf4 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);
48
22c45c7d
AR
49 // force done() for a reason but continue with the current method
50 void mustStop(const char *aReason);
c824c43b 51
22c45c7d 52 bool done() const; ///< the job is destroyed in callEnd() when done()
c824c43b 53
22c45c7d
AR
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
c824c43b 58
3e5c8cf4 59public:
22c45c7d
AR
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
0a8bbeeb 65 virtual void callException(const std::exception &e);
c824c43b 66
3e5c8cf4 67protected:
22c45c7d
AR
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
52ed047a 71 const InstanceId<AsyncJob> id; ///< job identifier
3e5c8cf4 72};
73
c824c43b 74#endif /* SQUID_ASYNC_JOB_H */