From f35d3c7d30e17e9141dfa71b9cb2ce7d09cdd9ed Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 27 Oct 2014 15:14:45 +0100 Subject: [PATCH] LauncherServer hostes DataServerManager and default DataScopeServer. --- src/Launcher/CMakeLists.txt | 2 + src/Launcher/SALOME_LauncherServer.cxx | 25 ++++++++---- .../Test/LifeCycleCORBATest.cxx | 1 + src/NamingService/SALOME_NamingService.hxx | 1 - src/NamingService/Test/NamingServiceTest.cxx | 1 + src/SALOMEDS/SALOMEDS_StudyManager.cxx | 3 +- src/SALOMESDS/CMakeLists.txt | 5 ++- src/SALOMESDS/SALOMESDS_AnyDataServer.hxx | 6 +-- src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 6 +-- src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 27 +++++++++++-- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 8 ++-- src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 40 ++++++++++++++++++- src/SALOMESDS/SALOMESDS_DataServerManager.hxx | 14 +++++-- src/SALOMESDS/SALOMESDS_StringDataServer.hxx | 6 +-- 14 files changed, 113 insertions(+), 32 deletions(-) diff --git a/src/Launcher/CMakeLists.txt b/src/Launcher/CMakeLists.txt index 4a14d0496..9757df6b9 100755 --- a/src/Launcher/CMakeLists.txt +++ b/src/Launcher/CMakeLists.txt @@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Notification ${CMAKE_CURRENT_SOURCE_DIR}/../Container ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager + ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMESDS ${PROJECT_BINARY_DIR}/idl ) @@ -95,6 +96,7 @@ IF(NOT SALOME_LAUNCHER_ONLY) SET(SALOME_LauncherServer_LIBS Launcher SalomeLauncher + SalomeSDS SALOMEBasics SALOMELocalTrace ${LIBBATCH_LIBRARIES} diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx index 4bb4ecfd9..b9ea0d7cf 100644 --- a/src/Launcher/SALOME_LauncherServer.cxx +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -21,6 +21,7 @@ // #include "SALOME_Launcher.hxx" +#include "SALOMESDS_DataServerManager.hxx" #include "utilities.h" #include #include @@ -85,18 +86,26 @@ int main(int argc, char* argv[]) if(!CORBA::is_nil(obj)) root_poa = PortableServer::POA::_narrow(obj); if(!CORBA::is_nil(root_poa)) - pman = root_poa->the_POAManager(); + { + pman = root_poa->the_POAManager(); + pman->activate(); + } } catch(CORBA::COMM_FAILURE&){ MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ); } - try{ - SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa); - pman->activate(); - lServ->_remove_ref(); - orb->run(); - orb->destroy(); - }catch(CORBA::SystemException&){ + try + { + SALOME_Launcher *lServ(new SALOME_Launcher(orb,root_poa)); + lServ->_remove_ref(); + // + SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(orb,root_poa)); + dsm->_remove_ref(); + // + orb->run(); + orb->destroy(); + } + catch(CORBA::SystemException&){ MESSAGE("Caught CORBA::SystemException."); }catch(PortableServer::POA::WrongPolicy&){ MESSAGE("Caught CORBA::WrongPolicyException."); diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx index f95cccdb9..a9805ca08 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx @@ -26,6 +26,7 @@ #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "Basics_Utils.hxx" +#include "utilities.h" #include #include diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index d6a53c28e..07605c6f7 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -35,7 +35,6 @@ #include #include -#include "utilities.h" #include "Utils_Mutex.hxx" #include "ServiceUnreachable.hxx" diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx index 8f8cf52fc..456b9d617 100644 --- a/src/NamingService/Test/NamingServiceTest.cxx +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -25,6 +25,7 @@ #include "Utils_SINGLETON.hxx" #include "Basics_Utils.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "utilities.h" #include #include diff --git a/src/SALOMEDS/SALOMEDS_StudyManager.cxx b/src/SALOMEDS/SALOMEDS_StudyManager.cxx index 3ffa83174..ce80b2644 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager.cxx @@ -35,7 +35,8 @@ #include "SALOMEDSImpl_Study.hxx" #include "Utils_ORB_INIT.hxx" -#include "Utils_SINGLETON.hxx" +#include "Utils_SINGLETON.hxx" +#include "utilities.h" #include "Basics_Utils.hxx" diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt index fa3169c1e..96964389e 100644 --- a/src/SALOMESDS/CMakeLists.txt +++ b/src/SALOMESDS/CMakeLists.txt @@ -22,11 +22,14 @@ INCLUDE_DIRECTORIES( ${OMNIORB_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/idl + ${PROJECT_BINARY_DIR}/salome_adm + ${CMAKE_CURRENT_SOURCE_DIR}/../Utils + ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService ) ADD_DEFINITIONS(${OMNIORB_DEFINITIONS}) -SET(COMMON_LIBS SalomeIDLKernel ${OMNIORB_LIBRARIES}) +SET(COMMON_LIBS SalomeNS SalomeIDLKernel ${OMNIORB_LIBRARIES}) SET(SalomeSDS_SOURCES SALOMESDS_Exception.cxx diff --git a/src/SALOMESDS/SALOMESDS_AnyDataServer.hxx b/src/SALOMESDS/SALOMESDS_AnyDataServer.hxx index c535357af..bba349a1e 100644 --- a/src/SALOMESDS/SALOMESDS_AnyDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_AnyDataServer.hxx @@ -21,10 +21,10 @@ #ifndef __SALOMESDS_ANYDATASERVER_HXX__ #define __SALOMESDS_ANYDATASERVER_HXX__ -#include "SALOMESDS_BasicDataServer.hxx" +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) -#include "SALOME_SDS.hh" -//#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMESDS_BasicDataServer.hxx" namespace SALOMESDS { diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index 6ff19db73..1a0b1ccff 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -21,10 +21,8 @@ #ifndef __SALOMESDS_BASICDATASERVER_HXX__ #define __SALOMESDS_BASICDATASERVER_HXX__ -#include "SALOMESDS_AutoRefCountPtr.hxx" - -#include "SALOME_SDS.hh" -//#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) #include "SALOMESDS_RefCountServ.hxx" diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 969501947..5de47052f 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -28,7 +28,7 @@ using namespace SALOMESDS; -DataScopeServer::DataScopeServer(const std::string& scopeName):_name(scopeName) +DataScopeServer::DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName):_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName) { } @@ -59,7 +59,8 @@ SALOME::StringDataServer_ptr DataScopeServer::createGlobalStringVar(const char * } AutoRefCountPtr tmp(new StringDataServer(varNameCpp)); _vars.push_back(DynamicCastSafe(tmp)); - return tmp->_this(); + CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + return SALOME::StringDataServer::_narrow(ret); } /*! @@ -77,7 +78,8 @@ SALOME::AnyDataServer_ptr DataScopeServer::createGlobalAnyVar(const char *varNam } AutoRefCountPtr tmp(new AnyDataServer(varNameCpp)); _vars.push_back(DynamicCastSafe(tmp)); - return tmp->_this(); + CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + return SALOME::AnyDataServer::_narrow(ret); } std::vector< std::string > DataScopeServer::getAllVarNames() const @@ -89,3 +91,22 @@ std::vector< std::string > DataScopeServer::getAllVarNames() const ret[i]=(*it)->getVarNameCpp(); return ret; } + +CORBA::Object_var DataScopeServer::activateWithDedicatedPOA(BasicDataServer *ds) +{ + CORBA::Object_var obj(_orb->resolve_initial_references("RootPOA")); + PortableServer::POA_var rootPoa; + if(!CORBA::is_nil(obj)) + rootPoa=PortableServer::POA::_narrow(obj); + PortableServer::POAManager_var pman(rootPoa->the_POAManager()); + CORBA::PolicyList policies; + policies.length(1); + PortableServer::ThreadPolicy_var threadPol(rootPoa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + PortableServer::POA_var poa(rootPoa->create_POA("SingleThPOA4SDS",pman,policies)); + threadPol->destroy(); + // + PortableServer::ObjectId_var id(poa->activate_object(ds)); + CORBA::Object_var ret(poa->id_to_reference(id)); + return ret; +} diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 030b17989..e47d1fa2c 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -21,8 +21,8 @@ #ifndef __SALOMESDS_DATASCOPEERVER_HXX__ #define __SALOMESDS_DATASCOPEERVER_HXX__ -#include "SALOME_SDS.hh" -//#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) #include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_RefCountServ.hxx" @@ -37,14 +37,16 @@ namespace SALOMESDS class DataScopeServer : public RefCountServ, public virtual POA_SALOME::DataScopeServer { public: - DataScopeServer(const std::string& scopeName); + DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName); DataScopeServer(const DataScopeServer& other); char *getScopeName(); SALOME::StringDataServer_ptr createGlobalStringVar(const char *varName); SALOME::AnyDataServer_ptr createGlobalAnyVar(const char *varName); private: std::vector< std::string> getAllVarNames() const; + CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds); private: + CORBA::ORB_var _orb; std::string _name; std::list< AutoRefCountPtr > _vars; }; diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 993158969..3be1d6e05 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -21,15 +21,45 @@ #include "SALOMESDS_DataServerManager.hxx" #include "SALOMESDS_Exception.hxx" +#include "SALOME_NamingService.hxx" + +#include + using namespace SALOMESDS; -DataServerManager::DataServerManager():_dft_scope(new DataScopeServer("")) +const char DataServerManager::NAME_IN_NS[]="/DataServerManager"; + +const char DataServerManager::DFT_SCOPE_NAME_IN_NS[]="Default"; + +DataServerManager::DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_dft_scope(new DataScopeServer(orb,DFT_SCOPE_NAME_IN_NS)),_orb(CORBA::ORB::_duplicate(orb)) { + PortableServer::POAManager_var pman(poa->the_POAManager()); + CORBA::PolicyList policies; + policies.length(1); + PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + _poa=poa->create_POA("SingleThPOA4SDS",pman,policies); + threadPol->destroy(); + // activate this to be ready to be usable from NS. + PortableServer::ObjectId_var id(_poa->activate_object(this)); + CORBA::Object_var obj(_poa->id_to_reference(id)); + SALOME::DataServerManager_var obj2(SALOME::DataServerManager::_narrow(obj)); + // publish Data server manager in NS + SALOME_NamingService ns(orb); + ns.Register(obj2,NAME_IN_NS); + // the default DataScopeServer object is the only one hosted by the current process + id=_poa->activate_object(_dft_scope); + obj=_poa->id_to_reference(id); + _ptr_dft_scope=SALOME::DataScopeServer::_narrow(obj); + _scopes.push_back(_dft_scope); + // + std::string fullNameInNS(CreateAbsNameInNSFromScopeName(DFT_SCOPE_NAME_IN_NS)); + ns.Register(_ptr_dft_scope,fullNameInNS.c_str()); } SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope() { - + return SALOME::DataScopeServer::_duplicate(_ptr_dft_scope); } SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName) @@ -43,3 +73,9 @@ SALOME::DataScopeServer_ptr DataServerManager::retriveDataScope(const char *scop SALOME::DataScopeServer_ptr DataServerManager::removeDataScope(const char *scopeName) { } + +std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& scopeName) +{ + std::ostringstream oss; oss << NAME_IN_NS << "/" << scopeName; + return oss.str(); +} diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx index d0629c75b..731739baa 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -21,8 +21,8 @@ #ifndef __SALOMESDS_DATASERVERMANAGER_HXX__ #define __SALOMESDS_DATASERVERMANAGER_HXX__ -#include "SALOME_SDS.hh" -//#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) #include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_DataScopeServer.hxx" @@ -37,14 +37,22 @@ namespace SALOMESDS class DataServerManager : public virtual POA_SALOME::DataServerManager { public: - DataServerManager(); + DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); SALOME::DataScopeServer_ptr getDefaultScope(); SALOME::DataScopeServer_ptr createDataScope(const char *scopeName); SALOME::DataScopeServer_ptr retriveDataScope(const char *scopeName); SALOME::DataScopeServer_ptr removeDataScope(const char *scopeName); + static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName); + public: + static const char NAME_IN_NS[]; + static const char DFT_SCOPE_NAME_IN_NS[]; private: AutoRefCountPtr _dft_scope; + SALOME::DataScopeServer_var _ptr_dft_scope; std::list< AutoRefCountPtr > _scopes; + CORBA::ORB_var _orb; + //! single thread poa + PortableServer::POA_var _poa; }; } diff --git a/src/SALOMESDS/SALOMESDS_StringDataServer.hxx b/src/SALOMESDS/SALOMESDS_StringDataServer.hxx index 7b054f4a0..55f323d6a 100644 --- a/src/SALOMESDS/SALOMESDS_StringDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_StringDataServer.hxx @@ -21,10 +21,10 @@ #ifndef __SALOMESDS_STRINGDATASERVER_HXX__ #define __SALOMESDS_STRINGDATASERVER_HXX__ -#include "SALOMESDS_BasicDataServer.hxx" +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) -#include "SALOME_SDS.hh" -//#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMESDS_BasicDataServer.hxx" namespace SALOMESDS { -- 2.39.2