]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
First executable test.
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 27 Oct 2014 16:27:15 +0000 (17:27 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 27 Oct 2014 16:27:15 +0000 (17:27 +0100)
idl/SALOME_SDS.idl
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_DataServerManager.cxx
src/SALOMESDS/SALOMESDS_DataServerManager.hxx

index a9bcab6c9652eb582c854dc63f929b1e3091eb5c..6bb48f433f50f3a8357446fdb3ad8e36e4445933 100644 (file)
@@ -20,6 +20,8 @@
 
 module SALOME
 {
+  typedef sequence<string> 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);
index 0692c3fa2367b0122dee6b5f25cb37e5b79f61f7..eed86acd90cc8252534c64b7db8eaa17644b20a7 100644 (file)
@@ -24,6 +24,7 @@
 #include "SALOMESDS_Exception.hxx"
 
 #include <sstream>
+#include <iterator>
 #include <algorithm>
 
 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<BasicDataServer> > >::iterator it(_vars.begin());
+  for(std::size_t i=0;i<sz;it++,i++)
+    {
+      BasicDataServer *obj((*it).second);
+      std::string name(obj->getVarNameCpp());
+      (*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<std::string> allNames(getAllVarNames());
+  std::vector<std::string>::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<std::string>(oss,", "));
+      throw Exception(oss.str());
+    }
+  std::size_t pos(std::distance(allNames.begin(),it));
+  std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > >::iterator it0(_vars.begin());
+  for(std::size_t i=0;i<pos;i++,it0++);
+  return SALOME::BasicDataServer::_duplicate((*it0).first);
+}
+
 /*!
  * Called remotely -> to protect against throw
  */
@@ -58,8 +97,9 @@ SALOME::StringDataServer_ptr DataScopeServer::createGlobalStringVar(const char *
       throw Exception(oss.str());
     }
   AutoRefCountPtr<StringDataServer> tmp(new StringDataServer(varNameCpp));
-  _vars.push_back(DynamicCastSafe<StringDataServer,BasicDataServer>(tmp));
   CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
+  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<StringDataServer,BasicDataServer>(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<AnyDataServer> tmp(new AnyDataServer(varNameCpp));
-  _vars.push_back(DynamicCastSafe<AnyDataServer,BasicDataServer>(tmp));
   CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
+  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<AnyDataServer,BasicDataServer>(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<std::string> ret(sz);
-  std::list< AutoRefCountPtr<BasicDataServer> >::const_iterator it(_vars.begin());
+  std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > >::const_iterator it(_vars.begin());
   for(std::size_t i=0;i<sz;it++,i++)
-    ret[i]=(*it)->getVarNameCpp();
+    ret[i]=(*it).second->getVarNameCpp();
   return ret;
 }
 
index e47d1fa2c2a9f4c0517015edc97dffe3b58a0d7c..25409bf925519fb17d5aba5eaa24c356b595f2cd 100644 (file)
@@ -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<BasicDataServer> > _vars;
+    std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > > _vars;
   };
 }
 
index 3be1d6e0537d07543c5ab9769f90837b1117ee27..ac81e710f86085d13039a8878e76d118a7a432b1 100644 (file)
@@ -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;i<sz;it++,i++)
+    {
+      SALOME::DataScopeServer_var obj(*it);
+      char *name(obj->getScopeName());
+      (*ret)[i]=CORBA::string_dup(name);
+      CORBA::string_free(name);
+    }
+  return ret;
+}
+
 SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope()
 {
   return SALOME::DataScopeServer::_duplicate(_ptr_dft_scope);
index 731739baaca3a813ad68a1f45c2dff36bc4e89bc..323ce0384750d2a7be1d84bf8806d048b4c70bac 100644 (file)
@@ -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<DataScopeServer> _dft_scope;
     SALOME::DataScopeServer_var _ptr_dft_scope;
-    std::list< AutoRefCountPtr<DataScopeServer> > _scopes;
+    std::list< SALOME::DataScopeServer_var > _scopes;
     CORBA::ORB_var _orb;
     //! single thread poa
     PortableServer::POA_var _poa;