2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 54 Interprocess Communication */
11 #ifndef SQUID_IPC_INQUIRER_H
12 #define SQUID_IPC_INQUIRER_H
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"
26 /// Coordinator's job that sends a cache manage request to each strand,
27 /// aggregating individual strand responses and dumping the result if needed
28 class Inquirer
: public AsyncJob
30 CBDATA_CLASS(Inquirer
);
33 Inquirer(Request::Pointer aRequest
, const Ipc::StrandCoords
& coords
, double aTimeout
);
36 /// finds and calls the right Inquirer upon strand's response
37 static void HandleRemoteAck(const Response
& response
);
39 /* has-to-be-public AsyncJob API */
40 virtual void callException(const std::exception
& e
);
42 CodeContextPointer codeContext
;
47 virtual void swanSong();
48 virtual bool doneAll() const;
49 virtual const char *status() const;
51 /// inquire the next strand
52 virtual void inquire();
53 /// perform cleanup actions on completion of job
54 virtual void cleanup();
55 /// do specific exception handling
56 virtual void handleException(const std::exception
& e
);
57 /// send response to client
58 virtual void sendResponse() = 0;
59 /// perform aggregating of responses and returns true if need to continue
60 virtual bool aggregate(Response::Pointer aResponse
) = 0;
63 typedef UnaryMemFunT
<Inquirer
, Response::Pointer
, Response::Pointer
> HandleAckDialer
;
65 void handleRemoteAck(Response::Pointer response
);
67 static AsyncCall::Pointer
DequeueRequest(RequestId::Index
);
69 static void RequestTimedOut(void* param
);
70 void requestTimedOut();
71 void removeTimeoutEvent();
74 Request::Pointer request
; ///< cache manager request received from client
76 Ipc::StrandCoords strands
; ///< all strands we want to query, in order
77 Ipc::StrandCoords::const_iterator pos
; ///< strand we should query now
79 const double timeout
; ///< number of seconds to wait for strand response
81 /// maps request->id to Inquirer::handleRemoteAck callback
82 typedef std::map
<RequestId::Index
, AsyncCall::Pointer
> RequestsMap
;
83 static RequestsMap TheRequestsMap
; ///< pending strand requests
85 static RequestId::Index LastRequestId
; ///< last requestId used
90 #endif /* SQUID_IPC_INQUIRER_H */