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