[1761] | 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 | |
---|
[2209] | 21 | CXios::launchRegistryManager(isXiosServer) ; |
---|
[1761] | 22 | CXios::launchRessourcesManager(isXiosServer) ; |
---|
| 23 | CXios::launchServicesManager(isXiosServer) ; |
---|
| 24 | CXios::launchContextsManager(isXiosServer) ; |
---|
[1878] | 25 | CXios::launchCouplerManager(isXiosServer) ; |
---|
[2547] | 26 | CXios::launchThreadManager(isXiosServer) ; |
---|
[2209] | 27 | |
---|
[1761] | 28 | if (isXiosServer) CServer::launchServersRessource(splitComm) ; |
---|
[2209] | 29 | MPI_Barrier(xiosComm) ; |
---|
[1761] | 30 | MPI_Comm_free(&splitComm) ; |
---|
| 31 | } |
---|
| 32 | |
---|
[1764] | 33 | CDaemonsManager::~CDaemonsManager() |
---|
| 34 | { |
---|
[2266] | 35 | finalize() ; |
---|
[1764] | 36 | } |
---|
| 37 | |
---|
[1761] | 38 | bool CDaemonsManager::eventLoop(void) |
---|
| 39 | { |
---|
[2246] | 40 | |
---|
[1761] | 41 | CXios::getRessourcesManager()->eventLoop() ; |
---|
| 42 | CXios::getServicesManager()->eventLoop() ; |
---|
| 43 | CXios::getContextsManager()->eventLoop() ; |
---|
[2547] | 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) ; |
---|
[2333] | 55 | } |
---|
[1764] | 56 | else return CXios::getPoolRessource()->eventLoop(false) ; |
---|
[1761] | 57 | } |
---|
[1764] | 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 | } |
---|
[1761] | 67 | |
---|
[2266] | 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() ; |
---|
[2547] | 81 | CXios::finalizeThreadManager() ; |
---|
[2266] | 82 | isFinalized_=true ; |
---|
| 83 | } |
---|
[2277] | 84 | return isFinalized_; |
---|
[2266] | 85 | } |
---|
| 86 | |
---|
[2277] | 87 | } |
---|