]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
First impl of RdExt policy.
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 9 Jan 2015 13:02:18 +0000 (14:02 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 9 Jan 2015 13:02:18 +0000 (14:02 +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
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
src/SALOMESDS/SalomeSDSClt.py
src/SALOMESDS/TestSalomeSDS1.py

index 27b9306879a16c01bf717975a2fd56327d22b3ef..61099d2898e6d3b22172d97afb61d6d943562b16 100644 (file)
@@ -61,6 +61,7 @@ module SALOME
     StringVec listVars();
     BasicDataServer retrieveVar(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);
     void shutdownIfNotHostedByDSM();
   };
@@ -73,7 +74,7 @@ module SALOME
     boolean isAliveAndKicking(in string scopeName) raises (SALOME::SALOME_Exception);
     DataScopeServer createDataScope(in string scopeName) raises (SALOME::SALOME_Exception);
     DataScopeServer retriveDataScope(in string scopeName) raises (SALOME::SALOME_Exception);
-    DataScopeServer giveADataScopeCalled(in string scopeName);
+    DataScopeServer giveADataScopeCalled(in string scopeName, out boolean isCreated);
     void removeDataScope(in string scopeName) raises (SALOME::SALOME_Exception);
     void cleanScopesInNS();
     void shutdownScopes() raises (SALOME::SALOME_Exception);
index 8f9aabcbc1223645b7465a4045e7e566d57fc050..d2ab4e60527b565ff98facb3bc574c669abdc4c3 100644 (file)
@@ -21,6 +21,7 @@
 #include "SALOMESDS_DataScopeServer.hxx"
 #include "SALOMESDS_DataServerManager.hxx"
 #include "SALOMESDS_PickelizedPyObjRdOnlyServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
 #include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
 #include "SALOME_NamingService.hxx"
 #include "SALOMESDS_Exception.hxx"
@@ -120,6 +121,17 @@ SALOME::PickelizedPyObjRdOnlyServer_ptr DataScopeServer::createRdOnlyVar(const c
   return SALOME::PickelizedPyObjRdOnlyServer::_narrow(ret);
 }
 
+SALOME::PickelizedPyObjRdExtServer_ptr DataScopeServer::createRdExtVar(const char *varName, const SALOME::ByteVec& constValue)
+{
+  std::string varNameCpp(varName);
+  checkNotAlreadyExistingVar(varNameCpp);
+  AutoRefCountPtr<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));
+  _vars.push_back(p);
+  return SALOME::PickelizedPyObjRdExtServer::_narrow(ret);
+}
+
 /*!
  * Called remotely -> to protect against throw
  */
index 8a06052c7fbc0bbf3e87d41da638712a7b27489f..2f95251af8aa39f423282848a80ccdf44b72c179 100644 (file)
@@ -46,6 +46,7 @@ namespace SALOMESDS
     SALOME::StringVec *listVars();
     SALOME::BasicDataServer_ptr retrieveVar(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);
     void shutdownIfNotHostedByDSM();
     ~DataScopeServer();
index 0db72ed6d86a2e958f84ae4c6248ef827bb19814..0193b507661a6136c48e8ebd1917ce461145355a 100644 (file)
@@ -136,23 +136,28 @@ SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scope
   return SALOME::DataScopeServer::_duplicate(ret);
 }
 
-SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName)
+SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
   std::string scopeNameCpp(scopeName);
   std::vector<std::string> scopes(listOfScopesCpp());
   if(std::find(scopes.begin(),scopes.end(),scopeNameCpp)==scopes.end())
     {
+      isCreated=true;
       return createDataScope(scopeName);
     }
   else
     {
       if(isAliveAndKicking(scopeName))
-        return retriveDataScope(scopeName);
+        {
+          isCreated=false;
+          return retriveDataScope(scopeName);
+        }
       else
         {
           SALOME_NamingService ns(_orb);
           std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(scopeNameCpp));
           ns.Destroy_Name(fullScopeName.c_str());
+          isCreated=true;
           return createDataScope(scopeName);
         }
     }
