]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Coordinator.h
Merged from parent (trunk r11711, v3.2.0.11+).
[thirdparty/squid.git] / src / ipc / Coordinator.h
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #ifndef SQUID_IPC_COORDINATOR_H
9 #define SQUID_IPC_COORDINATOR_H
10
11
12 #include "Array.h"
13 #include "ipc/Messages.h"
14 #include "ipc/Port.h"
15 #include "ipc/SharedListen.h"
16 #include "ipc/StrandCoords.h"
17 #include "ipc/StrandSearch.h"
18 #include "mgr/forward.h"
19 #if SQUID_SNMP
20 #include "snmp/forward.h"
21 #endif
22 #include <list>
23 #include <map>
24
25 namespace Ipc
26 {
27
28 /// Coordinates shared activities of Strands (Squid processes or threads)
29 class Coordinator: public Port
30 {
31 public:
32 static Coordinator* Instance();
33
34 public:
35 Coordinator();
36
37 void broadcastSignal(int sig) const; ///< send sig to registered strands
38
39 const StrandCoords &strands() const; ///< currently registered strands
40
41 protected:
42 virtual void start(); // Port (AsyncJob) API
43 virtual void receive(const TypedMsgHdr& message); // Port API
44
45 StrandCoord* findStrand(int kidId); ///< registered strand or NULL
46 void registerStrand(const StrandCoord &); ///< adds or updates existing
47 void handleRegistrationRequest(const HereIamMessage &); ///< register,ACK
48
49 /// answer the waiting search request
50 void notifySearcher(const StrandSearchRequest &request, const StrandCoord&);
51 /// answers or queues the request if the answer is not yet known
52 void handleSearchRequest(const StrandSearchRequest &request);
53
54 /// returns cached socket or calls openListenSocket()
55 void handleSharedListenRequest(const SharedListenRequest& request);
56 void handleCacheMgrRequest(const Mgr::Request& request);
57 void handleCacheMgrResponse(const Mgr::Response& response);
58 #if SQUID_SNMP
59 void handleSnmpRequest(const Snmp::Request& request);
60 void handleSnmpResponse(const Snmp::Response& response);
61 #endif
62 /// calls comm_open_listener()
63 Comm::ConnectionPointer openListenSocket(const SharedListenRequest& request, int &errNo);
64
65 private:
66 StrandCoords strands_; ///< registered processes and threads
67
68 typedef std::list<StrandSearchRequest> Searchers; ///< search requests
69 Searchers searchers; ///< yet unanswered search requests in arrival order
70
71 typedef std::map<OpenListenerParams, Comm::ConnectionPointer> Listeners; ///< params:connection map
72 Listeners listeners; ///< cached comm_open_listener() results
73
74 static Coordinator* TheInstance; ///< the only class instance in existence
75
76 private:
77 Coordinator(const Coordinator&); // not implemented
78 Coordinator& operator =(const Coordinator&); // not implemented
79
80 CBDATA_CLASS2(Coordinator);
81 };
82
83
84 } // namespace Ipc
85
86 #endif /* SQUID_IPC_COORDINATOR_H */