KeyWaiter waitForKeyInVar(in string varName, in ByteVec keyVal) raises (SALOME::SALOME_Exception);
KeyWaiter waitForKeyInVarAndKillIt(in string varName, in ByteVec keyVal, out Transaction transac) raises (SALOME::SALOME_Exception);
void atomicApply(in ListOfTransaction transactions) raises (SALOME::SALOME_Exception);
+ ByteVec waitForMonoThrRev(in KeyWaiter kw) raises (SALOME::SALOME_Exception);
};
interface DataServerManager
DataScopeServerBase::DataScopeServerBase(CORBA::ORB_ptr orb, const std::string& scopeName):_globals(0),_locals(0),_pickler(0),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName)
{
- pthread_mutex_init(&_mutex_for_py_interp,0);
}
DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars)
Py_XDECREF(mod);
}
-/*!
- * \a ptr has been activated by the POA \a poa.
- */
-void DataScopeServerBase::setPOAAndRegister(PortableServer::POA_var poa, SALOME::DataScopeServerBase_ptr ptr)
+void DataScopeServerBase::setPOA(PortableServer::POA_var poa)
{
_poa=poa;
+}
+
+void DataScopeServerBase::registerInNS(SALOME::DataScopeServerBase_ptr ptr)
+{
std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name));
SALOME_NamingService ns(_orb);
ns.Register(ptr,fullScopeName.c_str());
+ _ptr_of_this=SALOME::DataScopeServerBase::_duplicate(ptr);
}
std::string DataScopeServerBase::BuildTmpVarNameFrom(const std::string& varName)
return SALOME::KeyWaiter::_narrow(obj);
}
+SALOME::ByteVec *DataScopeServerTransaction::waitForMonoThrRev(SALOME::KeyWaiter_ptr kw)
+{
+ PortableServer::ServantBase *ret(0);
+ try
+ {
+ ret=_poa_for_key_waiter->reference_to_servant(kw);
+ }
+ catch(...) { ret=0; }
+ KeyWaiter *retc(dynamic_cast<KeyWaiter *>(ret));
+ if(!retc)
+ throw Exception("DataScopeServerTransaction::invokeMonoThr : internal error 1 !");
+ retc->_remove_ref();
+ retc->waitForMonoThr();
+}
+
class TrustTransaction
{
public:
#include "SALOMESDS_Defines.hxx"
#include <Python.h>
-#include <pthread.h>
#include <string>
#include <vector>
public:
void initializePython(int argc, char *argv[]);
void registerToSalomePiDict() const;
- void setPOAAndRegister(PortableServer::POA_var poa, SALOME::DataScopeServerBase_ptr ptr);
+ void setPOA(PortableServer::POA_var poa);
+ void registerInNS(SALOME::DataScopeServerBase_ptr ptr);
PyObject *getGlobals() const { return _globals; }
PyObject *getLocals() const { return _locals; }
PyObject *getPickler() const { return _pickler; }
PortableServer::POA_var getPOA() const { return _poa; }
CORBA::ORB_var getORB() { return _orb; }
+ //! MTA = Mono thread activated
+ SALOME::DataScopeServerBase_var getObjectRefMTA() { return _ptr_of_this ;}
std::string getScopeNameCpp() const { return _name; }
static std::string BuildTmpVarNameFrom(const std::string& varName);
public:
void checkNotAlreadyExistingVar(const std::string& varName) const;
void checkExistingVar(const std::string& varName) const;
PickelizedPyObjServer *checkVarExistingAndDict(const std::string& varName);
- pthread_mutex_t *getMutexForPyInterp() { return &_mutex_for_py_interp; }
protected:
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const;
protected:
CORBA::ORB_var _orb;
std::string _name;
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars;
- pthread_mutex_t _mutex_for_py_interp;
+ // CORBA pointer of this activated by monothread POA _poa.
+ SALOME::DataScopeServerBase_var _ptr_of_this;
static std::size_t COUNTER;
};
void addWaitKey(KeyWaiter *kw);
void pingKey(PyObject *keyObj);
void notifyKey(PyObject *keyObj, PyObject *valueObj);
+ SALOME::ByteVec *waitForMonoThrRev(SALOME::KeyWaiter_ptr kw);
public://remotely callable
SALOME::ByteVec *fetchSerializedContent(const char *varName);
SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue);
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);
+ dftScope->setPOA(_poa);
+ obj=dftScope->activate();
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 !
+ dftScope->registerInNS(dftScopePtr);// agy : Very important ! invoke this method BEFORE activation ! Because this method initializes Python !
}
SALOME::StringVec *DataServerManager::listScopes()
using namespace SALOMESDS;
-class MutexLocker
-{
-public:
- MutexLocker(DataScopeServerBase *dss):_dss(dss) { pthread_mutex_lock(_dss->getMutexForPyInterp()); }
- ~MutexLocker() { pthread_mutex_unlock(_dss->getMutexForPyInterp()); }
-private:
- DataScopeServerBase *_dss;
-};
-
KeyWaiter::KeyWaiter(PickelizedPyObjServer *var, const SALOME::ByteVec& keyVal):_var(var),_ze_key(0),_ze_value(0)
{
if(sem_init(&_sem,0,0)!=0)// put value to 0 to lock by default
{
sem_wait(&_sem);
if(!_ze_value)
- throw Exception("KeyWaiter::waitFor : internal error !");
- std::string st;
+ throw Exception("KeyWaiter::waitFor : internal error 1 !");
+ SALOME::ByteVec *ret(0);
{
- MutexLocker ml(_var->getFather());
- Py_XINCREF(_ze_value);
- st=PickelizedPyObjServer::Pickelize(_ze_value,_var->getFather());
+ SALOME::DataScopeServerBase_var ptr(_var->getFather()->getObjectRefMTA());
+ SALOME::DataScopeServerTransaction_var ptr2(SALOME::DataScopeServerTransaction::_narrow(ptr));
+ if(CORBA::is_nil(ptr2))
+ throw Exception("KeyWaiter::waitFor : internal error 2 !");
+ CORBA::Object_var thisPtr(getPOA()->servant_to_reference(this));
+ SALOME::KeyWaiter_var thisPtr2(SALOME::KeyWaiter::_narrow(thisPtr));
+ ret=ptr2->waitForMonoThrRev(thisPtr2);
}
- SALOME::ByteVec *ret(PickelizedPyObjServer::FromCppToByteSeq(st));
enforcedRelease();
return ret;
}
+SALOME::ByteVec *KeyWaiter::waitForMonoThr()
+{
+ Py_XINCREF(_ze_value);
+ std::string st(PickelizedPyObjServer::Pickelize(_ze_value,_var->getFather()));
+ return PickelizedPyObjServer::FromCppToByteSeq(st);
+}
+
/*!
* WARNING call this method before calling go !
*/
SALOME::ByteVec *waitFor();
void valueJustCome(PyObject *val);
void go();
+ SALOME::ByteVec *waitForMonoThr();
private:
DataScopeServerTransaction *getDSS() const { return static_cast<DataScopeServerTransaction *>(_var->getFather()); }//thanks to dynamic_cast in constructor
private:
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);
+ //
+ server->setPOA(poa2);
+ obj=server->activate();
SALOME::DataScopeServerBase_var serverPtr(SALOME::DataScopeServerBase::_narrow(obj));
- server->setPOAAndRegister(poa2,serverPtr);
+ server->registerInNS(serverPtr);
//
orb->run();
server->_remove_ref();