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