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