3
* $Id: AsyncCall.h,v 1.2 2007/05/08 16:15:50 rousskov Exp $
6
* SQUID Web Proxy Cache http://www.squid-cache.org/
7
* ----------------------------------------------------------
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.
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.
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.
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.
34
#ifndef SQUID_ASYNCCALL_H
35
#define SQUID_ASYNCCALL_H
40
// A call is asynchronous if the caller proceeds after the call is made,
41
// and the callee receives the call during the next main loop iteration.
42
// Asynchronous calls help avoid nasty call-me-when-I-call-you loops
43
// that humans often have trouble understanding or implementing correctly.
45
// Asynchronous calls are currently implemented via Squid events. The call
46
// event stores the pointer to the callback function and cbdata-protected
47
// callback data. To call a method of an object, the method is wrapped
48
// in a method-specific, static callback function and the pointer to the
49
// object is passed to the wrapper. For the method call to be safe, the
50
// class must be cbdata-enabled.
52
// You do not have to use the macros below to make or receive asynchronous
53
// method calls, but they give you a uniform interface and handy call
56
// See AsyncCall.cc for a usage sketch.
59
// Make an asynchronous object->callName() call.
60
#define AsyncCall(debugSection, debugLevel, objectPtr, callName) \
61
scheduleAsyncCall((debugSection), (debugLevel), __FILE__, __LINE__, \
62
(objectPtr), #callName, \
63
&(callName ## Wrapper))
65
// Declare and define a wrapper for an asynchronous call handler method
66
#define AsyncCallWrapper(debugSection, debugLevel, ClassName, callName) \
68
void callName ## Wrapper(void *data) { \
69
ClassName *objectPtr = static_cast<ClassName*>(data); \
70
if (enterAsyncCallWrapper((debugSection), (debugLevel), data, #ClassName, #callName)) { \
71
objectPtr->callName(); \
72
exitAsyncCallWrapper((debugSection), (debugLevel), data, #ClassName, #callName); \
77
// Hint: to customize debugging of asynchronous messages in a class, provide
78
// class method called scheduleAsyncCall, enterAsyncCallWrapper, and/or
79
// exitAsyncCallWrapper. Class method will take priority over these globals.
81
extern void scheduleAsyncCall(int debugSection, int debugLevel,
82
const char *fileName, int fileLine, void *objectPtr, const char *callName,
83
EVH *wrapper, bool cbdataProtected = true);
85
extern bool enterAsyncCallWrapper(int debugSection, int debugLevel,
86
void *objectPtr, const char *className, const char *methodName);
88
extern void exitAsyncCallWrapper(int debugSection, int debugLevel,
89
void *objectPtr, const char *className, const char *methodName);
92
#endif /* SQUID_ASYNCCALL_H */