-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 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
#include "SALOMESDS_PickelizedPyObjRdOnlyServer.hxx"
#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
#include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdExtInitServer.hxx"
+#include "SALOMESDS_TrustTransaction.hxx"
#include "SALOMESDS_KeyWaiter.hxx"
#include "SALOMESDS_Transaction.hxx"
#include "SALOME_NamingService.hxx"
_orb->shutdown(0);
}
+RequestSwitcher::RequestSwitcher(CORBA::ORB_ptr orb)
+{
+ CORBA::Object_var obj(orb->resolve_initial_references("RootPOA"));
+ PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
+ _poa_manager_under_control=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);
+ // all is in PortableServer::POAManager::_nil. By specifying _nil cf Advanced CORBA Programming with C++ p 506
+ // a new POA manager is created. This POA manager is independent from POA manager of the son ones.
+ _poa_for_request_control=poa->create_POA("4RqstSwitcher",PortableServer::POAManager::_nil(),policies);
+ threadPol->destroy();
+ PortableServer::POAManager_var mgr(_poa_for_request_control->the_POAManager());
+ mgr->activate();
+ //obj=orb->resolve_initial_references ("POACurrent");// agy : usage of POACurrent breaks the hold_requests. Why ?
+ //PortableServer::Current_var current(PortableServer::Current::_narrow(obj));
+}
+
+void RequestSwitcher::holdRequests()
+{
+ _poa_manager_under_control->hold_requests(true);
+}
+
+void RequestSwitcher::activeRequests()
+{
+ _poa_manager_under_control->activate();
+}
+
DataScopeServerBase::DataScopeServerBase(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):_globals(0),_locals(0),_pickler(0),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(killer)
{
}
-DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars),_killer(other._killer)
+DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):omniServant(other),ServantBase(other),_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars),_killer(other._killer)
{
}
return ret;
}
+SALOME::RequestSwitcher_ptr DataScopeServerBase::getRequestSwitcher()
+{
+ if(_rs.isNull())
+ {
+ _rs=new RequestSwitcher(_orb);
+ }
+ CORBA::Object_var obj(_rs->activate());
+ return SALOME::RequestSwitcher::_narrow(obj);
+}
+
+void DataScopeServerBase::takeANap(CORBA::Double napDurationInSec)
+{
+ if(napDurationInSec<0.)
+ throw Exception("DataScopeServerBase::takeANap : negative value !");
+#ifndef WIN32
+ struct timespec req,rem;
+ long nbSec((long)napDurationInSec);
+ double remainTime(napDurationInSec-(double)nbSec);
+ req.tv_sec=nbSec;
+ req.tv_nsec=(long)(remainTime*1000000.);
+ int ret(nanosleep(&req,&rem));
+ if(ret!=0)
+ throw Exception("DataScopeServerBase::takeANap : nap not finished as expected !");
+#else
+ throw Exception("DataScopeServerBase::takeANap : not implemented for Windows !");
+#endif
+}
+
void DataScopeServerBase::initializePython(int argc, char *argv[])
{
Py_Initialize();
void DataScopeServerBase::registerToSalomePiDict() const
{
- PyObject *mod(PyImport_ImportModule("addToKillList"));
+ PyObject *mod(PyImport_ImportModule("addToKillList"));//new value
if(!mod)
return;
- PyObject *meth(PyObject_GetAttrString(mod,"addToKillList"));
+ PyObject *meth(PyObject_GetAttrString(mod,"addToKillList"));//new value
if(!meth)
{ Py_XDECREF(mod); return ; }
PyObject *args(PyTuple_New(2));
PyObject *res(PyObject_CallObject(meth,args));
Py_XDECREF(args);
Py_XDECREF(res);
+ Py_XDECREF(meth);
Py_XDECREF(mod);
}
varc->decrRef();
}
+void DataScopeServerBase::moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit(const std::string& varName)
+{
+ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName));
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it);
+ PickelizedPyObjRdExtServer *varc0(dynamic_cast<PickelizedPyObjRdExtServer *>(p.second));
+ PickelizedPyObjRdExtInitServer *varc1(dynamic_cast<PickelizedPyObjRdExtInitServer *>(p.second));
+ if(!varc0 && !varc1)
+ throw Exception("DataScopeServerBase::moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit : var is neither RdExt nor RdExtInit !");
+ if(varc0)
+ {
+ PyObject *pyobj(varc0->getPyObj()); Py_XINCREF(pyobj);
+ PickelizedPyObjRdExtInitServer *newVar(new PickelizedPyObjRdExtInitServer(this,varName,pyobj));
+ newVar->incrNbClients();
+ CORBA::Object_var obj(newVar->activate());
+ SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj));
+ p.first=obj2; p.second=newVar;
+ varc0->decrRef();
+ }
+ else
+ varc1->incrNbClients();
+}
+
+void DataScopeServerBase::moveStatusOfVarFromRdExtOrRdExtInitToRdExt(const std::string& varName)
+{
+ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName));
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it);
+ PickelizedPyObjRdExtInitServer *varc0(dynamic_cast<PickelizedPyObjRdExtInitServer *>(p.second));
+ PickelizedPyObjRdExtServer *varc1(dynamic_cast<PickelizedPyObjRdExtServer *>(p.second));
+ if(!varc0 && !varc1)
+ throw Exception("DataScopeServerBase::moveStatusOfVarFromRdExtOrRdExtInitToRdExt : var is not a RdExtInit !");
+ if(varc0)
+ {
+ if(varc0->decrNbClients())
+ {
+ PyObject *pyobj(varc0->getPyObj()); Py_XINCREF(pyobj);
+ PickelizedPyObjRdExtServer *newVar(new PickelizedPyObjRdExtServer(this,varName,pyobj));
+ CORBA::Object_var obj(newVar->activate());
+ SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj));
+ p.first=obj2; p.second=newVar;
+ varc0->decrRef();
+ }
+ }
+}
+
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator DataScopeServerBase::retrieveVarInternal3(const std::string& varName) const
{
std::vector<std::string> allNames(getAllVarNames());
{
}
-DataScopeServer::DataScopeServer(const DataScopeServer& other):DataScopeServerBase(other)
+DataScopeServer::DataScopeServer(const DataScopeServer& other):omniServant(other),ServantBase(other),DataScopeServerBase(other)
{
}
_poa_for_key_waiter=poa2;
}
-DataScopeServerTransaction::DataScopeServerTransaction(const DataScopeServerTransaction& other):DataScopeServerBase(other),_poa_for_key_waiter(other.getPOA4KeyWaiter())
+DataScopeServerTransaction::DataScopeServerTransaction(const DataScopeServerTransaction& other):omniServant(other),ServantBase(other),DataScopeServerBase(other),_poa_for_key_waiter(other.getPOA4KeyWaiter())
{
}
return CORBA::string_dup(ret.c_str());
}
+/*!
+ * This method is here to retrieve atomically accessStr and picklization.
+ */
+void DataScopeServerTransaction::fetchAndGetAccessOfVar(const char *varName, CORBA::String_out access, SALOME::ByteVec_out data)
+{
+ access=getAccessOfVar(varName);
+ data=fetchSerializedContent(varName);
+}
+
void DataScopeServerTransaction::createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
{
checkNotAlreadyExistingVar(varName);
_vars.push_back(p);
}
+void DataScopeServerTransaction::createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
+{
+ checkNotAlreadyExistingVar(varName);
+ PickelizedPyObjRdExtInitServer *tmp(new PickelizedPyObjRdExtInitServer(this,varName,constValue));
+ CORBA::Object_var ret(tmp->activate());
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
+ _vars.push_back(p);
+}
+
void DataScopeServerTransaction::createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
{
checkNotAlreadyExistingVar(varName);
return SALOME::Transaction::_narrow(obj);
}
+SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue)
+{
+ checkNotAlreadyExistingVar(varName);
+ TransactionRdExtInitVarCreate *ret(new TransactionRdExtInitVarCreate(this,varName,constValue));
+ CORBA::Object_var obj(ret->activate());
+ return SALOME::Transaction::_narrow(obj);
+}
+
SALOME::Transaction_ptr DataScopeServerTransaction::createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue)
{
checkNotAlreadyExistingVar(varName);
}
}
-void DataScopeServerTransaction::notifyKey(PyObject *keyObj, PyObject *valueObj)
+void DataScopeServerTransaction::notifyKey(const std::string& varName, PyObject *keyObj, PyObject *valueObj)
{
PyObject *cmpObj(getPyCmpFunc());
if(!keyObj)
std::list< KeyWaiter *> newList,listOfEltToWakeUp;
for(std::list< KeyWaiter *>::iterator it=_waiting_keys.begin();it!=_waiting_keys.end();it++,ii++)
{
+ if((*it)->getVarName()!=varName)
+ {
+ newList.push_back(*it);
+ continue;
+ }
PyObject *waitKey((*it)->getKeyPyObj());
PyTuple_SetItem(args,1,waitKey); Py_XINCREF(waitKey);
PyObject *res(PyObject_CallObject(cmpObj,args));
TransactionAddKeyValueErrorIfAlreadyExisting *ret(new TransactionAddKeyValueErrorIfAlreadyExisting(this,varName,key,value));
CORBA::Object_var obj(ret->activate());
return SALOME::Transaction::_narrow(obj);
-};
-
-class TrustTransaction
-{
-public:
- TrustTransaction():_must_rollback(0),_ptr(0) { }
- void setTransaction(Transaction *t, bool *mustRollback) { if(!t || !mustRollback) throw Exception("TrustTransaction Error #1"); _ptr=t; _must_rollback=mustRollback; _ptr->prepareRollBackInCaseOfFailure(); }
- void operate() { _ptr->perform(); }
- ~TrustTransaction() { if(!_ptr) return ; if(*_must_rollback) _ptr->rollBack(); }
-private:
- bool *_must_rollback;
- Transaction *_ptr;
-};
+}
-void DataScopeServerTransaction::addKeyValueInVarErrorIfAlreadyExistingNow(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value)
+SALOME::TransactionMultiKeyAddSession_ptr DataScopeServerTransaction::addMultiKeyValueSession(const char *varName)
{
checkVarExistingAndDict(varName);
- TransactionAddKeyValueErrorIfAlreadyExisting ret(this,varName,key,value);
- {
- bool mustRollback(true);
- TrustTransaction t;
- t.setTransaction(&ret,&mustRollback);
- t.operate();
- mustRollback=false;
- }
+ TransactionMultiKeyAddSession *ret(new TransactionMultiKeyAddSession(this,varName));
+ CORBA::Object_var obj(ret->activate());
+ return SALOME::TransactionMultiKeyAddSession::_narrow(obj);
}
SALOME::Transaction_ptr DataScopeServerTransaction::removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const SALOME::ByteVec& key)
return SALOME::TransactionRdWrAccess::_narrow(obj2);
}
+SALOME::Transaction_ptr DataScopeServerTransaction::killVarTransac(const char *varName)
+{
+ std::string varNameCpp(varName);
+ checkExistingVar(varNameCpp);
+ //
+ TransactionKillVar *ret(new TransactionKillVar(this,varName));
+ CORBA::Object_var obj2(ret->activate());
+ return SALOME::Transaction::_narrow(obj2);
+}
+
SALOME::KeyWaiter_ptr DataScopeServerTransaction::waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal)
{
PickelizedPyObjServer *pickelObj(checkVarExistingAndDict(varName));
PortableServer::ServantBase *ret(0);
try
{
- ret=_poa_for_key_waiter->reference_to_servant(kw);
+ ret=_poa_for_key_waiter->reference_to_servant(kw);// Warning ref cnt of ret has been incremented !
+ }
+ catch(...) { ret=0; }
+ KeyWaiter *retc(dynamic_cast<KeyWaiter *>(ret));
+ if(!retc)
+ throw Exception("DataScopeServerTransaction::invokeMonoThr : internal error 1 !");
+ retc->_remove_ref();// restore the counter after _poa_for_key_waiter->reference_to_servant(kw)
+ SALOME::ByteVec *zeRet(retc->waitForMonoThr());
+ retc->enforcedRelease();
+ return zeRet;
+}
+
+SALOME::ByteVec *DataScopeServerTransaction::waitForAndKill(SALOME::KeyWaiter_ptr kw)
+{
+ PortableServer::ServantBase *ret(0);
+ try
+ {
+ ret=_poa_for_key_waiter->reference_to_servant(kw);// Warning ref cnt of ret has been incremented !
}
catch(...) { ret=0; }
KeyWaiter *retc(dynamic_cast<KeyWaiter *>(ret));
if(!retc)
throw Exception("DataScopeServerTransaction::invokeMonoThr : internal error 1 !");
- retc->_remove_ref();
- retc->waitForMonoThr();
+ retc->_remove_ref();// restore the counter after _poa_for_key_waiter->reference_to_servant(kw)
+ SALOME::ByteVec *zeRet(retc->waitForAndKill());
+ retc->enforcedRelease();
+ return zeRet;
}
void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& transactions)