]>
Commit | Line | Data |
---|---|---|
10cefb7b | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
10cefb7b | 3 | * |
bbc27441 AJ |
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. | |
10cefb7b | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
10cefb7b | 11 | #ifndef SQUID_IPC_COORDINATOR_H |
12 | #define SQUID_IPC_COORDINATOR_H | |
13 | ||
1bac0258 | 14 | #include "ipc/Messages.h" |
8822ebee | 15 | #include "ipc/Port.h" |
0d0bce6a | 16 | #include "ipc/SharedListen.h" |
8822ebee | 17 | #include "ipc/StrandCoords.h" |
254912f3 | 18 | #include "ipc/StrandSearch.h" |
8822ebee | 19 | #include "mgr/forward.h" |
f738d783 | 20 | #if SQUID_SNMP |
d6e3ad20 | 21 | #include "snmp/forward.h" |
f738d783 | 22 | #endif |
254912f3 | 23 | #include <list> |
8822ebee | 24 | #include <map> |
10cefb7b | 25 | |
26 | namespace Ipc | |
27 | { | |
28 | ||
ba568924 AR |
29 | /// Coordinates shared activities of Strands (Squid processes or threads) |
30 | class Coordinator: public Port | |
10cefb7b | 31 | { |
5c2f68b7 AJ |
32 | CBDATA_CLASS(Coordinator); |
33 | ||
a2c48c98 AR |
34 | public: |
35 | static Coordinator* Instance(); | |
36 | ||
10cefb7b | 37 | public: |
38 | Coordinator(); | |
39 | ||
a2c48c98 AR |
40 | void broadcastSignal(int sig) const; ///< send sig to registered strands |
41 | ||
8822ebee AR |
42 | const StrandCoords &strands() const; ///< currently registered strands |
43 | ||
ba568924 AR |
44 | protected: |
45 | virtual void start(); // Port (AsyncJob) API | |
1bac0258 | 46 | virtual void receive(const TypedMsgHdr& message); // Port API |
10cefb7b | 47 | |
1bac0258 AR |
48 | StrandCoord* findStrand(int kidId); ///< registered strand or NULL |
49 | void registerStrand(const StrandCoord &); ///< adds or updates existing | |
254912f3 AR |
50 | void handleRegistrationRequest(const HereIamMessage &); ///< register,ACK |
51 | ||
52 | /// answer the waiting search request | |
53 | void notifySearcher(const StrandSearchRequest &request, const StrandCoord&); | |
54 | /// answers or queues the request if the answer is not yet known | |
55 | void handleSearchRequest(const StrandSearchRequest &request); | |
10cefb7b | 56 | |
0d0bce6a AR |
57 | /// returns cached socket or calls openListenSocket() |
58 | void handleSharedListenRequest(const SharedListenRequest& request); | |
8822ebee AR |
59 | void handleCacheMgrRequest(const Mgr::Request& request); |
60 | void handleCacheMgrResponse(const Mgr::Response& response); | |
f738d783 | 61 | #if SQUID_SNMP |
51ea0904 CT |
62 | void handleSnmpRequest(const Snmp::Request& request); |
63 | void handleSnmpResponse(const Snmp::Response& response); | |
f738d783 | 64 | #endif |
0d0bce6a | 65 | /// calls comm_open_listener() |
e0d28505 | 66 | Comm::ConnectionPointer openListenSocket(const SharedListenRequest& request, int &errNo); |
0d0bce6a | 67 | |
10cefb7b | 68 | private: |
8822ebee | 69 | StrandCoords strands_; ///< registered processes and threads |
0d0bce6a | 70 | |
254912f3 AR |
71 | typedef std::list<StrandSearchRequest> Searchers; ///< search requests |
72 | Searchers searchers; ///< yet unanswered search requests in arrival order | |
73 | ||
109cf61c | 74 | typedef std::map<OpenListenerParams, Comm::ConnectionPointer> Listeners; ///< params:connection map |
0d0bce6a AR |
75 | Listeners listeners; ///< cached comm_open_listener() results |
76 | ||
a2c48c98 | 77 | static Coordinator* TheInstance; ///< the only class instance in existence |
10cefb7b | 78 | |
ba568924 AR |
79 | private: |
80 | Coordinator(const Coordinator&); // not implemented | |
81 | Coordinator& operator =(const Coordinator&); // not implemented | |
10cefb7b | 82 | }; |
83 | ||
ba568924 | 84 | } // namespace Ipc |
10cefb7b | 85 | |
86 | #endif /* SQUID_IPC_COORDINATOR_H */ |