]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Almost ready to be used. Valgrind OK on TestSalomeSDS2.
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 15 Jan 2015 15:43:37 +0000 (16:43 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 15 Jan 2015 15:43:37 +0000 (16:43 +0100)
13 files changed:
idl/SALOME_SDS.idl
src/SALOMESDS/SALOMESDS_BasicDataServer.cxx
src/SALOMESDS/SALOMESDS_BasicDataServer.hxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_DataServerManager.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.hxx
src/SALOMESDS/SalomeSDSClt.py
src/SALOMESDS/TestSalomeSDS2.py [new file with mode: 0644]

index 61099d2898e6d3b22172d97afb61d6d943562b16..dd2782a40f844de58693b82ea9fa4a0b35ace922 100644 (file)
@@ -26,8 +26,11 @@ module SALOME
   typedef sequence<string> StringVec;
   typedef sequence<octet> ByteVec;
   
+  interface DataScopeServer;
+
   interface BasicDataServer : GenericObj
   {
+    DataScopeServer getMyDataScopeServer();
     string getVarName();
     string getScopeName();
   };
@@ -60,6 +63,7 @@ module SALOME
     string getScopeName();
     StringVec listVars();
     BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception);
+    void deleteVar(in string varName) raises (SALOME::SALOME_Exception);
     PickelizedPyObjRdOnlyServer createRdOnlyVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
     PickelizedPyObjRdExtServer createRdExtVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
     PickelizedPyObjRdWrServer createRdWrVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception);
index 4d3e89151fdb2e32ca4bb0fb9bc53a61bce3c010..00a639b3489e6d42dfcbcae3b2ae4de3498853f0 100644 (file)
@@ -30,6 +30,12 @@ BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& var
 {
 }
 
+SALOME::DataScopeServer_ptr BasicDataServer::getMyDataScopeServer()
+{
+  CORBA::Object_var obj(getPOA()->servant_to_reference(_father));
+  return SALOME::DataScopeServer::_narrow(obj);
+}
+
 /*!
  * Called remotely -> to protect against throw
  */
@@ -57,3 +63,8 @@ void BasicDataServer::Destroy()
 {
   enforcedRelease();
 }
+
+PortableServer::POA_var BasicDataServer::getPOA()
+{
+  return _father->getPOA();
+}
index e0ed15dbf783ee7c3fad3ab649b3bb12c2464426..3115064c054d0e75e05043164c3a69124f0e9723 100644 (file)
@@ -36,6 +36,7 @@ namespace SALOMESDS
   {
   public:
     BasicDataServer(DataScopeServer *father, const std::string& varName);
+    SALOME::DataScopeServer_ptr getMyDataScopeServer();
     char *getVarName();
     char *getScopeName();
   public:
@@ -44,6 +45,8 @@ namespace SALOMESDS
     void Destroy();
   public:
     std::string getVarNameCpp() const { return _var_name; }
+  protected:
+    PortableServer::POA_var getPOA();
   protected:
     DataScopeServer *_father;
   private:
index d2ab4e60527b565ff98facb3bc574c669abdc4c3..3ff2e0479555afd4126f862c9dfa350016987c47 100644 (file)
@@ -80,7 +80,7 @@ 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());
+  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(_vars.begin());
   for(std::size_t i=0;i<sz;it++,i++)
     {
       BasicDataServer *obj((*it).second);
@@ -90,9 +90,6 @@ SALOME::StringVec *DataScopeServer::listVars()
   return ret;
 }
 
-/*!
- * Called remotely -> to protect against throw
- */
 SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName)
 {
   std::string varNameCpp(varName);
@@ -105,18 +102,35 @@ SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName)
       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());
+  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin());
   for(std::size_t i=0;i<pos;i++,it0++);
   return SALOME::BasicDataServer::_duplicate((*it0).first);
 }
 
+void DataScopeServer::deleteVar(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::deleteVar : 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, BasicDataServer * > >::iterator it0(_vars.begin());
+  (*it0).first->UnRegister();
+  _vars.erase(it0);
+}
+
 SALOME::PickelizedPyObjRdOnlyServer_ptr DataScopeServer::createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue)
 {
   std::string varNameCpp(varName);
   checkNotAlreadyExistingVar(varNameCpp);
-  AutoRefCountPtr<PickelizedPyObjRdOnlyServer> tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue));
+  PickelizedPyObjRdOnlyServer *tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue));
   CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
