1 | #ifndef __SERVICE_HPP__ |
---|
2 | #define __SERVICE_HPP__ |
---|
3 | |
---|
4 | #include "xios_spl.hpp" |
---|
5 | #include "mpi.hpp" |
---|
6 | #include "services_manager.hpp" |
---|
7 | #include "event_scheduler.hpp" |
---|
8 | |
---|
9 | namespace xios |
---|
10 | { |
---|
11 | |
---|
12 | class CServerContext ; |
---|
13 | |
---|
14 | class CService |
---|
15 | { |
---|
16 | public: |
---|
17 | |
---|
18 | const int NOTIFY_NOTHING=0 ; |
---|
19 | const int NOTIFY_CREATE_CONTEXT=1 ; |
---|
20 | |
---|
21 | CService(MPI_Comm serviceComm, const std::string& poolId, const std::string& serviceId, const int& partitionId, |
---|
22 | int type, int nbPartitions, shared_ptr<CEventScheduler> = nullptr) ; |
---|
23 | ~CService() ; |
---|
24 | |
---|
25 | bool eventLoop(bool serviceOnly=false) ; |
---|
26 | void createContext(const std::string& poolId, const std::string& serviceId, const int& partitionId, const std::string& contextId) ; |
---|
27 | void checkCreateContextNotification(void) ; |
---|
28 | void createContextNotify(int rank, const std::string& poolId, const std::string& serviceId, const int& partitionId, const std::string& contextId) ; |
---|
29 | void createContextDumpOut(CBufferOut& buffer) ; |
---|
30 | void createContextDumpIn(CBufferIn& buffer) ; |
---|
31 | void createNewContext(const std::string& poolId, const std::string& serviceId, const int& partitionId, const std::string& contextId) ; |
---|
32 | CServerContext* getServerContext(const std::string& contextId) { return contexts_[contextId]; } |
---|
33 | void finalizeSignal(void) ; |
---|
34 | shared_ptr<CEventScheduler> getEventScheduler(void) ; |
---|
35 | |
---|
36 | std::string getPoolId(void) {return poolId_;} |
---|
37 | std::string getServiceId(void) {return serviceId_;} |
---|
38 | int getPartitionId(void) {return partitionId_;} |
---|
39 | int getType(void) {return type_;} |
---|
40 | int getNbPartitions(void) {return nbPartitions_;} |
---|
41 | const MPI_Comm& getCommunicator(void) { return serviceComm_ ;} |
---|
42 | |
---|
43 | private: |
---|
44 | void sendNotification(int rank) ; |
---|
45 | void notificationsDumpOut(CBufferOut& buffer) ; |
---|
46 | void notificationsDumpIn(CBufferIn& buffer) ; |
---|
47 | void checkNotifications(void) ; |
---|
48 | void createContext(void) ; |
---|
49 | |
---|
50 | MPI_Comm serviceComm_ ; |
---|
51 | MPI_Comm globalComm_ ; |
---|
52 | |
---|
53 | const size_t maxBufferSize_=1024*1024 ; |
---|
54 | const int localLeader_=0 ; |
---|
55 | int globalLeader_ ; |
---|
56 | CWindowManager* winNotify_ ; |
---|
57 | |
---|
58 | std::string name_ ; |
---|
59 | |
---|
60 | std::list<std::tuple<std::string, std::string, int, std::string>> notifications_; |
---|
61 | |
---|
62 | bool hasNotification_ ; |
---|
63 | int notifyInType_,notifyOutType_ ; |
---|
64 | std::tuple<std::string, std::string, int, std::string> notifyInCreateContext_, notifyOutCreateContext_ ; |
---|
65 | |
---|
66 | std::map<std::string, CServerContext*> contexts_ ; |
---|
67 | bool finalizeSignal_ ; |
---|
68 | shared_ptr<CEventScheduler> eventScheduler_ ; |
---|
69 | |
---|
70 | std::string poolId_ ; |
---|
71 | std::string serviceId_ ; |
---|
72 | int partitionId_ ; |
---|
73 | int type_ ; |
---|
74 | int nbPartitions_ ; |
---|
75 | |
---|
76 | const double eventLoopLatency_=0; |
---|
77 | double lastEventLoop_=0. ; |
---|
78 | |
---|
79 | }; |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | #endif |
---|