index 3badf22c23a8eb92558ab7651ed5230fa0707929..cf835c486a8aa95ace516cbbc311d5c2c9e23a38 100644 (file)
@@ -43,7 +43,7 @@ namespace SALOMESDS
     CORBA::Boolean isAliveAndKicking(const char *scopeName);
     SALOME::DataScopeServer_ptr createDataScope(const char *scopeName);
     SALOME::DataScopeServer_ptr retriveDataScope(const char *scopeName);
-    SALOME::DataScopeServer_ptr giveADataScopeCalled(const char *scopeName);
+    SALOME::DataScopeServer_ptr giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated);
     void removeDataScope(const char *scopeName);
     void cleanScopesInNS();
     void shutdownScopes();
index ff381642ffb81488e48ca4b06c7831733eafa7bc..752669d7d1c010dfc9e85bcf5937f6e6f555c941 100644 (file)
@@ -47,6 +47,7 @@ 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));
@@ -72,3 +73,37 @@ SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonM
   CORBA::Object_var obj(poa->id_to_reference(id));
   return SALOME::PickelizedPyObjRdExtServer::_narrow(obj);
 }
+
+void PickelizedPyObjRdExtServer::checkRdExtnessOf(const std::string& methodName)
+{
+  if(!_self)
+    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);
+  else if(PyDict_Check(_self)==1)
+    checkDictRdExtnessOf(methodName);
+  else
+    throw Exception("PickelizedPyObjRdExtServer::checkRdExtnessOf : Supported python types are [list,tuple,dict,str,int,float] !");
+}
+
+void PickelizedPyObjRdExtServer::checkListRdExtnessOf(const std::string& methodName)
+{
+  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 !";
+  throw Exception(oss.str());
+}
+
+void PickelizedPyObjRdExtServer::checkDictRdExtnessOf(const std::string& methodName)
+{
+  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 !";
+  throw Exception(oss.str());
+}
index 100d1c5508fc0a9c7d44801e6c7a374f9f3a378c..293b64aa681d1890373a9dcbbbd03635c5f4097d 100644 (file)
@@ -37,6 +37,10 @@ namespace SALOMESDS
     PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
     ~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);
   };
 }
 
index 53c0b1ad430df05c64fc719d8c7d4697f5a91d0a..3cfa90d845334e798789f9ac166aab038ca6f8fb 100644 (file)
@@ -33,8 +33,9 @@ PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std:
 }
 
 //! obj is consumed
-PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(obj)
+PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(0)
 {
+  setNewPyObj(obj);
 }
 
 PickelizedPyObjServer::~PickelizedPyObjServer()
@@ -120,6 +121,8 @@ void PickelizedPyObjServer::setNewPyObj(PyObject *obj)
     throw Exception("PickelizedPyObjServer::setNewPyObj : trying to assign a NULL pyobject in this !");
   if(obj==_self)
     return ;