-  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<PickelizedPyObjRdOnlyServer,BasicDataServer>(tmp));
+  std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
   _vars.push_back(p);
   return SALOME::PickelizedPyObjRdOnlyServer::_narrow(ret);
 }
@@ -125,9 +139,9 @@ SALOME::PickelizedPyObjRdExtServer_ptr DataScopeServer::createRdExtVar(const cha
 {
   std::string varNameCpp(varName);
   checkNotAlreadyExistingVar(varNameCpp);
-  AutoRefCountPtr<PickelizedPyObjRdExtServer> tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue));
+  PickelizedPyObjRdExtServer *tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue));
   CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
-  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<PickelizedPyObjRdExtServer,BasicDataServer>(tmp));
+  std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
   _vars.push_back(p);
   return SALOME::PickelizedPyObjRdExtServer::_narrow(ret);
 }
@@ -139,9 +153,9 @@ SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char
 {
   std::string varNameCpp(varName),typeNameCpp(typeName);
   checkNotAlreadyExistingVar(varNameCpp);
-  AutoRefCountPtr<PickelizedPyObjRdWrServer> tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp));
+  PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp));
   CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
-  std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > p(SALOME::BasicDataServer::_narrow(ret),DynamicCastSafe<PickelizedPyObjRdWrServer,BasicDataServer>(tmp));
+  std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
   _vars.push_back(p);
   return SALOME::PickelizedPyObjRdWrServer::_narrow(ret);
 }
@@ -231,7 +245,7 @@ std::vector< std::string > DataScopeServer::getAllVarNames() const
 {
   std::size_t sz(_vars.size());
   std::vector<std::string> ret(sz);
-  std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > >::const_iterator it(_vars.begin());
+  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator it(_vars.begin());
   for(std::size_t i=0;i<sz;it++,i++)
     ret[i]=(*it).second->getVarNameCpp();
   return ret;
@@ -239,23 +253,8 @@ std::vector< std::string > DataScopeServer::getAllVarNames() const
 
 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);
-  std::string name(ds->getVarNameCpp());
-  std::ostringstream oss; oss << "POA@" << name;
-  std::string zePOAName(oss.str());
-  PortableServer::POA_var poa(rootPoa->create_POA(zePOAName.c_str(),pman,policies));
-  threadPol->destroy();
-  //
-  PortableServer::ObjectId_var id(poa->activate_object(ds));
-  CORBA::Object_var ret(poa->id_to_reference(id));
+  PortableServer::ObjectId_var id(_poa->activate_object(ds));
+  CORBA::Object_var ret(_poa->id_to_reference(id));
   return ret;
 }
 
@@ -265,7 +264,7 @@ void DataScopeServer::checkNotAlreadyExistingVar(const std::string& varName)
   std::vector<std::string>::iterator it(std::find(allNames.begin(),allNames.end(),varName));
   if(it!=allNames.end())
     {
-      std::ostringstream oss; oss << "DataScopeServer::createGlobalStringVar : name \"" << varName << "\" already exists !";
+      std::ostringstream oss; oss << "DataScopeServer::checkNotAlreadyExistingVar : name \"" << varName << "\" already exists !";
       throw Exception(oss.str());
     }
 }
index 2f95251af8aa39f423282848a80ccdf44b72c179..1147ba66586834e89fd05e10d293e10a2ccf7246 100644 (file)
@@ -45,6 +45,7 @@ namespace SALOMESDS
     char *getScopeName();
     SALOME::StringVec *listVars();
     SALOME::BasicDataServer_ptr retrieveVar(const char *varName);
+    void deleteVar(const char *varName);
     SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
     SALOME::PickelizedPyObjRdExtServer_ptr createRdExtVar(const char *varName, const SALOME::ByteVec& constValue);
     SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName);
@@ -70,7 +71,7 @@ namespace SALOMESDS
     PortableServer::POA_var _poa;
     CORBA::ORB_var _orb;
     std::string _name;
-    std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr<BasicDataServer> > > _vars;
+    std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars;
     static std::size_t COUNTER;
   };
 }
index 0193b507661a6136c48e8ebd1917ce461145355a..003539143d9ffd477fb913994afd7b01342fd378 100644 (file)
@@ -119,10 +119,12 @@ SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scope
   //
   SALOME_NamingService ns(_orb);
   std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName));
-  std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " ";
+  std::ostringstream oss; oss << "valgrind --leak-check=yes SALOME_DataScopeServer" << " " << scopeName << " ";
   SALOME_ContainerManager::AddOmninamesParams(oss,&ns);
   std::string command(oss.str());
