]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Exceptions management + clean DataScopes destruction.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 7 Jan 2015 08:13:15 +0000 (09:13 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 7 Jan 2015 08:13:15 +0000 (09:13 +0100)
idl/SALOME_SDS.idl
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_Exception.cxx
src/SALOMESDS/SALOMESDS_Exception.hxx
src/SALOMESDS/SALOMESDS_StringDataServer.cxx
src/SALOMESDS/SALOME_DataScopeServer.cxx
src/SALOMESDS/TestSalomeSDS1.py

index 76f45c8930b870d4195c4cc061ee5530b11a6761..9fcc3ec8575ff6bf07162169e275bdf4db29d4dc 100644 (file)
@@ -19,6 +19,7 @@
 // Author : Anthony GEAY (EDF R&D)
 
 #include "SALOME_GenericObj.idl"
+#include "SALOME_Exception.idl"
 
 module SALOME
 {
@@ -35,9 +36,9 @@ module SALOME
 
   interface StringDataServer : BasicDataServer
   {
-    void setSerializedContent(in ByteVec newValue);
-    ByteVec fetchSerializedContent();
-    StringDataServer invokePythonMethodOn(in string method, in ByteVec args);
+    void setSerializedContent(in ByteVec newValue) raises (SALOME::SALOME_Exception);
+    ByteVec fetchSerializedContent() raises (SALOME::SALOME_Exception);
+    StringDataServer invokePythonMethodOn(in string method, in ByteVec args) raises (SALOME::SALOME_Exception);
   };
 
   interface DataServerManager;
@@ -47,23 +48,23 @@ module SALOME
     void ping();
     string getScopeName();
     StringVec listVars();
-    BasicDataServer retrieveVar(in string varName);
-    StringDataServer createGlobalStringVar(in string typeName, in string varName);
-    StringDataServer createGlobalTmpVar(in ByteVec newValue);
+    BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception);
+    StringDataServer createGlobalStringVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception);
+    StringDataServer createGlobalTmpVar(in ByteVec newValue) raises (SALOME::SALOME_Exception);
     void shutdownIfNotHostedByDSM();
   };
 
   interface DataServerManager
   {
     StringVec listScopes();
-    StringVec listAliveAndKickingScopes();
-    DataScopeServer getDefaultScope();
-    boolean isAliveAndKicking(in string scopeName);
-    DataScopeServer createDataScope(in string scopeName);
-    DataScopeServer retriveDataScope(in string scopeName);
+    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);
-    void removeDataScope(in string scopeName);
+    void removeDataScope(in string scopeName) raises (SALOME::SALOME_Exception);
     void cleanScopesInNS();
-    void shutdownScopes();
+    void shutdownScopes() raises (SALOME::SALOME_Exception);
   };
 };
index 5b3cfc1c2ce378fb969f81c381d5835ea305f00c..a1a109496385737b6ef3aeceac45e9e491469fb5 100644 (file)
 #include <iterator>
 #include <algorithm>
 
+// agy : awful, to be factorized with ContainerManager.
+#ifndef WIN32
+#include <unistd.h>
+#else
+#include <process.h>
+#define getpid _getpid
+#endif
+
 using namespace SALOMESDS;
 
 std::size_t DataScopeServer::COUNTER=0;
@@ -181,6 +189,23 @@ void DataScopeServer::initializePython(int argc, char *argv[])
   _pickler=PyImport_ImportModuleLevel(const_cast<char *>("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.
  */
index 6f50f68c008d21602ebe17a930a7bad396b62039..cf80fee60e314bf3bfa0bf3c12fc32afb5d11b0a 100644 (file)
@@ -51,6 +51,7 @@ namespace SALOMESDS
     ~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; }
index fd3d8e199826fa86365b92bc31b49895f93630a1..5493bbf2d0bf849e9da5923c02fdc51bd14b2756 100644 (file)
 
 #include "SALOMESDS_Exception.hxx"
 
-SALOMESDS::Exception::Exception(const std::string& reason):_reason(reason)
+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;
 }
 
-SALOMESDS::Exception::~Exception() throw ()
-{
-}
 
-const char *SALOMESDS::Exception::what() const throw()
-{
-  return _reason.c_str();
-}
index 2299c223352b96b7b430efa87bbe76bf2c146a9f..c5943ae8a0c00922c81cfaacde465b63bf3c7c5c 100644 (file)
 #ifndef __SALOMESDS_EXCEPTION_HXX__
 #define __SALOMESDS_EXCEPTION_HXX__
 
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_Exception)
+
 #include <string>
-#include <exception>
 
 namespace SALOMESDS
 {
-  class Exception : public std::exception
+  class Exception : public SALOME::SALOME_Exception
   {
   public:
     Exception(const std::string& reason);
-    ~Exception() throw ();
-    const char *what() const throw();
-  protected:
-    std::string _reason;
   };
 }
 
index 87b155a67db40770ffcd8490c1b94fd83e303804..8bece7749ec69b1c1b04fb8cb03d78688a8b2b36 100644 (file)
@@ -166,6 +166,18 @@ void StringDataServer::setNewPyObj(PyObject *obj)
     throw Exception("StringDataServer::setNewPyObj : trying to assign a NULL pyobject in this !");
   if(obj==_self)
     return ;
+  if(_self)
+    {
+      PyObject *selfType(PyObject_Type(_self));
+      if(PyObject_IsInstance(obj,selfType)!=1)
+        {
+          Py_XDECREF(obj);
+          Py_XDECREF(selfType);
+          throw Exception("StringDataServer::setNewPyObj : type of new object is not the same than those previously set !");
+        }
+      else
+        Py_XDECREF(selfType);
+    }
   Py_XDECREF(_self);
   _self=obj;
 }
index 63e08b90d7c8b3b5e09d19a10ca9369516755250..a5061c38402b0d73359328fe0d67f48a384866de 100644 (file)
@@ -47,6 +47,7 @@ int main(int argc, char *argv[])
   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));
index 4951c98325aa22c31fc47978455f00631049658e..44ab8edb333e30e7688a9ebdf222a5899bff895d 100644 (file)
@@ -32,7 +32,7 @@ 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.createGlobalStringVar("int","c")
+a=d2s.createGlobalStringVar("str","c")
 assert(a.getVarName()=="c")
 #
 a.setSerializedContent(cPickle.dumps(st,cPickle.HIGHEST_PROTOCOL))
@@ -55,8 +55,8 @@ dsm=salome.naming_service.Resolve("/DataServerManager")
 st=cPickle.dumps([],cPickle.HIGHEST_PROTOCOL)
 a=dsm.giveADataScopeCalled(sname).createGlobalStringVar("list","a")
 dsm.giveADataScopeCalled(sname)
-a.setSerializedContent(cPickle.dumps((0,),cPickle.HIGHEST_PROTOCOL))
-assert(cPickle.loads(a.fetchSerializedContent())==(0,))
+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))