+  if(PyList_Check(obj)==0 && PyDict_Check(obj)==0 && PyTuple_Check(obj)==0 && PyString_Check(obj)==0 && PyInt_Check(obj)==0 && PyBool_Check(obj)==0 && PyFloat_Check(obj)==0 && obj!=Py_None)
+    throw Exception("PickelizedPyObjServer::setNewPyObj : Supported python types are [list,tuple,dict,str,int,bool,float,None] !");
   if(_self)
     {
       PyObject *selfType(PyObject_Type(_self));
index e340c04238e8ee1b42c2afea2efdb7c6a691e2fb..1126024877403a95c13ab90bf5e87f1393c65e52 100644 (file)
@@ -1,4 +1,4 @@
-#  -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
@@ -109,29 +109,6 @@ class List(WrappedType):
         return len(self.local_copy())
     pass
 
-class Tuple(WrappedType):
-    def __init__(self,varPtr,isTemporaryVar=False):
-        WrappedType.__init__(self,varPtr,isTemporaryVar)
-        self._wrapped_type=tuple
-        pass
-
-    def __getitem__(self,*args):
-        ret=Caller(self._var_ptr,"__getitem__")
-        return ret(*args)
-    
-    # work on local copy
-
-    def count(self,*args):
-        return self.local_copy().count(*args)
-
-    def index(self,*args):
-        return self.local_copy().index(*args)
-    
-    def __len__(self):
-        return len(self.local_copy())
-
-    pass
-
 class Dict(WrappedType):
     def __init__(self,varPtr,isTemporaryVar=False):
         WrappedType.__init__(self,varPtr,isTemporaryVar)
@@ -201,6 +178,29 @@ class Dict(WrappedType):
 
     pass
 
+class Tuple(WrappedType):
+    def __init__(self,varPtr,isTemporaryVar=False):
+        WrappedType.__init__(self,varPtr,isTemporaryVar)
+        self._wrapped_type=tuple
+        pass
+
+    def __getitem__(self,*args):
+        ret=Caller(self._var_ptr,"__getitem__")
+        return ret(*args)
+    
+    # work on local copy
+
+    def count(self,*args):
+        return self.local_copy().count(*args)
+
+    def index(self,*args):
+        return self.local_copy().index(*args)
+    
+    def __len__(self):
+        return len(self.local_copy())
+
+    pass
+
 class Float(WrappedType):
     def __init__(self,varPtr,isTemporaryVar=False):
         WrappedType.__init__(self,varPtr,isTemporaryVar)
@@ -469,9 +469,22 @@ def GetHandlerFromRef(objCorba,isTempVar=False):
     if v is None:
         return None
     return PyHandlerTypeMap[v.__class__](objCorba,isTempVar)
+    
+    
+def CreateRdOnlyGlobalVar(value,varName,scopeName):
+    import salome
+    dsm=salome.naming_service.Resolve("/DataServerManager")
+    d2s,isCreated=dsm.giveADataScopeCalled()
+    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()
+    return GetHandlerFromRef(d2s.createRdExtVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False)
 
 def GetHandlerFromName(scopeName,varName):
     import salome
     dsm=salome.naming_service.Resolve("/DataServerManager")
-    d2s=dsm.giveADataScopeCalled(scopeName)
+    d2s=dsm.retriveDataScope(scopeName)
     return GetHandlerFromRef(d2s.retrieveVar(varName),False)
index af073282753660b35fa5399787abf6d314689e65..26e11ac8d8a1a50b0682254872ef24a814c46bd4 100644 (file)
@@ -1,4 +1,4 @@
-#  -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
@@ -53,7 +53,7 @@ a=dsm.retriveDataScope("S2").createRdWrVar("int","a")
 sname="S7"
 dsm=salome.naming_service.Resolve("/DataServerManager")
 st=cPickle.dumps([],cPickle.HIGHEST_PROTOCOL)
-a=dsm.giveADataScopeCalled(sname).createRdWrVar("list","a")
+a=dsm.giveADataScopeCalled(sname)[0].createRdWrVar("list","a")
 dsm.giveADataScopeCalled(sname)
 a.setSerializedContent(cPickle.dumps([0,],cPickle.HIGHEST_PROTOCOL))
 assert(cPickle.loads(a.fetchSerializedContent())==[0,])
@@ -67,7 +67,7 @@ for i in xrange(0,1000):
 dsm.removeDataScope(sname)
 #
 sname="S4"
-d2s=dsm.giveADataScopeCalled(sname)
+d2s,_=dsm.giveADataScopeCalled(sname)
 d2s.createRdWrVar("list","a")
 a=SalomeSDSClt.GetHandlerFromRef(dsm.retriveDataScope(sname).retrieveVar("a"))
 a.append(1)
@@ -79,7 +79,7 @@ assert(dsm.isAliveAndKicking(sname))
 #
 dsm=salome.naming_service.Resolve("/DataServerManager")
 sname="S11"
-d2s=dsm.giveADataScopeCalled(sname)
+d2s,_=dsm.giveADataScopeCalled(sname)
 d2s.createRdWrVar("dict","a")
 a=SalomeSDSClt.GetHandlerFromName(sname,"a")
 assert(isinstance(a,SalomeSDSClt.Dict))