From 7e402665abc99f8ed0fd5d91434405ba6c1f1319 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 27 Oct 2014 17:27:15 +0100 Subject: [PATCH] First executable test. --- idl/SALOME_SDS.idl | 5 ++ src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 49 +++++++++++++++++-- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 4 +- src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 18 ++++++- src/SALOMESDS/SALOMESDS_DataServerManager.hxx | 3 +- 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index a9bcab6c9..6bb48f433 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -20,6 +20,8 @@ module SALOME { + typedef sequence StringVec; + interface BasicDataServer { string getVarName(); @@ -40,12 +42,15 @@ module SALOME interface DataScopeServer { string getScopeName(); + StringVec listVars(); + BasicDataServer retrieveVar(in string varName); StringDataServer createGlobalStringVar(in string varName); AnyDataServer createGlobalAnyVar(in string varName); }; interface DataServerManager { + StringVec listScopes(); DataScopeServer getDefaultScope(); DataScopeServer createDataScope(in string scopeName); DataScopeServer retriveDataScope(in string scopeName); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 0692c3fa2..eed86acd9 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -24,6 +24,7 @@ #include "SALOMESDS_Exception.hxx" #include +#include #include using namespace SALOMESDS; @@ -44,6 +45,44 @@ char *DataScopeServer::getScopeName() return CORBA::string_dup(_name.c_str()); } +/*! + * Called remotely -> to protect against throw + */ +SALOME::StringVec *DataScopeServer::listVars() +{ + SALOME::StringVec *ret(new SALOME::StringVec); + std::size_t sz(_vars.size()); + ret->length(sz); + std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > >::iterator it(_vars.begin()); + for(std::size_t i=0;igetVarNameCpp()); + (*ret)[i]=CORBA::string_dup(name.c_str()); + } + return ret; +} + +/*! + * Called remotely -> to protect against throw + */ +SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName) +{ + std::string varNameCpp(varName); + std::vector allNames(getAllVarNames()); + std::vector::iterator it(std::find(allNames.begin(),allNames.end(),varNameCpp)); + if(it==allNames.end()) + { + std::ostringstream oss; oss << "DataScopeServer::retrieveVar : name \"" << varNameCpp << "\" does not exists ! Possibilities are :"; + std::copy(allNames.begin(),allNames.end(),std::ostream_iterator(oss,", ")); + throw Exception(oss.str()); + } + std::size_t pos(std::distance(allNames.begin(),it)); + std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > >::iterator it0(_vars.begin()); + for(std::size_t i=0;i to protect against throw */ @@ -58,8 +97,9 @@ SALOME::StringDataServer_ptr DataScopeServer::createGlobalStringVar(const char * throw Exception(oss.str()); } AutoRefCountPtr tmp(new StringDataServer(varNameCpp)); - _vars.push_back(DynamicCastSafe(tmp)); CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(tmp)); + _vars.push_back(p); return SALOME::StringDataServer::_narrow(ret); } @@ -77,8 +117,9 @@ SALOME::AnyDataServer_ptr DataScopeServer::createGlobalAnyVar(const char *varNam throw Exception(oss.str()); } AutoRefCountPtr tmp(new AnyDataServer(varNameCpp)); - _vars.push_back(DynamicCastSafe(tmp)); CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe(tmp)); + _vars.push_back(p); return SALOME::AnyDataServer::_narrow(ret); } @@ -86,9 +127,9 @@ std::vector< std::string > DataScopeServer::getAllVarNames() const { std::size_t sz(_vars.size()); std::vector ret(sz); - std::list< AutoRefCountPtr >::const_iterator it(_vars.begin()); + std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > >::const_iterator it(_vars.begin()); for(std::size_t i=0;igetVarNameCpp(); + ret[i]=(*it).second->getVarNameCpp(); return ret; } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index e47d1fa2c..25409bf92 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -40,6 +40,8 @@ namespace SALOMESDS DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName); DataScopeServer(const DataScopeServer& other); char *getScopeName(); + SALOME::StringVec *listVars(); + SALOME::BasicDataServer_ptr retrieveVar(const char *varName); SALOME::StringDataServer_ptr createGlobalStringVar(const char *varName); SALOME::AnyDataServer_ptr createGlobalAnyVar(const char *varName); private: @@ -48,7 +50,7 @@ namespace SALOMESDS private: CORBA::ORB_var _orb; std::string _name; - std::list< AutoRefCountPtr > _vars; + std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > > _vars; }; } diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 3be1d6e05..ac81e710f 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -51,12 +51,28 @@ DataServerManager::DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr id=_poa->activate_object(_dft_scope); obj=_poa->id_to_reference(id); _ptr_dft_scope=SALOME::DataScopeServer::_narrow(obj); - _scopes.push_back(_dft_scope); + _scopes.push_back(_ptr_dft_scope); // std::string fullNameInNS(CreateAbsNameInNSFromScopeName(DFT_SCOPE_NAME_IN_NS)); ns.Register(_ptr_dft_scope,fullNameInNS.c_str()); } +SALOME::StringVec *DataServerManager::listScopes() +{ + SALOME::StringVec *ret(new SALOME::StringVec); + std::size_t sz(_scopes.size()); + ret->length(sz); + std::list< SALOME::DataScopeServer_var >::iterator it(_scopes.begin()); + for(std::size_t i=0;igetScopeName()); + (*ret)[i]=CORBA::string_dup(name); + CORBA::string_free(name); + } + return ret; +} + SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope() { return SALOME::DataScopeServer::_duplicate(_ptr_dft_scope); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx index 731739baa..323ce0384 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -38,6 +38,7 @@ namespace SALOMESDS { public: DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); + SALOME::StringVec *listScopes(); SALOME::DataScopeServer_ptr getDefaultScope(); SALOME::DataScopeServer_ptr createDataScope(const char *scopeName); SALOME::DataScopeServer_ptr retriveDataScope(const char *scopeName); @@ -49,7 +50,7 @@ namespace SALOMESDS private: AutoRefCountPtr _dft_scope; SALOME::DataScopeServer_var _ptr_dft_scope; - std::list< AutoRefCountPtr > _scopes; + std::list< SALOME::DataScopeServer_var > _scopes; CORBA::ORB_var _orb; //! single thread poa PortableServer::POA_var _poa; -- 2.39.2