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();
};
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);
#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"
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
*/
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();
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);
}
}
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();
{
if(!_self)
throw Exception("PickelizedPyObjRdExtServer::invokePythonMethodOn : self is NULL !");
+ checkRdExtnessOf(method);
std::string argsCpp;
FromByteSeqToCpp(args,argsCpp);
PyObject *argsPy(getPyObjFromPickled(argsCpp));
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());
+}
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);
};
}
}
//! 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()
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));
-# -*- 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
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)
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)
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)
-# -*- 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
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,])
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)
#
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))