1 | #include "daemons_manager.hpp" |
---|
2 | #include "cxios.hpp" |
---|
3 | #include "ressources_manager.hpp" |
---|
4 | #include "services_manager.hpp" |
---|
5 | #include "contexts_manager.hpp" |
---|
6 | #include "servers_ressource.hpp" |
---|
7 | #include "server.hpp" |
---|
8 | |
---|
9 | namespace xios |
---|
10 | { |
---|
11 | using namespace std ; |
---|
12 | |
---|
13 | CDaemonsManager::CDaemonsManager(bool isXiosServer) : isServer_(isXiosServer) |
---|
14 | { |
---|
15 | MPI_Comm xiosComm = CXios::getXiosComm() ; |
---|
16 | int commRank ; |
---|
17 | MPI_Comm_rank(xiosComm,&commRank) ; |
---|
18 | MPI_Comm splitComm ; |
---|
19 | MPI_Comm_split(xiosComm,isXiosServer,commRank,&splitComm) ; |
---|
20 | |
---|
21 | CXios::launchRegistryManager(isXiosServer) ; |
---|
22 | CXios::launchRessourcesManager(isXiosServer) ; |
---|
23 | CXios::launchServicesManager(isXiosServer) ; |
---|
24 | CXios::launchContextsManager(isXiosServer) ; |
---|
25 | CXios::launchCouplerManager(isXiosServer) ; |
---|
26 | CXios::launchThreadManager(isXiosServer) ; |
---|
27 | |
---|
28 | if (isXiosServer) CServer::launchServersRessource(splitComm) ; |
---|
29 | MPI_Barrier(xiosComm) ; |
---|
30 | MPI_Comm_free(&splitComm) ; |
---|
31 | } |
---|
32 | |
---|
33 | CDaemonsManager::~CDaemonsManager() |
---|
34 | { |
---|
35 | finalize() ; |
---|
36 | } |
---|
37 | |
---|
38 | bool CDaemonsManager::eventLoop(void) |
---|
39 | { |
---|
40 | |
---|
41 | CXios::getRessourcesManager()->eventLoop() ; |
---|
42 | CXios::getServicesManager()->eventLoop() ; |
---|
43 | CXios::getContextsManager()->eventLoop() ; |
---|
44 | if (isServer_) |
---|
45 | { |
---|
46 | if (CServer::isRoot) |
---|
47 | { |
---|
48 | CServer::listenOasisEnddef() ; |
---|
49 | CServer::listenRootOasisEnddef() ; |
---|
50 | } |
---|
51 | else CServer::listenRootOasisEnddef() ; |
---|
52 | |
---|
53 | if (CThreadManager::isUsingThreads()) return CServer::getServersRessource()->isFinished() ; |
---|
54 | else return CServer::getServersRessource()->eventLoop(false) ; |
---|
55 | } |
---|
56 | else return CXios::getPoolRessource()->eventLoop(false) ; |
---|
57 | } |
---|
58 | |
---|
59 | bool CDaemonsManager::servicesEventLoop(void) |
---|
60 | { |
---|
61 | CXios::getRessourcesManager()->eventLoop() ; |
---|
62 | CXios::getServicesManager()->eventLoop() ; |
---|
63 | CXios::getContextsManager()->eventLoop() ; |
---|
64 | if (isServer_) return CServer::getServersRessource()->eventLoop(true) ; |
---|
65 | else return CXios::getPoolRessource()->eventLoop(true) ; |
---|
66 | } |
---|
67 | |
---|
68 | bool CDaemonsManager::finalize(void) |
---|
69 | { |
---|
70 | if (!isFinalized_) |
---|
71 | { |
---|
72 | if (isServer_) CServer::getServersRessource()->finalizeSignal() ; |
---|
73 | else CXios::getPoolRessource()->finalizeSignal() ; |
---|
74 | while(!eventLoop()) ; |
---|
75 | MPI_Barrier( CXios::getXiosComm()) ; |
---|
76 | CXios::finalizeContextsManager() ; |
---|
77 | CXios::finalizeCouplerManager() ; |
---|
78 | CXios::finalizeServicesManager() ; |
---|
79 | CXios::finalizeRessourcesManager() ; |
---|
80 | CXios::finalizeRegistryManager() ; |
---|
81 | CXios::finalizeThreadManager() ; |
---|
82 | isFinalized_=true ; |
---|
83 | } |
---|
84 | return isFinalized_; |
---|
85 | } |
---|
86 | |
---|
87 | } |
---|