]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Inquirer.h
importing smp-snmp patch
[thirdparty/squid.git] / src / ipc / Inquirer.h
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #ifndef SQUID_IPC_INQUIRER_H
9 #define SQUID_IPC_INQUIRER_H
10
11 #include "base/AsyncJobCalls.h"
12 #include "base/AsyncJob.h"
13 #include "ipc/forward.h"
14 #include "ipc/Request.h"
15 #include "ipc/Response.h"
16 #include "ipc/StrandCoords.h"
17 #include <map>
18
19
20 namespace Ipc
21 {
22
23 /// Coordinator's job that sends a cache manage request to each strand,
24 /// aggregating individual strand responses and dumping the result if needed
25 class Inquirer: public AsyncJob
26 {
27 public:
28 Inquirer(Request::Pointer aRequest, const Ipc::StrandCoords& coords, double aTimeout);
29 virtual ~Inquirer();
30
31 /// finds and calls the right Inquirer upon strand's response
32 static void HandleRemoteAck(const Response& response);
33
34 /* has-to-be-public AsyncJob API */
35 virtual void callException(const std::exception& e);
36
37 protected:
38 /* AsyncJob API */
39 virtual void start();
40 virtual void swanSong();
41 virtual bool doneAll() const;
42 virtual const char *status() const;
43
44 /// inquire the next strand
45 virtual void inquire();
46 /// perform cleanup actions on completion of job
47 virtual void cleanup();
48 /// do specific exception handling
49 virtual void handleException(const std::exception& e);
50 /// send response to client
51 virtual void sendResponse() = 0;
52 /// perform aggregating of responses and returns true if need to continue
53 virtual bool aggregate(Response::Pointer aResponse) = 0;
54
55 private:
56 typedef UnaryMemFunT<Inquirer, Response::Pointer, Response::Pointer> HandleAckDialer;
57
58 void handleRemoteAck(Response::Pointer response);
59
60 static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
61
62 static void RequestTimedOut(void* param);
63 void requestTimedOut();
64 void removeTimeoutEvent();
65
66 protected:
67 Request::Pointer request; ///< cache manager request received from client
68
69 Ipc::StrandCoords strands; ///< all strands we want to query, in order
70 Ipc::StrandCoords::const_iterator pos; ///< strand we should query now
71
72 const double timeout; ///< number of seconds to wait for strand response
73
74 /// maps request->id to Inquirer::handleRemoteAck callback
75 typedef std::map<unsigned int, AsyncCall::Pointer> RequestsMap;
76 static RequestsMap TheRequestsMap; ///< pending strand requests
77
78 static unsigned int LastRequestId; ///< last requestId used
79
80 CBDATA_CLASS2(Inquirer);
81 };
82
83 } // namespace Ipc
84
85 #endif /* SQUID_IPC_INQUIRER_H */