]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ICAP/AsyncJob.h
Merging async-call branch changes to HEAD:
[thirdparty/squid.git] / src / ICAP / AsyncJob.h
CommitLineData
c824c43b 1
2/*
9fcd0cd4 3 * $Id: AsyncJob.h,v 1.2 2007/06/19 21:00:11 rousskov Exp $
c824c43b 4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34#ifndef SQUID_ASYNC_JOB_H
35#define SQUID_ASYNC_JOB_H
36
37#include "AsyncCall.h"
38
39/*
40 * AsyncJob is an API and a base for a class that implements a stand-alone
41 * "job", "task", or "logical processing thread" which receives asynchronous
42 * calls.
43 *
44 * Implementations should wrap each method receiving an asynchronous call in
45 * a pair of macros: AsyncCallEnter and AsyncCallExit. These macros:
46 * - provide call debugging
47 * - trap exceptions and terminate the task if an exception occurs
48 * - ensure that only one asynchronous call is active per object
49 * Most of the work is done by AsyncJob class methods. Macros just provide
50 * an enter/try/catch/exit framework.
51 *
52 * Eventually, the macros can and perhaps should be replaced with call/event
53 * processing code so that individual job classes do not have to wrap all
54 * asynchronous calls.
55 */
56
57class TextException;
58
59class AsyncJob
60{
61
62public:
63 static AsyncJob *AsyncStart(AsyncJob *job); // use this to start jobs
64
65 AsyncJob(const char *aTypeName);
66 virtual ~AsyncJob();
67
68 void noteStart(); // calls virtual start
69 AsyncCallWrapper(93,3, AsyncJob, noteStart);
70
71protected:
72 void mustStop(const char *aReason); // force done() for a reason
73
74 bool done() const; // the job is destroyed in callEnd() when done()
75
76 virtual void start() = 0;
77 virtual bool doneAll() const = 0; // return true when done
78 virtual void swanSong() = 0; // perform internal cleanup
79 virtual const char *status() const = 0; // for debugging
80
81 // asynchronous call maintenance
82 bool callStart(const char *methodName);
9fcd0cd4 83 virtual void callException(const TextException &e);
c824c43b 84 virtual void callEnd();
85
86 const char *stopReason; // reason for forcing done() to be true
87 const char *typeName; // kid (leaf) class name, for debugging
88 const char *inCall; // name of the asynchronous call being executed, if any
89};
90
91
92// call guards for all "asynchronous" note*() methods
93// TODO: Move to core.
94
95// asynchronous call entry:
96// - open the try clause;
97// - call callStart().
98#define AsyncCallEnter(method) \
99 try { \
100 if (!callStart(#method)) \
101 return;
102
103// asynchronous call exit:
104// - close the try clause;
105// - catch exceptions;
106// - let callEnd() handle transaction termination conditions
107#define AsyncCallExit() \
108 } \
109 catch (const TextException &e) { \
110 callException(e); \
111 } \
112 callEnd();
113
114
115#endif /* SQUID_ASYNC_JOB_H */