From: Anthony Geay Date: Fri, 9 Jan 2015 13:02:18 +0000 (+0100) Subject: First impl of RdExt policy. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=85597c90ca9d6c229eb5a89bfdc2c341bacef134;p=modules%2Fkernel.git First impl of RdExt policy. --- diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 27b930687..61099d289 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -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); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 8f9aabcbc..d2ab4e605 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -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 tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue)); + 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::PickelizedPyObjRdExtServer::_narrow(ret); +} + /*! * Called remotely -> to protect against throw */ diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 8a06052c7..2f95251af 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -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(); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 0db72ed6d..0193b5076 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -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 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); } } diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx index 3badf22c2..cf835c486 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -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(); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx index ff381642f..752669d7d 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx @@ -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