// Author : Anthony GEAY (EDF R&D)
#include "SALOME_GenericObj.idl"
+#include "SALOME_Exception.idl"
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;
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);
};
};
#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;
_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.
*/
~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; }
#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();
-}
#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;
};
}
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;
}
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));
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))
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))