-  SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command);
+  //SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command);
+  command+=" > err.log 2>&1 &";
+  std::cerr << "************** " << command << std::endl;
   int status(SALOME_ContainerManager::SystemThreadSafe(command.c_str()));
   int count(SALOME_ContainerManager::GetTimeOutToLoaunchServer());
   SALOME::DataScopeServer_var ret(SALOME::DataScopeServer::_nil());
index 752669d7d1c010dfc9e85bcf5937f6e6f555c941..5409851c0fb69e5e3544dd7de42e4a5a11c00705 100644 (file)
@@ -47,10 +47,10 @@ SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonM
 {
   if(!_self)
     throw Exception("PickelizedPyObjRdExtServer::invokePythonMethodOn : self is NULL !");
-  checkRdExtnessOf(method);
   std::string argsCpp;
   FromByteSeqToCpp(args,argsCpp);
   PyObject *argsPy(getPyObjFromPickled(argsCpp));
+  checkRdExtnessOf(method,argsPy);
   //
   PyObject *selfMeth(PyObject_GetAttrString(_self,method));
   if(!selfMeth)
@@ -68,42 +68,70 @@ SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonM
     }
   PickelizedPyObjRdExtServer *ret(new PickelizedPyObjRdExtServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
   PortableServer::POA_var poa(_father->getPOA());
-  ret->setPOA(poa);
   PortableServer::ObjectId_var id(poa->activate_object(ret));
   CORBA::Object_var obj(poa->id_to_reference(id));
   return SALOME::PickelizedPyObjRdExtServer::_narrow(obj);
 }
 
-void PickelizedPyObjRdExtServer::checkRdExtnessOf(const std::string& methodName)
+void PickelizedPyObjRdExtServer::checkRdExtnessOf(const std::string& methodName, PyObject *argsPy)
 {
   if(!_self)
-    throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : self is NULL !");
+    {
+      Py_XDECREF(argsPy);
+      throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : self is NULL !");
+    }
   if(PyTuple_Check(_self)==1 || PyString_Check(_self)==1 || PyInt_Check(_self)==1 || PyBool_Check(_self)==1 || PyFloat_Check(_self)==1)
     return ;//_self is tuple, str, int or float -> immutable in python. So no method can break the RdExtness of _self.
   if(PyList_Check(_self)==1)
-    checkListRdExtnessOf(methodName);
+    checkListRdExtnessOf(methodName,argsPy);
   else if(PyDict_Check(_self)==1)
-    checkDictRdExtnessOf(methodName);
+    checkDictRdExtnessOf(methodName,argsPy);
   else
     throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : Supported python types are [list,tuple,dict,str,int,float] !");
 }
 
-void PickelizedPyObjRdExtServer::checkListRdExtnessOf(const std::string& methodName)
+void PickelizedPyObjRdExtServer::checkListRdExtnessOf(const std::string& methodName, PyObject *argsPy)
 {
   static const char *THE_RDEXT_METH_OF_LIST[]={"__getitem__","append","extend","insert","reverse","sort"};
   for(std::size_t i=0;i<sizeof(THE_RDEXT_METH_OF_LIST)/sizeof(const char *);i++)
     if(methodName==THE_RDEXT_METH_OF_LIST[i])
       return ;
-  std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::checkListRdExtnessOf : The method \"" << methodName << "\" is a method that can lead to a loss of data ! Supported method of \"list \"without loss of data are : __getitem__, append, extend, insert,reverse, sort !";
+  Py_XDECREF(argsPy);
+  std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::checkListRdExtnessOf : The method \"" << methodName << "\" is a method that can lead to a loss of data ! Supported method of \"list \"without loss of data are : __getitem__, append, extend, insert, reverse, sort !";
   throw Exception(oss.str());
 }
 
