-// 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"
{
}
-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)
{
}
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));
if(!retc)
throw Exception("DataScopeServerTransaction::invokeMonoThr : internal error 1 !");
retc->_remove_ref();
- retc->waitForMonoThr();
+ return retc->waitForMonoThr();
}
void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& transactions)