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