-void PickelizedPyObjRdExtServer::checkDictRdExtnessOf(const std::string& methodName)
+void PickelizedPyObjRdExtServer::checkDictRdExtnessOf(const std::string& methodName, PyObject *argsPy)
 {
   static const char *THE_RDEXT_METH_OF_DICT[]={"__getitem__","get","items","keys","setdefault","update","values"};
   for(std::size_t i=0;i<sizeof(THE_RDEXT_METH_OF_DICT)/sizeof(const char *);i++)
     if(methodName==THE_RDEXT_METH_OF_DICT[i])
       return ;
-  std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::checkDictRdExtnessOf : The method \"" << methodName << "\" is a method that can lead to a loss of data ! Supported method of \"list \"without loss of data are : __getitem__, get, items, keys, setdefault, update, values !";
+  if(methodName=="__setitem__")
+    {
+      checkDictSetitemRdExtness(argsPy);
+      return ;
+    }
+  Py_XDECREF(argsPy);
+  std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::checkDictRdExtnessOf : The method \"" << methodName << "\" is a method that can lead to a loss of data ! Supported method of \"list \"without loss of data are : __getitem__, __setitem__(with conditions), get, items, keys, setdefault, update, values !";
   throw Exception(oss.str());
 }
+
+void PickelizedPyObjRdExtServer::checkDictSetitemRdExtness(PyObject *argsPy)
+{
+  if(PyTuple_Check(argsPy)==0)
+    {
+      Py_XDECREF(argsPy);
+      throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : args of dic(self).__setitem__ is not a tuple !");
+    }
+  if(PyTuple_Size(argsPy)!=2)
+    {
+      Py_XDECREF(argsPy);
+      throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : tuple of dic(self).__setitem__ has not a size equal to 2 !");
+    }
+  if(PyDict_GetItem(_self,PyTuple_GetItem(argsPy,0))!=0)
+    {// argsPy[0] is already a key of _self -> __setitem__ is NOT RdExt !
+      Py_XDECREF(argsPy);
+      throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : specified key of __setitem__ already exists ! RdExt property is not applied !");
+    }
+}
index 293b64aa681d1890373a9dcbbbd03635c5f4097d..ea62b734e7d133f1c196be4ae83782d570b26e2b 100644 (file)
@@ -38,9 +38,10 @@ namespace SALOMESDS
     ~PickelizedPyObjRdExtServer();
     SALOME::PickelizedPyObjRdExtServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
   private:
-    void checkRdExtnessOf(const std::string& methodName);
-    void checkListRdExtnessOf(const std::string& methodName);
-    void checkDictRdExtnessOf(const std::string& methodName);
+    void checkRdExtnessOf(const std::string& methodName, PyObject *argsPy);
+    void checkListRdExtnessOf(const std::string& methodName, PyObject *argsPy);
+    void checkDictRdExtnessOf(const std::string& methodName, PyObject *argsPy);
+    void checkDictSetitemRdExtness(PyObject *argsPy);
   };
 }
 
index 64459730f5b1fcbf786d1bf2bc367322dd1b2e92..848cefc1626fff6723ab74869ebc0848f81090ed 100644 (file)
@@ -104,7 +104,6 @@ SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMet
     }
   PickelizedPyObjRdWrServer *ret(new PickelizedPyObjRdWrServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res));
   PortableServer::POA_var poa(_father->getPOA());
-  ret->setPOA(poa);
   PortableServer::ObjectId_var id(poa->activate_object(ret));
   CORBA::Object_var obj(poa->id_to_reference(id));
   return SALOME::PickelizedPyObjRdWrServer::_narrow(obj);
index 3cfa90d845334e798789f9ac166aab038ca6f8fb..baba4b55dada2a18f7d72449e0e7da638e2f7cfd 100644 (file)
@@ -40,7 +40,6 @@ PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std:
 
 PickelizedPyObjServer::~PickelizedPyObjServer()
 {
-  std::cerr << "~~~~~~~~~~ PickelizedPyObjServer : " << getVarNameCpp() << std::endl;
   Py_XDECREF(_self);
 }
 
@@ -53,11 +52,6 @@ SALOME::ByteVec *PickelizedPyObjServer::fetchSerializedContent()
   return FromCppToByteSeq(pickelize(_self));
 }
 
-PortableServer::POA_var PickelizedPyObjServer::getPOA()
-{
-  return _poa;
-}
-
 void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
 {
   std::size_t sz(bsToBeConv.length());
index cc691bdb8485c6a9089642d8870a55ff16afa86f..ba8af50b9d864217ad238c87cbde22c2ce23d76f 100644 (file)
@@ -38,10 +38,7 @@ namespace SALOMESDS
     ~PickelizedPyObjServer();
     void setSerializedContent(const SALOME::ByteVec& newValue);
     SALOME::ByteVec *fetchSerializedContent();
-  public:
-    void setPOA(PortableServer::POA_var poa) { _poa=poa; }
   protected:
-    PortableServer::POA_var getPOA();
     static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
     static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv);
     PyObject *getPyObjFromPickled(const std::string& pickledData);
