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