]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Inquirer.h
Replaced most custom high-level callbacks with a unified API (#1094)
[thirdparty/squid.git] / src / ipc / Inquirer.h
1 /*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 54 Interprocess Communication */
10
11 #ifndef SQUID_IPC_INQUIRER_H
12 #define SQUID_IPC_INQUIRER_H
13
14 #include "base/AsyncJob.h"
15 #include "base/AsyncJobCalls.h"
16 #include "base/forward.h"
17 #include "ipc/forward.h"
18 #include "ipc/Request.h"
19 #include "ipc/Response.h"
20 #include "ipc/StrandCoords.h"
21
22 namespace 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
27 class Inquirer: public AsyncJob
28 {
29 CBDATA_CLASS(Inquirer);
30
31 public:
32 Inquirer(Request::Pointer aRequest, const Ipc::StrandCoords& coords, double aTimeout);
33 virtual ~Inquirer();
34
35 /// finds and calls the right Inquirer upon strand's response
36 static void HandleRemoteAck(const Response& response);
37
38 /* has-to-be-public AsyncJob API */
39 virtual void callException(const std::exception& e);
40
41 CodeContextPointer codeContext;
42
43 protected:
44 /* AsyncJob API */
45 virtual void start();
46 virtual void swanSong();
47 virtual bool doneAll() const;
48 virtual const char *status() const;
49
50 /// inquire the next strand
51 virtual void inquire();
52 /// perform cleanup actions on completion of job
53 virtual void cleanup();
54 /// do specific exception handling
55 virtual void handleException(const std::exception& e);
56 /// send response to client
57 virtual void sendResponse() = 0;
58 /// perform aggregating of responses and returns true if need to continue
59 virtual bool aggregate(Response::Pointer aResponse) = 0;
60
61 private:
62 void handleRemoteAck(Response::Pointer response);
63
64 static void RequestTimedOut(void* param);
65 void requestTimedOut();
66 void removeTimeoutEvent();
67
68 protected:
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 static RequestId::Index LastRequestId; ///< last requestId used
77 };
78
79 } // namespace Ipc
80
81 #endif /* SQUID_IPC_INQUIRER_H */
82