From: Anthony Geay Date: Mon, 27 Oct 2014 12:39:19 +0000 (+0100) Subject: First version before plugging. X-Git-Tag: V7_6_0a1~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8a89a50b36a47cba1839646c0623562f30af9c28;p=modules%2Fkernel.git First version before plugging. LauncherServer hostes DataServerManager and default DataScopeServer. Little correction. First executable test. ScopeServer launching. Debug. Now scope server are correctly launched. ScopeServer are correctly created and destroyed. Small correction. On the road for remote python evaluation of global vars. Debuging done -> valgrind OK. string -> sequence to support the exchance via CORBA or pickled strings + addition of some useful methods. A good version. TODO : 1 - multi levels management 2 - clean exception handling Suppress AnyDataServer for the moment. String -> PyObject + support of invocation of methods recursively. A full use case is runnable. Remaining : raise management, float, string Little Bug. Imp Exceptions management + clean DataScopes destruction. on the road of read only and read ext. coming soon \! End of preparation to move to RdExt instead of RdWr. First impl of RdExt policy. Almost ready to be used. Valgrind OK on TestSalomeSDS2. OK. Only RdOnly and RdExt is now available. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d3c79b47..a0099ee44 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,7 +218,7 @@ ELSE() LIST(APPEND _${PROJECT_NAME}_exposed_targets DF SalomeLoggerServer with_loggerTraceCollector SalomeNS SalomeGenericObj Registry SalomeCatalog ResourcesManager SalomeResourcesManager - SalomeNotification SalomeContainer Launcher SalomeLauncher + SalomeNotification SalomeContainer SalomeSDS Launcher SalomeLauncher SalomeLifeCycleCORBA SalomeDSClient TOOLSDS SalomeKernelHelpers SalomeDSImpl SalomeDS SalomeCommunication SalomeDSCContainer) # Temporary solution for package src\DSC on windows diff --git a/SalomeKERNELConfig.cmake.in b/SalomeKERNELConfig.cmake.in index f3fc6bd48..02f080dfb 100644 --- a/SalomeKERNELConfig.cmake.in +++ b/SalomeKERNELConfig.cmake.in @@ -168,6 +168,7 @@ SET(KERNEL_SALOMEBasics SALOMEBasics) SET(KERNEL_SalomeCatalog SalomeCatalog) SET(KERNEL_SalomeCommunication SalomeCommunication) SET(KERNEL_SalomeContainer SalomeContainer) +SET(KERNEL_SalomeSDS SalomeSDS) SET(KERNEL_SalomeDatastream SalomeDatastream) SET(KERNEL_SalomeDSCContainer SalomeDSCContainer) SET(KERNEL_SalomeDSClient SalomeDSClient) diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt index 894de4afa..b69a9bd1e 100755 --- a/idl/CMakeLists.txt +++ b/idl/CMakeLists.txt @@ -36,6 +36,7 @@ SET(SalomeIDLKernel_IDLSOURCES SALOMEDS_Attributes.idl SALOME_Component.idl SALOME_ContainerManager.idl + SALOME_SDS.idl SALOME_Registry.idl Logger.idl SALOME_GenericObj.idl diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl new file mode 100644 index 000000000..762f46e01 --- /dev/null +++ b/idl/SALOME_SDS.idl @@ -0,0 +1,86 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOME_GenericObj.idl" +#include "SALOME_Exception.idl" + +module SALOME +{ + typedef sequence StringVec; + typedef sequence ByteVec; + + interface DataScopeServer; + + interface BasicDataServer : GenericObj + { + DataScopeServer getMyDataScopeServer(); + string getVarName(); + string getScopeName(); + }; + + interface PickelizedPyObjServer : BasicDataServer + { + ByteVec fetchSerializedContent() raises (SALOME::SALOME_Exception); + }; + + interface PickelizedPyObjRdOnlyServer : PickelizedPyObjServer + { + }; + + interface PickelizedPyObjRdExtServer : PickelizedPyObjServer + { + PickelizedPyObjRdExtServer invokePythonMethodOn(in string method, in ByteVec args) raises (SALOME::SALOME_Exception); + }; + + interface PickelizedPyObjRdWrServer : PickelizedPyObjServer + { + void setSerializedContent(in ByteVec newValue) raises (SALOME::SALOME_Exception); + PickelizedPyObjRdWrServer invokePythonMethodOn(in string method, in ByteVec args) raises (SALOME::SALOME_Exception); + }; + + interface DataServerManager; + + interface DataScopeServer + { + void ping(); + 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); + void shutdownIfNotHostedByDSM(); + }; + + interface DataServerManager + { + StringVec listScopes(); + StringVec listAliveAndKickingScopes() raises (SALOME::SALOME_Exception); + DataScopeServer getDefaultScope() raises (SALOME::SALOME_Exception); + 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, out boolean isCreated); + void removeDataScope(in string scopeName) raises (SALOME::SALOME_Exception); + void cleanScopesInNS(); + void shutdownScopes() raises (SALOME::SALOME_Exception); + }; +}; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26ed1a052..9e8ee2889 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,7 @@ SET(SUBDIR_CORBA Notification NOTIFICATION_SWIG Container + SALOMESDS TestContainer Launcher LifeCycleCORBA diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index ee9a30adc..ec1db62dc 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -21,6 +21,8 @@ // #include "SALOME_ContainerManager.hxx" +#include "SALOME_ResourcesManager.hxx" +#include "SALOME_LoadRateManager.hxx" #include "SALOME_NamingService.hxx" #include "SALOME_ResourcesManager_Client.hxx" #include "SALOME_ModuleCatalog.hh" @@ -49,7 +51,7 @@ #include "PaCOPP.hxx" #endif -#define TIME_OUT_TO_LAUNCH_CONT 60 +const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60; const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager"; @@ -587,11 +589,7 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par logFilename += tmp.str(); logFilename += ".log" ; command += " > " + logFilename + " 2>&1"; -#ifdef WIN32 - command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\""; -#else - command += " &"; -#endif + MakeTheCommandToBeLaunchedASync(command); // launch container with a system call status=SystemThreadSafe(command.c_str()); @@ -612,30 +610,14 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par else { // Step 4: Wait for the container - int count = TIME_OUT_TO_LAUNCH_CONT; - if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0) - { - std::string new_count_str = GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER"); - int new_count; - std::istringstream ss(new_count_str); - if (!(ss >> new_count)) - { - INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int"); - } - else - count = new_count; - } + int count(GetTimeOutToLoaunchServer()); INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS); while (CORBA::is_nil(ret) && count) { -#ifndef WIN32 - sleep( 1 ) ; -#else - Sleep(1000); -#endif + SleepInSecond(1); count--; MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected); - CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str()); + CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str())); ret=Engines::Container::_narrow(obj); } if (CORBA::is_nil(ret)) @@ -980,9 +962,9 @@ void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName) void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const { - CORBA::String_var iorstr = _NS->getIORaddr(); - command += "ORBInitRef NameService="; - command += iorstr; + std::ostringstream oss; + AddOmninamesParams(oss); + command+=oss.str(); } //============================================================================= @@ -991,11 +973,9 @@ void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const */ //============================================================================= -void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const +void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const { - CORBA::String_var iorstr = _NS->getIORaddr(); - fileStream << "ORBInitRef NameService="; - fileStream << iorstr; + AddOmninamesParams(fileStream,_NS); } //============================================================================= @@ -1004,11 +984,48 @@ void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) cons */ //============================================================================= -void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const +void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns) +{ + CORBA::String_var iorstr(ns->getIORaddr()); + fileStream << "ORBInitRef NameService="; + fileStream << iorstr; +} + +void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command) { - CORBA::String_var iorstr = _NS->getIORaddr(); - oss << "ORBInitRef NameService="; - oss << iorstr; +#ifdef WIN32 + command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\""; +#else + command += " &"; +#endif +} + +int SALOME_ContainerManager::GetTimeOutToLoaunchServer() +{ + int count(TIME_OUT_TO_LAUNCH_CONT); + if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0) + { + std::string new_count_str(GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER")); + int new_count; + std::istringstream ss(new_count_str); + if (!(ss >> new_count)) + { + INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int"); + } + else + count = new_count; + } + return count; +} + +void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond) +{ +#ifndef WIN32 + sleep( ellapseTimeInSecond ) ; +#else + int timeInMS(1000*ellapseTimeInSecond); + Sleep(timeInMS); +#endif } //============================================================================= @@ -1853,7 +1870,7 @@ SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, return container_proxy; } - int count = TIME_OUT_TO_LAUNCH_CONT; + int count(GetTimeOutToLoaunchServer()); CORBA::Object_var obj = CORBA::Object::_nil(); std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(), hostname.c_str()); @@ -1937,9 +1954,9 @@ SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, std::string container_node_name = name + proc_number; std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str()); INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine); - int count = TIME_OUT_TO_LAUNCH_CONT; + int count(GetTimeOutToLoaunchServer()); while (CORBA::is_nil(obj) && count) { - sleep(1) ; + SleepInSecond(1); count-- ; obj = _NS->Resolve(containerNameInNS.c_str()); } diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index fc55e7579..fea0be910 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -81,9 +81,7 @@ protected: void AddOmninamesParams(std::string& command) const; - void AddOmninamesParams(std::ostringstream& oss) const; - - void AddOmninamesParams(std::ofstream& fileStream) const; + void AddOmninamesParams(std::ostream& fileStream) const; static std::string BuildTemporaryFileName(); @@ -161,7 +159,12 @@ protected: public: static char *GetenvThreadSafe(const char *name); static int SystemThreadSafe(const char *command); -private: + static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns); + static void MakeTheCommandToBeLaunchedASync(std::string& command); + static int GetTimeOutToLoaunchServer(); + static void SleepInSecond(int ellapseTimeInSecond); + private: + static const int TIME_OUT_TO_LAUNCH_CONT; static Utils_Mutex _getenvMutex; static Utils_Mutex _systemMutex; }; diff --git a/src/Launcher/CMakeLists.txt b/src/Launcher/CMakeLists.txt index 4a14d0496..9757df6b9 100755 --- a/src/Launcher/CMakeLists.txt +++ b/src/Launcher/CMakeLists.txt @@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Notification ${CMAKE_CURRENT_SOURCE_DIR}/../Container ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager + ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMESDS ${PROJECT_BINARY_DIR}/idl ) @@ -95,6 +96,7 @@ IF(NOT SALOME_LAUNCHER_ONLY) SET(SALOME_LauncherServer_LIBS Launcher SalomeLauncher + SalomeSDS SALOMEBasics SALOMELocalTrace ${LIBBATCH_LIBRARIES} diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 707b29470..4793267e9 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -24,6 +24,7 @@ #include "BatchTest.hxx" #include "OpUtil.hxx" #include "SALOME_ContainerManager.hxx" +#include "SALOME_NamingService.hxx" #include "SALOME_ResourcesManager.hxx" #include "Utils_CorbaException.hxx" @@ -32,6 +33,8 @@ #include "Launcher_Job_YACSFile.hxx" #include "Launcher_Job_PythonSALOME.hxx" +#include "utilities.h" + #ifdef WIN32 # include #else diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx index 4bb4ecfd9..d3b8ec602 100644 --- a/src/Launcher/SALOME_LauncherServer.cxx +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -21,6 +21,7 @@ // #include "SALOME_Launcher.hxx" +#include "SALOMESDS_DataServerManager.hxx" #include "utilities.h" #include #include @@ -85,18 +86,26 @@ int main(int argc, char* argv[]) if(!CORBA::is_nil(obj)) root_poa = PortableServer::POA::_narrow(obj); if(!CORBA::is_nil(root_poa)) - pman = root_poa->the_POAManager(); + { + pman = root_poa->the_POAManager(); + pman->activate(); + } } catch(CORBA::COMM_FAILURE&){ MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ); } - try{ - SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa); - pman->activate(); - lServ->_remove_ref(); - orb->run(); - orb->destroy(); - }catch(CORBA::SystemException&){ + try + { + SALOME_Launcher *lServ(new SALOME_Launcher(orb,root_poa)); + lServ->_remove_ref(); + // + SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(argc,argv,orb,root_poa)); + dsm->_remove_ref(); + // + orb->run(); + orb->destroy(); + } + catch(CORBA::SystemException&){ MESSAGE("Caught CORBA::SystemException."); }catch(PortableServer::POA::WrongPolicy&){ MESSAGE("Caught CORBA::WrongPolicyException."); diff --git a/src/LifeCycleCORBA/CMakeLists.txt b/src/LifeCycleCORBA/CMakeLists.txt index abc89bbcd..2ae2bf280 100755 --- a/src/LifeCycleCORBA/CMakeLists.txt +++ b/src/LifeCycleCORBA/CMakeLists.txt @@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Batch ${CMAKE_CURRENT_SOURCE_DIR}/../Notification ${CMAKE_CURRENT_SOURCE_DIR}/../Registry + ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMESDS ${PROJECT_BINARY_DIR}/idl ) @@ -40,6 +41,7 @@ SET(COMMON_LIBS SalomeContainer SalomeResourcesManager SalomeNS + SalomeSDS OpUtil SALOMELocalTrace SALOMEBasics diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 5473178da..19e66e5e1 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -42,11 +42,15 @@ #include #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_ResourcesManager.hxx" +#include "SALOMESDS_DataServerManager.hxx" + #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) #include CORBA_CLIENT_HEADER(SALOME_Session) #include CORBA_CLIENT_HEADER(DSC_Engines) #include CORBA_CLIENT_HEADER(SALOME_Registry) #include CORBA_CLIENT_HEADER(SALOMEDS) +#include CORBA_CLIENT_HEADER(SALOME_SDS) #include CORBA_CLIENT_HEADER(Logger) #include CORBA_CLIENT_HEADER(SALOME_Launcher) @@ -503,8 +507,20 @@ void SALOME_LifeCycleCORBA::shutdownServers() #ifndef WIN32 nanosleep(&ts_req,0); #endif + // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after) + try + { + CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS)); + SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM)); + if ( !CORBA::is_nil(dsm) ) + dsm->shutdownScopes(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } - // 4) SalomeLauncher + // 5) SalomeLauncher try { CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher"); @@ -522,7 +538,7 @@ void SALOME_LifeCycleCORBA::shutdownServers() nanosleep(&ts_req,0); #endif - // 5) Registry + // 6) Registry try { CORBA::Object_var objR = _NS->Resolve("/Registry"); @@ -535,20 +551,6 @@ void SALOME_LifeCycleCORBA::shutdownServers() // ignore and continue } - /* - // 6) Session - if ( !CORBA::is_nil( session ) ) { - try - { - session->Shutdown(); - } - catch(const CORBA::Exception& e) - { - // ignore and continue - } - } - */ - // 7) Logger int argc = 0; char *xargv = (char*)""; diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx index f95cccdb9..a9805ca08 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx @@ -26,6 +26,7 @@ #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "Basics_Utils.hxx" +#include "utilities.h" #include #include diff --git a/src/LifeCycleCORBA/TestContainerManager.cxx b/src/LifeCycleCORBA/TestContainerManager.cxx index 40e2afabe..1dc981fe0 100644 --- a/src/LifeCycleCORBA/TestContainerManager.cxx +++ b/src/LifeCycleCORBA/TestContainerManager.cxx @@ -33,6 +33,7 @@ #include "SALOME_ResourcesManager.hxx" #include "SALOME_ContainerManager.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_ResourcesManager.hxx" #include "NamingService_WaitForServerReadiness.hxx" #include "OpUtil.hxx" #include "Utils_ORB_INIT.hxx" diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index d6a53c28e..07605c6f7 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -35,7 +35,6 @@ #include #include -#include "utilities.h" #include "Utils_Mutex.hxx" #include "ServiceUnreachable.hxx" diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx index 8f8cf52fc..456b9d617 100644 --- a/src/NamingService/Test/NamingServiceTest.cxx +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -25,6 +25,7 @@ #include "Utils_SINGLETON.hxx" #include "Basics_Utils.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "utilities.h" #include #include diff --git a/src/SALOMEDS/SALOMEDS_StudyManager.cxx b/src/SALOMEDS/SALOMEDS_StudyManager.cxx index 3ffa83174..ce80b2644 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager.cxx @@ -35,7 +35,8 @@ #include "SALOMEDSImpl_Study.hxx" #include "Utils_ORB_INIT.hxx" -#include "Utils_SINGLETON.hxx" +#include "Utils_SINGLETON.hxx" +#include "utilities.h" #include "Basics_Utils.hxx" diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt new file mode 100644 index 000000000..b86b57676 --- /dev/null +++ b/src/SALOMESDS/CMakeLists.txt @@ -0,0 +1,59 @@ +# Copyright (C) 2012-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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 (EDF R&D) + +INCLUDE_DIRECTORIES( + ${OMNIORB_INCLUDE_DIR} + ${PTHREAD_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} + ${PROJECT_BINARY_DIR}/idl + ${PROJECT_BINARY_DIR}/salome_adm + ${CMAKE_CURRENT_SOURCE_DIR}/../Utils + ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService + ${CMAKE_CURRENT_SOURCE_DIR}/../Container + ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager +) + +ADD_DEFINITIONS(${OMNIORB_DEFINITIONS} ${PYTHON_DEFINITIONS}) + +SET(COMMON_LIBS SalomeNS SalomeContainer SalomeIDLKernel ${OMNIORB_LIBRARIES} ${PYTHON_LIBRARIES}) + +SET(SalomeSDS_SOURCES + SALOMESDS_Exception.cxx + SALOMESDS_RefCountServ.cxx + SALOMESDS_BasicDataServer.cxx + SALOMESDS_DataScopeServer.cxx + SALOMESDS_DataServerManager.cxx + SALOMESDS_PickelizedPyObjServer.cxx + SALOMESDS_PickelizedPyObjRdOnlyServer.cxx + SALOMESDS_PickelizedPyObjRdExtServer.cxx + SALOMESDS_PickelizedPyObjRdWrServer.cxx + ) + +ADD_LIBRARY(SalomeSDS ${SalomeSDS_SOURCES}) +TARGET_LINK_LIBRARIES(SalomeSDS ${COMMON_LIBS} ${PTHREAD_LIBRARIES}) +INSTALL(TARGETS SalomeSDS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + +ADD_EXECUTABLE(SALOME_DataScopeServer SALOME_DataScopeServer.cxx) +TARGET_LINK_LIBRARIES(SALOME_DataScopeServer SalomeSDS) +INSTALL(TARGETS SALOME_DataScopeServer DESTINATION ${SALOME_INSTALL_BINS}) +INSTALL(FILES SalomeSDSClt.py DESTINATION ${SALOME_INSTALL_BINS}) + +FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") +INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/SALOMESDS/SALOMEGlobalVarHelper.py b/src/SALOMESDS/SALOMEGlobalVarHelper.py new file mode 100644 index 000000000..f4b6bbf5a --- /dev/null +++ b/src/SALOMESDS/SALOMEGlobalVarHelper.py @@ -0,0 +1,212 @@ +# -*- coding: iso-8859-1 -*- +# 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 + +# dict,list,tuple,int,float,str +import SALOME +import cPickle + +class List(object): + def __init__(self,varPtr,isTemporaryVar=False): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + if not isTemporaryVar: + self._var_ptr.Register() + self._is_temp=isTemporaryVar + pass + + def __del__(self): + self._var_ptr.UnRegister() + pass + + def assign(self,elt): + st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) + self._var_ptr.setSerializedContent(st) + pass + + def __getitem__(self,*args): + ret=Caller(self._var_ptr,"__getitem__") + return ret(*args) + + def __setitem__(self,*args): + ret=Caller(self._var_ptr,"__setitem__") + return ret(*args) + + def append(self,*args): + ret=Caller(self._var_ptr,"append") + return ret(*args) + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def local_copy(self): + return cPickle.loads(self._var_ptr.fetchSerializedContent()) + + def __reduce__(self): + return (list,(self.local_copy(),)) + + pass + +class Tuple(object): + def __init__(self,varPtr,isTemporaryVar=False): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + if not isTemporaryVar: + self._var_ptr.Register() + self._is_temp=isTemporaryVar + pass + + def __del__(self): + self._var_ptr.UnRegister() + pass + + def assign(self,elt): + st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) + self._var_ptr.setSerializedContent(st) + pass + + def __getitem__(self,*args): + ret=Caller(self._var_ptr,"__getitem__") + return ret(*args) + + def __setitem__(self,*args): + ret=Caller(self._var_ptr,"__setitem__") + return ret(*args) + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def local_copy(self): + return cPickle.loads(self._var_ptr.fetchSerializedContent()) + + def __reduce__(self): + return (tuple,(self.local_copy(),)) + + pass + + +class Int(object): + def __init__(self,varPtr,isTemporaryVar=False): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + if not isTemporaryVar: + self._var_ptr.Register() + self._is_temp=isTemporaryVar + pass + + def __del__(self): + self._var_ptr.UnRegister() + pass + + def __iadd__(self,*args): + ret=Caller(self._var_ptr,"__add__") + return ret(*args) + + def __isub__(self,*args): + ret=Caller(self._var_ptr,"__sub__") + return ret(*args) + + def assign(self,elt): + st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) + self._var_ptr.setSerializedContent(st) + pass + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def local_copy(self): + return cPickle.loads(self._var_ptr.fetchSerializedContent()) + + def __reduce__(self): + return (int,(self.local_copy(),)) + + pass + +class Dict(object): + def __init__(self,varPtr,isTemporaryVar=False): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + if not isTemporaryVar: + self._var_ptr.Register() + self._is_temp=isTemporaryVar + pass + + def __del__(self): + self._var_ptr.UnRegister() + pass + + def assign(self,elt): + st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL) + self._var_ptr.setSerializedContent(st) + pass + + def __getitem__(self,*args): + ret=Caller(self._var_ptr,"__getitem__") + return ret(*args) + + def __setitem__(self,*args): + ret=Caller(self._var_ptr,"__setitem__") + return ret(*args) + + def __len__(self): + return len(self.local_copy()) + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def local_copy(self): + return cPickle.loads(self._var_ptr.fetchSerializedContent()) + + def __reduce__(self): + return (dict,(self.local_copy(),)) + + pass + +class Caller: + def __init__(self,varPtr,meth): + assert(isinstance(varPtr,SALOME._objref_StringDataServer)) + self._var_ptr=varPtr + self._meth=meth + pass + + def __call__(self,*args): + ret=self._var_ptr.invokePythonMethodOn(self._meth,cPickle.dumps(args,cPickle.HIGHEST_PROTOCOL)) + return GetHandlerFromRef(ret,True) + pass + +PyHandlerTypeMap={int:Int,list:List,tuple:Tuple,dict:Dict} + +def GetHandlerFromRef(objCorba,isTempVar=False): + v=cPickle.loads(objCorba.fetchSerializedContent()) + if v is None: + return None + return PyHandlerTypeMap[v.__class__](objCorba,isTempVar) diff --git a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx new file mode 100644 index 000000000..021b115dd --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx @@ -0,0 +1,78 @@ +// 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 (EDF R&D) + +#ifndef __SALOMESDS_AUTOREFCOUNTPTR_HXX__ +#define __SALOMESDS_AUTOREFCOUNTPTR_HXX__ + +#include "SALOMESDS_Exception.hxx" + +namespace SALOMESDS +{ + template + class AutoRefCountPtr + { + public: + AutoRefCountPtr(const AutoRefCountPtr& other):_ptr(0) { referPtr(other._ptr); } + AutoRefCountPtr(T *ptr=0):_ptr(ptr) { } + ~AutoRefCountPtr() { destroyPtr(); } + bool operator==(const AutoRefCountPtr& other) const { return _ptr==other._ptr; } + bool operator==(const T *other) const { return _ptr==other; } + AutoRefCountPtr &operator=(const AutoRefCountPtr& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } + AutoRefCountPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } + T *operator->() { return _ptr ; } + const T *operator->() const { return _ptr; } + T& operator*() { return *_ptr; } + const T& operator*() const { return *_ptr; } + operator T *() { return _ptr; } + operator const T *() const { return _ptr; } + T *retn() { if(_ptr) _ptr->incrRef(); return _ptr; } + private: + void referPtr(T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } + void destroyPtr() { if(_ptr) _ptr->decrRef(); } + private: + T *_ptr; + }; + + template + typename SALOMESDS::AutoRefCountPtr DynamicCast(typename SALOMESDS::AutoRefCountPtr& autoSubPtr) throw() + { + T *subPtr(autoSubPtr); + U *ptr(dynamic_cast(subPtr)); + typename SALOMESDS::AutoRefCountPtr ret(ptr); + if(ptr) + ptr->incrRef(); + return ret; + } + + template + typename SALOMESDS::AutoRefCountPtr DynamicCastSafe(typename SALOMESDS::AutoRefCountPtr& autoSubPtr) + { + T *subPtr(autoSubPtr); + U *ptr(dynamic_cast(subPtr)); + if(subPtr && !ptr) + throw Exception("DynamicCastSafe : U is not a subtype of T !"); + typename SALOMESDS::AutoRefCountPtr ret(ptr); + if(ptr) + ptr->incrRef(); + return ret; + } +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx new file mode 100644 index 000000000..00a639b34 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -0,0 +1,70 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_BasicDataServer.hxx" +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_Exception.hxx" + +#include + +using namespace SALOMESDS; + +BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& varName):_father(father),_var_name(varName) +{ +} + +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 + */ +char *BasicDataServer::getVarName() +{ + return CORBA::string_dup(_var_name.c_str()); +} + +char *BasicDataServer::getScopeName() +{ + return _father->getScopeName(); +} + +void BasicDataServer::Register() +{ + incrRef(); +} + +void BasicDataServer::UnRegister() +{ + decrRef(); +} + +void BasicDataServer::Destroy() +{ + enforcedRelease(); +} + +PortableServer::POA_var BasicDataServer::getPOA() +{ + return _father->getPOA(); +} diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx new file mode 100644 index 000000000..3115064c0 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -0,0 +1,57 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_BASICDATASERVER_HXX__ +#define __SALOMESDS_BASICDATASERVER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include "SALOMESDS_RefCountServ.hxx" + +#include + +namespace SALOMESDS +{ + class DataScopeServer; + + class BasicDataServer : public RefCountServ, public virtual POA_SALOME::BasicDataServer + { + public: + BasicDataServer(DataScopeServer *father, const std::string& varName); + SALOME::DataScopeServer_ptr getMyDataScopeServer(); + char *getVarName(); + char *getScopeName(); + public: + void Register(); + void UnRegister(); + void Destroy(); + public: + std::string getVarNameCpp() const { return _var_name; } + protected: + PortableServer::POA_var getPOA(); + protected: + DataScopeServer *_father; + private: + std::string _var_name; + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx new file mode 100644 index 000000000..3ff2e0479 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -0,0 +1,270 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#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" + +#include +#include +#include + +// agy : awful, to be factorized with ContainerManager. +#ifndef WIN32 +#include +#else +#include +#define getpid _getpid +#endif + +using namespace SALOMESDS; + +std::size_t DataScopeServer::COUNTER=0; + +DataScopeServer::DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName):_globals(0),_locals(0),_pickler(0),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName) +{ +} + +DataScopeServer::DataScopeServer(const DataScopeServer& other):_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars) +{ +} + +DataScopeServer::~DataScopeServer() +{ + // _globals is borrowed ref -> do nothing + Py_XDECREF(_locals); + Py_XDECREF(_pickler); +} + +/*! + * Called remotely -> to protect against throw + */ +void DataScopeServer::ping() +{ +} + +/*! + * Called remotely -> to protect against throw + */ +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, BasicDataServer * > >::iterator it(_vars.begin()); + for(std::size_t i=0;igetVarNameCpp()); + (*ret)[i]=CORBA::string_dup(name.c_str()); + } + return ret; +} + +SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName) +{ + std::string varNameCpp(varName); + std::vector allNames(getAllVarNames()); + std::vector::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(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()); + for(std::size_t i=0;i allNames(getAllVarNames()); + std::vector::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(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); + PickelizedPyObjRdOnlyServer *tmp(new PickelizedPyObjRdOnlyServer(this,varNameCpp,constValue)); + CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); + _vars.push_back(p); + return SALOME::PickelizedPyObjRdOnlyServer::_narrow(ret); +} + +SALOME::PickelizedPyObjRdExtServer_ptr DataScopeServer::createRdExtVar(const char *varName, const SALOME::ByteVec& constValue) +{ + std::string varNameCpp(varName); + checkNotAlreadyExistingVar(varNameCpp); + PickelizedPyObjRdExtServer *tmp(new PickelizedPyObjRdExtServer(this,varNameCpp,constValue)); + CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); + _vars.push_back(p); + return SALOME::PickelizedPyObjRdExtServer::_narrow(ret); +} + +/*! + * Called remotely -> to protect against throw + */ +SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char *typeName, const char *varName) +{ + std::string varNameCpp(varName),typeNameCpp(typeName); + checkNotAlreadyExistingVar(varNameCpp); + PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,typeNameCpp,varNameCpp)); + CORBA::Object_var ret(activateWithDedicatedPOA(tmp)); + std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); + _vars.push_back(p); + return SALOME::PickelizedPyObjRdWrServer::_narrow(ret); +} + +void DataScopeServer::shutdownIfNotHostedByDSM() +{ + SALOME_NamingService ns(_orb); + CORBA::Object_var obj(ns.Resolve(DataServerManager::NAME_IN_NS)); + SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(obj)); + if(CORBA::is_nil(dsm)) + return ; + // destroy ref in the naming service + std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name)); + ns.Destroy_Name(fullScopeName.c_str()); + // establish if dsm and this shared the same POA. If yes dsm and this are collocated ! + PortableServer::ServantBase *ret(0); + try + { + ret=_poa->reference_to_servant(dsm); + } + catch(...) { ret=0; } + // + if(!ret) + _orb->shutdown(0); + else + { + PortableServer::ObjectId_var oid(_poa->servant_to_id(this)); + _poa->deactivate_object(oid); + ret->_remove_ref(); + } +} + +void DataScopeServer::initializePython(int argc, char *argv[]) +{ + Py_Initialize(); + PySys_SetArgv(argc,argv); + PyObject *mainmod(PyImport_AddModule("__main__")); + _globals=PyModule_GetDict(mainmod); + if(PyDict_GetItemString(_globals, "__builtins__") == NULL) + { + PyObject *bimod(PyImport_ImportModule("__builtin__")); + if (bimod == NULL || PyDict_SetItemString(_globals, "__builtins__", bimod) != 0) + Py_FatalError("can't add __builtins__ to __main__"); + Py_XDECREF(bimod); + } + _locals=PyDict_New(); + PyObject *tmp(PyList_New(0)); + _pickler=PyImport_ImportModuleLevel(const_cast("cPickle"),_globals,_locals,tmp,-1); +} + +void DataScopeServer::registerToSalomePiDict() const +{ + PyObject *mod(PyImport_ImportModule("addToKillList")); + if(!mod) + return; + PyObject *meth(PyObject_GetAttrString(mod,"addToKillList")); + if(!meth) + { Py_XDECREF(mod); return ; } + PyObject *args(PyTuple_New(2)); + PyTuple_SetItem(args,0,PyInt_FromLong(getpid())); + PyTuple_SetItem(args,1,PyString_FromString("SALOME_DataScopeServer")); + PyObject *res(PyObject_CallObject(meth,args)); + Py_XDECREF(args); + Py_XDECREF(res); + Py_XDECREF(mod); +} + +/*! + * \a ptr has been activated by the POA \a poa. + */ +void DataScopeServer::setPOAAndRegister(PortableServer::POA_var poa, SALOME::DataScopeServer_ptr ptr) +{ + _poa=poa; + std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name)); + SALOME_NamingService ns(_orb); + ns.Register(ptr,fullScopeName.c_str()); +} + +std::string DataScopeServer::BuildTmpVarNameFrom(const std::string& varName) +{ + std::ostringstream oss; + oss << varName << "@" << COUNTER++; + return oss.str(); +} + +std::vector< std::string > DataScopeServer::getAllVarNames() const +{ + std::size_t sz(_vars.size()); + std::vector ret(sz); + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator it(_vars.begin()); + for(std::size_t i=0;igetVarNameCpp(); + return ret; +} + +CORBA::Object_var DataScopeServer::activateWithDedicatedPOA(BasicDataServer *ds) +{ + PortableServer::ObjectId_var id(_poa->activate_object(ds)); + CORBA::Object_var ret(_poa->id_to_reference(id)); + return ret; +} + +void DataScopeServer::checkNotAlreadyExistingVar(const std::string& varName) +{ + std::vector allNames(getAllVarNames()); + std::vector::iterator it(std::find(allNames.begin(),allNames.end(),varName)); + if(it!=allNames.end()) + { + std::ostringstream oss; oss << "DataScopeServer::checkNotAlreadyExistingVar : name \"" << varName << "\" already exists !"; + throw Exception(oss.str()); + } +} diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx new file mode 100644 index 000000000..1147ba665 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -0,0 +1,79 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_DATASCOPEERVER_HXX__ +#define __SALOMESDS_DATASCOPEERVER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include "SALOMESDS_RefCountServ.hxx" +#include "SALOMESDS_AutoRefCountPtr.hxx" +#include "SALOMESDS_BasicDataServer.hxx" + +#include + +#include +#include +#include + +namespace SALOMESDS +{ + class DataScopeServer : public virtual POA_SALOME::DataScopeServer + { + public: + DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName); + DataScopeServer(const DataScopeServer& other); + void ping(); + 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); + void shutdownIfNotHostedByDSM(); + ~DataScopeServer(); + public: + void initializePython(int argc, char *argv[]); + void registerToSalomePiDict() const; + void setPOAAndRegister(PortableServer::POA_var poa, SALOME::DataScopeServer_ptr ptr); + PyObject *getGlobals() const { return _globals; } + PyObject *getLocals() const { return _locals; } + PyObject *getPickler() const { return _pickler; } + PortableServer::POA_var getPOA() { return _poa; } + static std::string BuildTmpVarNameFrom(const std::string& varName); + private: + std::vector< std::string> getAllVarNames() const; + CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds); + void checkNotAlreadyExistingVar(const std::string& varName); + private: + PyObject *_globals; + PyObject *_locals; + PyObject *_pickler; + PortableServer::POA_var _poa; + CORBA::ORB_var _orb; + std::string _name; + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars; + static std::size_t COUNTER; + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx new file mode 100644 index 000000000..0193b5076 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -0,0 +1,227 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_Exception.hxx" + +#include "SALOME_ContainerManager.hxx" +#include "SALOME_NamingService.hxx" + +#include +#include + +using namespace SALOMESDS; + +const char DataServerManager::NAME_IN_NS[]="/DataServerManager"; + +const char DataServerManager::DFT_SCOPE_NAME_IN_NS[]="Default"; + +DataServerManager::DataServerManager(int argc, char *argv[], CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_orb(CORBA::ORB::_duplicate(orb)) +{ + DataScopeServer *dftScope(new DataScopeServer(orb,DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM + PortableServer::POAManager_var pman(poa->the_POAManager()); + CORBA::PolicyList policies; + policies.length(1); + PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + _poa=poa->create_POA("SingleThPOA4SDS",pman,policies); + threadPol->destroy(); + // + dftScope->initializePython(argc,argv);// agy : Very important ! invoke this method BEFORE activation ! + // activate this to be ready to be usable from NS. + PortableServer::ObjectId_var id(_poa->activate_object(this)); + CORBA::Object_var obj(_poa->id_to_reference(id)); + SALOME::DataServerManager_var obj2(SALOME::DataServerManager::_narrow(obj)); + // publish Data server manager in NS + SALOME_NamingService ns(orb); + ns.Register(obj2,NAME_IN_NS); + // the default DataScopeServer object is the only one hosted by the current process + id=_poa->activate_object(dftScope); + obj=_poa->id_to_reference(id); + SALOME::DataScopeServer_var dftScopePtr(SALOME::DataScopeServer::_narrow(obj)); + dftScope->setPOAAndRegister(_poa,dftScopePtr);// agy : Very important ! invoke this method BEFORE activation ! Because this method initializes Python ! +} + +SALOME::StringVec *DataServerManager::listScopes() +{ + std::vector scopes(listOfScopesCpp()); + SALOME::StringVec *ret(new SALOME::StringVec); + std::size_t sz(scopes.size()); + ret->length(sz); + for(std::size_t i=0;i scopes(listOfScopesCpp()); + std::size_t sz(scopes.size()); + std::vector retCpp; retCpp.reserve(sz); + for(std::size_t i=0;ilength(sz); + for(std::size_t i=0;iping(); + } + catch(...) + { ret=false; } + return ret; +} + +SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName) +{ + std::string scopeNameCpp(scopeName); + std::vector scopes(listOfScopesCpp()); + if(std::find(scopes.begin(),scopes.end(),scopeNameCpp)!=scopes.end()) + { + std::ostringstream oss; oss << "DataServerManager::createDataScope : scope name \"" << scopeName << "\" already exists !"; + throw Exception(oss.str()); + } + // + SALOME_NamingService ns(_orb); + std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName)); + std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " "; + SALOME_ContainerManager::AddOmninamesParams(oss,&ns); + std::string command(oss.str()); + SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command); + int status(SALOME_ContainerManager::SystemThreadSafe(command.c_str())); + int count(SALOME_ContainerManager::GetTimeOutToLoaunchServer()); + SALOME::DataScopeServer_var ret(SALOME::DataScopeServer::_nil()); + while (CORBA::is_nil(ret) && count) + { + SALOME_ContainerManager::SleepInSecond(1); + count--; + CORBA::Object_var obj(ns.Resolve(fullScopeName.c_str())); + ret=SALOME::DataScopeServer::_narrow(obj); + } + return SALOME::DataScopeServer::_duplicate(ret); +} + +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)) + { + 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); + } + } +} + +SALOME::DataScopeServer_ptr DataServerManager::retriveDataScope(const char *scopeName) +{ + SALOME::DataScopeServer_var ret(getScopePtrGivenName(scopeName)); + return SALOME::DataScopeServer::_duplicate(ret); +} + +void DataServerManager::removeDataScope(const char *scopeName) +{ + SALOME::DataScopeServer_var scs(getScopePtrGivenName(scopeName)); + scs->shutdownIfNotHostedByDSM(); +} + +void DataServerManager::cleanScopesInNS() +{ + SALOME_NamingService ns(_orb); + std::vector scopes(listOfScopesCpp()); + for(std::vector::const_iterator it=scopes.begin();it!=scopes.end();it++) + { + if(!isAliveAndKicking((*it).c_str())) + { + std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(*it)); + ns.Destroy_Name(fullScopeName.c_str()); + } + } +} + +void DataServerManager::shutdownScopes() +{ + std::vector scopeNames(listOfScopesCpp()); + for(std::vector::const_iterator it=scopeNames.begin();it!=scopeNames.end();it++) + getScopePtrGivenName(*it)->shutdownIfNotHostedByDSM(); +} + +std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& scopeName) +{ + std::ostringstream oss; oss << NAME_IN_NS << "/" << scopeName; + return oss.str(); +} + +std::vector DataServerManager::listOfScopesCpp() +{ + SALOME_NamingService ns(_orb); + ns.Change_Directory(NAME_IN_NS); + std::vector ret(ns.list_directory()); + return ret; +} + +SALOME::DataScopeServer_var DataServerManager::getScopePtrGivenName(const std::string& scopeName) +{ + std::vector scopes(listOfScopesCpp()); + std::size_t sz(scopes.size()); + if(std::find(scopes.begin(),scopes.end(),scopeName)==scopes.end()) + { + std::ostringstream oss; oss << "DataServerManager::getScopePtrGivenName : scope name \"" << scopeName << "\" does not exist !"; + throw Exception(oss.str()); + } + SALOME_NamingService ns(_orb); + std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName)); + CORBA::Object_var obj(ns.Resolve(fullScopeName.c_str())); + SALOME::DataScopeServer_var ret(SALOME::DataScopeServer::_narrow(obj)); + return ret; +} diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx new file mode 100644 index 000000000..cf835c486 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -0,0 +1,64 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_DATASERVERMANAGER_HXX__ +#define __SALOMESDS_DATASERVERMANAGER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include "SALOMESDS_AutoRefCountPtr.hxx" +#include "SALOMESDS_DataScopeServer.hxx" + +#include + +namespace SALOMESDS +{ + class DataScopeServer; + + class DataServerManager : public virtual POA_SALOME::DataServerManager + { + public: + DataServerManager(int argc, char *argv[], CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); + SALOME::StringVec *listScopes(); + SALOME::StringVec *listAliveAndKickingScopes(); + SALOME::DataScopeServer_ptr getDefaultScope(); + 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, CORBA::Boolean& isCreated); + void removeDataScope(const char *scopeName); + void cleanScopesInNS(); + void shutdownScopes(); + static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName); + public: + static const char NAME_IN_NS[]; + static const char DFT_SCOPE_NAME_IN_NS[]; + private: + std::vector listOfScopesCpp(); + SALOME::DataScopeServer_var getScopePtrGivenName(const std::string& scopeName); + private: + CORBA::ORB_var _orb; + //! single thread poa + PortableServer::POA_var _poa; + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_Exception.cxx b/src/SALOMESDS/SALOMESDS_Exception.cxx new file mode 100644 index 000000000..5493bbf2d --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_Exception.cxx @@ -0,0 +1,32 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_Exception.hxx" + +SALOMESDS::Exception::Exception(const std::string& reason) +{ + SALOME::ExceptionStruct es; + es.type=SALOME::INTERNAL_ERROR; + es.text=CORBA::string_dup(reason.c_str()); + es.lineNumber=0; + (*this).details=es; +} + + diff --git a/src/SALOMESDS/SALOMESDS_Exception.hxx b/src/SALOMESDS/SALOMESDS_Exception.hxx new file mode 100644 index 000000000..c5943ae8a --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_Exception.hxx @@ -0,0 +1,38 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_EXCEPTION_HXX__ +#define __SALOMESDS_EXCEPTION_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_Exception) + +#include + +namespace SALOMESDS +{ + class Exception : public SALOME::SALOME_Exception + { + public: + Exception(const std::string& reason); + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx new file mode 100644 index 000000000..5409851c0 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx @@ -0,0 +1,137 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx" +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_Exception.hxx" + +#include +#include + +using namespace SALOMESDS; + +PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) +{ +} + +//! obj is consumed +PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj) +{ +} + +PickelizedPyObjRdExtServer::~PickelizedPyObjRdExtServer() +{ +} + +/*! + * Called remotely -> to protect against throw + */ +SALOME::PickelizedPyObjRdExtServer_ptr PickelizedPyObjRdExtServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args) +{ + if(!_self) + throw Exception("PickelizedPyObjRdExtServer::invokePythonMethodOn : self is NULL !"); + std::string argsCpp; + FromByteSeqToCpp(args,argsCpp); + PyObject *argsPy(getPyObjFromPickled(argsCpp)); + checkRdExtnessOf(method,argsPy); + // + PyObject *selfMeth(PyObject_GetAttrString(_self,method)); + if(!selfMeth) + { + std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::invokePythonMethodOn : Method \"" << method << "\" is not available !"; + throw Exception(oss.str()); + } + PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call ! + Py_XDECREF(selfMeth); + Py_XDECREF(argsPy); + if(!res) + { + std::ostringstream oss; oss << "PickelizedPyObjRdExtServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" !"; + throw Exception(oss.str()); + } + PickelizedPyObjRdExtServer *ret(new PickelizedPyObjRdExtServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res)); + PortableServer::POA_var poa(_father->getPOA()); + 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, PyObject *argsPy) +{ + if(!_self) + { + 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,argsPy); + else if(PyDict_Check(_self)==1) + 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, PyObject *argsPy) +{ + static const char *THE_RDEXT_METH_OF_LIST[]={"__getitem__","append","extend","insert","reverse","sort"}; + for(std::size_t i=0;i __setitem__ is NOT RdExt ! + Py_XDECREF(argsPy); + throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : specified key of __setitem__ already exists ! RdExt property is not applied !"); + } +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx new file mode 100644 index 000000000..ea62b734e --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_PICKELIZEDPYOBJRDEXTSERVER_HXX__ +#define __SALOMESDS_PICKELIZEDPYOBJRDEXTSERVER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include + +#include "SALOMESDS_PickelizedPyObjServer.hxx" + +namespace SALOMESDS +{ + class PickelizedPyObjRdExtServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdExtServer + { + public: + PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value); + 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, PyObject *argsPy); + void checkListRdExtnessOf(const std::string& methodName, PyObject *argsPy); + void checkDictRdExtnessOf(const std::string& methodName, PyObject *argsPy); + void checkDictSetitemRdExtness(PyObject *argsPy); + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx new file mode 100644 index 000000000..4626d00da --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.cxx @@ -0,0 +1,35 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_PickelizedPyObjRdOnlyServer.hxx" + +using namespace SALOMESDS; + +PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) +{ +} + +PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj) +{ +} + +PickelizedPyObjRdOnlyServer::~PickelizedPyObjRdOnlyServer() +{ +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx new file mode 100644 index 000000000..68924a737 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdOnlyServer.hxx @@ -0,0 +1,42 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_PICKELIZEDPYOBJRDONLYSERVER_HXX__ +#define __SALOMESDS_PICKELIZEDPYOBJRDONLYSERVER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include + +#include "SALOMESDS_PickelizedPyObjServer.hxx" + +namespace SALOMESDS +{ + class PickelizedPyObjRdOnlyServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdOnlyServer + { + public: + PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value); + PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, PyObject *obj); + ~PickelizedPyObjRdOnlyServer(); + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx new file mode 100644 index 000000000..848cefc16 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.cxx @@ -0,0 +1,110 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_PickelizedPyObjRdWrServer.hxx" +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_Exception.hxx" + +#include +#include + +using namespace SALOMESDS; + +PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName)) +{ +} + +PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value) +{ +} + +//! obj is consumed +PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj) +{ +} + +PickelizedPyObjRdWrServer::~PickelizedPyObjRdWrServer() +{ +} + +/*! + * Called remotely -> to protect against throw + */ +void PickelizedPyObjRdWrServer::setSerializedContent(const SALOME::ByteVec& newValue) +{ + setSerializedContentInternal(newValue); +} + +/*! + * Called remotely -> to protect against throw + */ +SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args) +{ + if(!_self) + throw Exception("PickelizedPyObjRdWrServer::invokePythonMethodOn : self is NULL !"); + std::string argsCpp; + FromByteSeqToCpp(args,argsCpp); + PyObject *argsPy(getPyObjFromPickled(argsCpp)); + // + PyObject *selfMeth(PyObject_GetAttrString(_self,method)); + if(!selfMeth) + { + std::ostringstream oss; oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Method \"" << method << "\" is not available !"; + throw Exception(oss.str()); + } + PyObject *res(PyObject_CallObject(selfMeth,argsPy));// self can have been modified by this call ! + Py_XDECREF(selfMeth); + Py_XDECREF(argsPy); + if(!res) + { + std::ostringstream oss,oss2,oss3; + PyObject *errTyp(0),*errValue(0),*errTB(0); + PyErr_Fetch(&errTyp,&errValue,&errTB); + oss2 << "("; + if(errTyp) + { + PyObject *ob(PyObject_Str(errTyp)); + oss2 << " type : \"" << (const char *)PyString_AsString(ob) << "\""; + Py_XDECREF(ob); Py_XDECREF(errTyp); + } + if(errValue) + { + PyObject *ob(PyObject_Str(errValue)); + oss2 << " value : \"" << (const char *)PyString_AsString(ob) << "\""; + Py_XDECREF(ob); Py_XDECREF(errValue); + } + oss2 << " )"; + if(errTB) + { + PyObject *ob(PyObject_Str(errTB)); + oss2 << "( traceback : \"" << (const char *)PyString_AsString(ob) << "\""; + Py_XDECREF(ob); Py_XDECREF(errTB); + } + oss2 << " )"; + PyErr_Clear(); + oss << "PickelizedPyObjRdWrServer::invokePythonMethodOn : Problem during invokation serverside of Method \"" << method << "\" ! Details are : " << oss2.str() << "\n\n" << "TraceBack is : " << oss3.str(); + throw Exception(oss.str()); + } + PickelizedPyObjRdWrServer *ret(new PickelizedPyObjRdWrServer(_father,DataScopeServer::BuildTmpVarNameFrom(getVarNameCpp()),res)); + PortableServer::POA_var poa(_father->getPOA()); + PortableServer::ObjectId_var id(poa->activate_object(ret)); + CORBA::Object_var obj(poa->id_to_reference(id)); + return SALOME::PickelizedPyObjRdWrServer::_narrow(obj); +} diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx new file mode 100644 index 000000000..fe33ca229 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdWrServer.hxx @@ -0,0 +1,45 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_PICKELIZEDPYOBJRDWRSERVER_HXX__ +#define __SALOMESDS_PICKELIZEDPYOBJRDWRSERVER_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include + +#include "SALOMESDS_PickelizedPyObjServer.hxx" + +namespace SALOMESDS +{ + class PickelizedPyObjRdWrServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdWrServer + { + public: + PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName); + PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value); + PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj); + ~PickelizedPyObjRdWrServer(); + void setSerializedContent(const SALOME::ByteVec& newValue); + SALOME::PickelizedPyObjRdWrServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args); + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx new file mode 100644 index 000000000..baba4b55d --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -0,0 +1,161 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_PickelizedPyObjServer.hxx" +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_Exception.hxx" + +#include +#include + +using namespace SALOMESDS; + +PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):BasicDataServer(father,varName),_self(0) +{ + setSerializedContentInternal(value); +} + +//! obj is consumed +PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(0) +{ + setNewPyObj(obj); +} + +PickelizedPyObjServer::~PickelizedPyObjServer() +{ + Py_XDECREF(_self); +} + +/*! + * Called remotely -> to protect against throw + */ +SALOME::ByteVec *PickelizedPyObjServer::fetchSerializedContent() +{ + Py_XINCREF(_self);//because pickelize consume _self + return FromCppToByteSeq(pickelize(_self)); +} + +void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret) +{ + std::size_t sz(bsToBeConv.length()); + ret.resize(sz,' '); + char *buf(const_cast(ret.c_str())); + for(std::size_t i=0;ilength(sz); + for(std::size_t i=0;igetPickler(),"loads")); + PyObject *args(PyTuple_New(1)); PyTuple_SetItem(args,0,pickledDataPy); + PyObject *ret(PyObject_CallObject(selfMeth,args)); + Py_XDECREF(args); + Py_XDECREF(selfMeth); + return ret; +} + +//! obj is consumed by this method. +std::string PickelizedPyObjServer::pickelize(PyObject *obj) +{ + PyObject *args(PyTuple_New(2)); + PyTuple_SetItem(args,0,obj); + PyTuple_SetItem(args,1,PyInt_FromLong(2));// because "assert(cPickle.HIGHEST_PROTOCOL is 2)" + PyObject *selfMeth(PyObject_GetAttrString(_father->getPickler(),"dumps")); + PyObject *retPy(PyObject_CallObject(selfMeth,args)); + Py_XDECREF(selfMeth); + Py_XDECREF(args); + std::size_t sz(PyString_Size(retPy)); + std::string ret(sz,'\0'); + const char *buf(PyString_AsString(retPy)); + char *inBuf(const_cast(ret.c_str())); + for(std::size_t i=0;i + +#include "SALOMESDS_BasicDataServer.hxx" + +namespace SALOMESDS +{ + class PickelizedPyObjServer : public BasicDataServer, public virtual POA_SALOME::PickelizedPyObjServer + { + public: + PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value); + PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj); + ~PickelizedPyObjServer(); + void setSerializedContent(const SALOME::ByteVec& newValue); + SALOME::ByteVec *fetchSerializedContent(); + protected: + static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret); + static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv); + PyObject *getPyObjFromPickled(const std::string& pickledData); + std::string pickelize(PyObject *obj); + void setNewPyObj(PyObject *obj); + void setSerializedContentInternal(const SALOME::ByteVec& newValue); + static PyObject *CreateDftObjFromType(PyObject *globals, const std::string& typeName); + protected: + static const char FAKE_VAR_NAME_FOR_WORK[]; + PyObject *_self; + PortableServer::POA_var _poa; + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_RefCountServ.cxx b/src/SALOMESDS/SALOMESDS_RefCountServ.cxx new file mode 100644 index 000000000..b21d5a9dc --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_RefCountServ.cxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_RefCountServ.hxx" + +using namespace SALOMESDS; + +void RefCountServ::incrRef() const +{ + _cnt++; +} + +bool RefCountServ::decrRef() const +{ + bool ret((--_cnt)==0); + if(ret) + { + RefCountServ *thisNC(const_cast(this)); + thisNC->enforcedRelease(); + } + return ret; +} + +void RefCountServ::enforcedRelease() +{ + PortableServer::POA_var poa(getPOA()); + PortableServer::ObjectId_var oid(poa->servant_to_id(this)); + poa->deactivate_object(oid); + _remove_ref(); +} + +RefCountServ::RefCountServ():_cnt(1) +{ +} + +RefCountServ::RefCountServ(const RefCountServ& other):_cnt(1) +{ +} + +RefCountServ::~RefCountServ() +{ +} diff --git a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx new file mode 100644 index 000000000..0ec2d95ab --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx @@ -0,0 +1,44 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#ifndef __SALOMESDS_REFCOUNTSERV_HXX__ +#define __SALOMESDS_REFCOUNTSERV_HXX__ + +#include + +namespace SALOMESDS +{ + class RefCountServ : public virtual PortableServer::ServantBase + { + public: + void incrRef() const; + bool decrRef() const; + virtual PortableServer::POA_var getPOA() = 0; + protected: + void enforcedRelease(); + RefCountServ(); + RefCountServ(const RefCountServ& other); + virtual ~RefCountServ(); + private: + mutable unsigned int _cnt; + }; +} + +#endif diff --git a/src/SALOMESDS/SALOME_DataScopeServer.cxx b/src/SALOMESDS/SALOME_DataScopeServer.cxx new file mode 100644 index 000000000..a5061c384 --- /dev/null +++ b/src/SALOMESDS/SALOME_DataScopeServer.cxx @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 (EDF R&D) + +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_Exception.hxx" + +#include "SALOME_NamingService.hxx" + +#include +#include + +int main(int argc, char *argv[]) +{ + std::string scopeName; + if(argc<=1) + throw SALOMESDS::Exception("In the main of SALOME_DataScopeServer.cxx !"); + scopeName=argv[1]; + CORBA::ORB_var orb(CORBA::ORB_init(argc,argv)); + CORBA::Object_var obj(orb->resolve_initial_references("RootPOA")); + PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); + PortableServer::POAManager_var mgr(poa->the_POAManager()); + mgr->activate(); + SALOMESDS::DataScopeServer *server(new SALOMESDS::DataScopeServer(orb,scopeName)); + // + CORBA::PolicyList policies; + policies.length(1); + PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + PortableServer::POA_var poa2(poa->create_POA("SingleThPOA4SDS",mgr,policies)); + threadPol->destroy(); + server->initializePython(argc,argv);// agy : Very important ! invoke this method BEFORE activation ! + server->registerToSalomePiDict(); + PortableServer::ObjectId_var id(poa2->activate_object(server)); + obj=poa2->id_to_reference(id); + SALOME::DataScopeServer_var serverPtr(SALOME::DataScopeServer::_narrow(obj)); + server->setPOAAndRegister(poa2,serverPtr); + // + orb->run(); + server->_remove_ref(); + return 0; +} + diff --git a/src/SALOMESDS/SalomeSDSClt.py b/src/SALOMESDS/SalomeSDSClt.py new file mode 100644 index 000000000..9b9218c62 --- /dev/null +++ b/src/SALOMESDS/SalomeSDSClt.py @@ -0,0 +1,492 @@ +# -*- 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 SALOME +import cPickle + +class WrappedType(object): + def __init__(self,varPtr,isTemporaryVar=False): + assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer)) + self._var_ptr=varPtr + if not isTemporaryVar: + self._var_ptr.Register() + self._is_temp=isTemporaryVar + pass + + def local_copy(self): + return cPickle.loads(self._var_ptr.fetchSerializedContent()) + + def __str__(self): + return self.local_copy().__str__() + + def __repr__(self): + return self.local_copy().__repr__() + + def __reduce__(self): + 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 + + def __del__(self): + self._var_ptr.UnRegister() + pass + pass + +class List(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=list + pass + + def __getitem__(self,*args): + ret=Caller(self._var_ptr,"__getitem__") + return ret(*args) + + def __setitem__(self,*args): + ret=Caller(self._var_ptr,"__setitem__") + return ret(*args) + + def __delitem__(self,*args): + ret=Caller(self._var_ptr,"__delitem__") + return ret(*args) + + def append(self,*args): + ret=Caller(self._var_ptr,"append") + return ret(*args) + + def extend(self,*args): + ret=Caller(self._var_ptr,"extend") + return ret(*args) + + def insert(self,*args): + ret=Caller(self._var_ptr,"insert") + return ret(*args) + + def pop(self,*args): + ret=Caller(self._var_ptr,"pop") + return ret(*args) + + def remove(self,*args): + ret=Caller(self._var_ptr,"remove") + return ret(*args) + + def reverse(self,*args): + ret=Caller(self._var_ptr,"reverse") + return ret(*args) + + def sort(self,*args): + ret=Caller(self._var_ptr,"sort") + return ret(*args) + + 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) + self._wrapped_type=dict + pass + + def __getitem__(self,*args): + ret=Caller(self._var_ptr,"__getitem__") + return ret(*args) + + def __setitem__(self,*args): + ret=Caller(self._var_ptr,"__setitem__") + return ret(*args) + + def __delitem__(self,*args): + ret=Caller(self._var_ptr,"__delitem__") + return ret(*args) + + def clear(self,*args): + ret=Caller(self._var_ptr,"clear") + return ret(*args) + + def get(self,*args): + ret=Caller(self._var_ptr,"get") + return ret(*args) + + def items(self,*args): + ret=Caller(self._var_ptr,"items") + return ret(*args) + + def pop(self,*args): + ret=Caller(self._var_ptr,"pop") + return ret(*args) + + def popitem(self,*args): + ret=Caller(self._var_ptr,"popitem") + return ret(*args) + + def setdefault(self,*args): + ret=Caller(self._var_ptr,"setdefault") + return ret(*args) + + def update(self,*args): + ret=Caller(self._var_ptr,"update") + return ret(*args) + + def values(self,*args): + ret=Caller(self._var_ptr,"values") + return ret(*args) + + # work on local copy + + def __contains__(self,*args): + return self.local_copy().__contains__(*args) + + def has_key(self,*args): + return self.local_copy().has_key(*args) + + def keys(self,*args): + return self.local_copy().keys(*args) + + def copy(self,*args): + return self.local_copy().copy(*args) + + def __len__(self): + 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 Float(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=float + pass + + def __iadd__(self,*args): + return self.local_copy().__add__(*args) + + def __isub__(self,*args): + return self.local_copy().__sub__(*args) + + def __imul__(self,*args): + return self.local_copy().__mul__(*args) + + def __idiv__(self,*args): + return self.local_copy().__div__(*args) + + def __add__(self,*args): + return self.local_copy().__add__(*args) + + def __sub__(self,*args): + return self.local_copy().__sub__(*args) + + def __mul__(self,*args): + return self.local_copy().__mul__(*args) + + def __div__(self,*args): + return self.local_copy().__div__(*args) + + def __pow__(self,*args): + return self.local_copy().__pow__(*args) + + def as_integer_ratio(self,*args): + return self.local_copy().as_integer_ratio(*args) + + def conjugate(self,*args): + return self.local_copy().conjugate(*args) + + def fromhex(self,*args): + return self.local_copy().fromhex(*args) + + def hex(self,*args): + return self.local_copy().hex(*args) + + def imag(self,*args): + return self.local_copy().imag(*args) + + def is_integer(self,*args): + return self.local_copy().is_integer(*args) + + def real(self,*args): + return self.local_copy().real(*args) + pass + +class Int(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=int + pass + + def __iadd__(self,*args): + return self.local_copy().__add__(*args) + + def __isub__(self,*args): + return self.local_copy().__sub__(*args) + + def __imul__(self,*args): + return self.local_copy().__mul__(*args) + + def __imod__(self,*args): + return self.local_copy().__mod__(*args) + + def __idiv__(self,*args): + return self.local_copy().__div__(*args) + + def __add__(self,*args): + return self.local_copy().__add__(*args) + + def __sub__(self,*args): + return self.local_copy().__sub__(*args) + + def __mul__(self,*args): + return self.local_copy().__mul__(*args) + + def __mod__(self,*args): + return self.local_copy().__mod__(*args) + + def __div__(self,*args): + return self.local_copy().__div__(*args) + + def __pow__(self,*args): + return self.local_copy().__pow__(*args) + + def bit_length(self,*args): + return self.local_copy().bit_length(*args) + + def conjugate(self,*args): + return self.local_copy().conjugate(*args) + + def denominator(self,*args): + return self.local_copy().denominator(*args) + + def imag(self,*args): + return self.local_copy().imag(*args) + + def numerator(self,*args): + return self.local_copy().numerator(*args) + + def real(self,*args): + return self.local_copy().real(*args) + pass + +class String(WrappedType): + def __init__(self,varPtr,isTemporaryVar=False): + WrappedType.__init__(self,varPtr,isTemporaryVar) + self._wrapped_type=int + pass + + def __add__(self,*args): + return self.local_copy().__add__(*args) + + def __iadd__(self,*args): + return self.local_copy().__add__(*args) + + def __getitem__(self,*args): + return self.local_copy().__getitem__(*args) + + def capitalize(self,*args): + return self.local_copy().capitalize(*args) + + def center(self,*args): + return self.local_copy().center(*args) + + def count(self,*args): + return self.local_copy().count(*args) + + def decode(self,*args): + return self.local_copy().decode(*args) + + def encode(self,*args): + return self.local_copy().encode(*args) + + def endswith(self,*args): + return self.local_copy().endswith(*args) + + def expandtabs(self,*args): + return self.local_copy().expandtabs(*args) + + def find(self,*args): + return self.local_copy().find(*args) + + def format(self,*args): + return self.local_copy().format(*args) + + def index(self,*args): + return self.local_copy().index(*args) + + def isalnum(self,*args): + return self.local_copy().isalnum(*args) + + def isalpha(self,*args): + return self.local_copy().isalpha(*args) + + def isdigit(self,*args): + return self.local_copy().isdigit(*args) + + def islower(self,*args): + return self.local_copy().islower(*args) + + def isspace(self,*args): + return self.local_copy().isspace(*args) + + def istitle(self,*args): + return self.local_copy().istitle(*args) + + def isupper(self,*args): + return self.local_copy().isupper(*args) + + def join(self,*args): + return self.local_copy().join(*args) + + def ljust(self,*args): + return self.local_copy().ljust(*args) + + def lower(self,*args): + return self.local_copy().lower(*args) + + def lstrip(self,*args): + return self.local_copy().lstrip(*args) + + def partition(self,*args): + return self.local_copy().partition(*args) + + def replace(self,*args): + return self.local_copy().replace(*args) + + def rfind(self,*args): + return self.local_copy().rfind(*args) + + def rindex(self,*args): + return self.local_copy().rindex(*args) + + def rjust(self,*args): + return self.local_copy().rjust(*args) + + def rpartition(self,*args): + return self.local_copy().rpartition(*args) + + def rsplit(self,*args): + return self.local_copy().rsplit(*args) + + def rstrip(self,*args): + return self.local_copy().rstrip(*args) + + def split(self,*args): + return self.local_copy().split(*args) + + def splitlines(self,*args): + return self.local_copy().splitlines(*args) + + def startswith(self,*args): + return self.local_copy().startswith(*args) + + def strip(self,*args): + return self.local_copy().strip(*args) + + def swapcase(self,*args): + return self.local_copy().swapcase(*args) + + def title(self,*args): + return self.local_copy().title(*args) + + def translate(self,*args): + return self.local_copy().translate(*args) + + def upper(self,*args): + return self.local_copy().upper(*args) + + def zfill(self,*args): + return self.local_copy().zfill(*args) + + def __len__(self): + return len(self.local_copy()) + pass + +class Caller: + def __init__(self,varPtr,meth): + assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer)) + self._var_ptr=varPtr + self._meth=meth + pass + + def __call__(self,*args): + ret=self._var_ptr.invokePythonMethodOn(self._meth,cPickle.dumps(args,cPickle.HIGHEST_PROTOCOL)) + return GetHandlerFromRef(ret,True) + pass + +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_PickelizedPyObjServer)) + v=cPickle.loads(objCorba.fetchSerializedContent()) + if v is None: + objCorba.UnRegister() + 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(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(scopeName) + 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.retriveDataScope(scopeName) + return GetHandlerFromRef(d2s.retrieveVar(varName),False) diff --git a/src/SALOMESDS/TestSalomeSDS1.py b/src/SALOMESDS/TestSalomeSDS1.py new file mode 100644 index 000000000..26e11ac8d --- /dev/null +++ b/src/SALOMESDS/TestSalomeSDS1.py @@ -0,0 +1,102 @@ +# -*- 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 salome +import SALOME +import cPickle +import gc +import SalomeSDSClt + +st="jjj" +dsm=salome.naming_service.Resolve("/DataServerManager") +assert(dsm.isAliveAndKicking("Default")) +assert(isinstance(dsm,SALOME._objref_DataServerManager)) +assert(isinstance(dsm.getDefaultScope(),SALOME._objref_DataScopeServer)) +d2s=dsm.createDataScope("tonyy") +assert(isinstance(d2s,SALOME._objref_DataScopeServer)) +a=d2s.createRdWrVar("str","c") +assert(a.getVarName()=="c") +# +a.setSerializedContent(cPickle.dumps(st,cPickle.HIGHEST_PROTOCOL)) +assert(cPickle.loads(a.fetchSerializedContent())==st) +assert(cPickle.loads(a.fetchSerializedContent())==st) +assert(cPickle.loads(d2s.retrieveVar("c").fetchSerializedContent())==st) +assert(isinstance(d2s.retrieveVar("c"),SALOME._objref_PickelizedPyObjRdWrServer)) +assert(dsm.listScopes()==['Default','tonyy']) +dsm.createDataScope("S2") +assert(dsm.retriveDataScope("S2").getScopeName()=="S2") +assert(dsm.listScopes()==['Default','tonyy','S2']) +dsm.removeDataScope("Default") +assert(dsm.listScopes()==['tonyy','S2']) +dsm.removeDataScope("tonyy") +assert(dsm.listScopes()==['S2']) +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)[0].createRdWrVar("list","a") +dsm.giveADataScopeCalled(sname) +a.setSerializedContent(cPickle.dumps([0,],cPickle.HIGHEST_PROTOCOL)) +assert(cPickle.loads(a.fetchSerializedContent())==[0,]) +a.setSerializedContent(st) +assert(cPickle.loads(a.fetchSerializedContent())==[]) +tmp=a.invokePythonMethodOn("append",cPickle.dumps((0,),cPickle.HIGHEST_PROTOCOL)) +assert(cPickle.loads(a.fetchSerializedContent())==[0]) +for i in xrange(0,1000): + tmp=a.invokePythonMethodOn("append",cPickle.dumps((i,),cPickle.HIGHEST_PROTOCOL)) + pass +dsm.removeDataScope(sname) +# +sname="S4" +d2s,_=dsm.giveADataScopeCalled(sname) +d2s.createRdWrVar("list","a") +a=SalomeSDSClt.GetHandlerFromRef(dsm.retriveDataScope(sname).retrieveVar("a")) +a.append(1) +for i in xrange(1000): + a.append(i) + pass +assert(sum(a.local_copy())==499501) +assert(dsm.isAliveAndKicking(sname)) +# +dsm=salome.naming_service.Resolve("/DataServerManager") +sname="S11" +d2s,_=dsm.giveADataScopeCalled(sname) +d2s.createRdWrVar("dict","a") +a=SalomeSDSClt.GetHandlerFromName(sname,"a") +assert(isinstance(a,SalomeSDSClt.Dict)) +a.assign({}) +a["ab"]=45 ; gc.collect(0) +a["cd"]=[4,5] ; gc.collect(0) +a["cd"].append(77) ; gc.collect(0) +a["cd"].append([4,7,8]) ; gc.collect(0) +a["cd"][3].append(3) ; gc.collect(0) +a["ab"]+=2 +assert(a.local_copy()=={'ab':47,'cd':[4,5,77,[4,7,8,3]]}) +a["ab"]-=1 +assert(a.local_copy()=={'ab':46,'cd':[4,5,77,[4,7,8,3]]}) +assert(len(a)==2) +c=a["cd"] ; gc.collect(0) +assert(isinstance(c,SalomeSDSClt.List)) +a["cd"]=26 ; gc.collect(0) +assert(a.local_copy()=={'ab':46,'cd':26}) +a["cd"]=c +assert(a.local_copy()=={'ab':46,'cd':[4,5,77,[4,7,8,3]]}) diff --git a/src/SALOMESDS/TestSalomeSDS2.py b/src/SALOMESDS/TestSalomeSDS2.py new file mode 100644 index 000000000..d4222a991 --- /dev/null +++ b/src/SALOMESDS/TestSalomeSDS2.py @@ -0,0 +1,83 @@ +# -*- 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 testReadOnly1(self): + a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0") + self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]}) + self.assertRaises(AttributeError,a.__getitem__,"ab") + a._var_ptr.getMyDataScopeServer().deleteVar("a") + + def setUp(self): + salome.salome_init() + pass + + pass + +unittest.main() +