index 1126024877403a95c13ab90bf5e87f1393c65e52..9b9218c621c2350bec352ab3dda856f4f74cb580 100644 (file)
@@ -24,7 +24,7 @@ import cPickle
 
 class WrappedType(object):
     def __init__(self,varPtr,isTemporaryVar=False):
-        assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer))
+        assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer))
         self._var_ptr=varPtr
         if not isTemporaryVar:
             self._var_ptr.Register()
@@ -44,6 +44,7 @@ class WrappedType(object):
         return (self._wrapped_type,(self.local_copy(),))
 
     def assign(self,elt):
+        assert(isinstance(self._var_ptr,SALOME._objref_PickelizedPyObjRdWrServer))
         st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL)
         self._var_ptr.setSerializedContent(st)
         pass
@@ -449,7 +450,7 @@ class String(WrappedType):
 
 class Caller:
     def __init__(self,varPtr,meth):
-        assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer))
+        assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer))
         self._var_ptr=varPtr
         self._meth=meth
         pass
@@ -464,9 +465,10 @@ PyHandlerTypeMap={int:Int,float:Float,str:String,list:List,tuple:Tuple,dict:Dict
 def GetHandlerFromRef(objCorba,isTempVar=False):
     """ Returns a client that allows to handle a remote corba ref of a global var easily.
     """
-    assert(isinstance(objCorba,SALOME._objref_PickelizedPyObjRdWrServer))
+    assert(isinstance(objCorba,SALOME._objref_PickelizedPyObjServer))
     v=cPickle.loads(objCorba.fetchSerializedContent())
     if v is None:
+        objCorba.UnRegister()
         return None
     return PyHandlerTypeMap[v.__class__](objCorba,isTempVar)
     
@@ -474,13 +476,13 @@ def GetHandlerFromRef(objCorba,isTempVar=False):
 def CreateRdOnlyGlobalVar(value,varName,scopeName):
     import salome
     dsm=salome.naming_service.Resolve("/DataServerManager")
-    d2s,isCreated=dsm.giveADataScopeCalled()
+    d2s,isCreated=dsm.giveADataScopeCalled(scopeName)
     return GetHandlerFromRef(d2s.createRdOnlyVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False)
     
 def CreateRdExtGlobalVar(value,varName,scopeName):
     import salome
     dsm=salome.naming_service.Resolve("/DataServerManager")
-    d2s,isCreated=dsm.giveADataScopeCalled()
+    d2s,isCreated=dsm.giveADataScopeCalled(scopeName)
     return GetHandlerFromRef(d2s.createRdExtVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False)
 
 def GetHandlerFromName(scopeName,varName):
diff --git a/src/SALOMESDS/TestSalomeSDS2.py b/src/SALOMESDS/TestSalomeSDS2.py
new file mode 100644 (file)
index 0000000..2ad849d
--- /dev/null
@@ -0,0 +1,77 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author : Anthony Geay
+
+import SalomeSDSClt
+import SALOME
+import salome
+import unittest
+import gc
+
+class SalomeSDS2Test(unittest.TestCase):
+  
+  def testList1(self):
+    a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0")
+    self.assertEqual(a.local_copy(),[])
+    a.append(5)
+    self.assertEqual(a.local_copy(),[5])
+    self.assertRaises(SALOME.SALOME_Exception,a.__delitem__,0)
+    a.append(["rt"])
+    self.assertEqual(a.local_copy(),[5,["rt"]])
+    a[1].append(8)
+    self.assertEqual(a.local_copy(),[5,["rt",8]])
+    a.extend(a)
+    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8]])
+    a.extend(a[3:])
+    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8]])
+    a[4].append(7)
+    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]])
+    a._var_ptr.getMyDataScopeServer().deleteVar("a")
+    pass
+  
+  def testDict1(self):
+    a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0")
+    a["ab"]=4
+    self.assertEqual(a.local_copy(),{"ab":4})
+    a["cd"]=[5]
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
+    a["cd"].append(77)
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
+    a.__setitem__("ef",["a","bb"])
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
+    self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb"])
+    self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb","ccc"])
+    a["ef"].append("ccc")
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
+    a["gh"]=a
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
+    a["gh"]["cd"].append(99) ; a["cd"].append(88)
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
+    a._var_ptr.getMyDataScopeServer().deleteVar("a")
+    pass
+
+  def setUp(self):
+    salome.salome_init()
+    pass
+  
+  pass
+
+unittest.main()
+