DataScopeServer getMyDataScopeServer();
string getVarName();
string getScopeName();
+ long getRCValue();
};
interface PickelizedPyObjServer : BasicDataServer
interface DataServerManager;
+ interface DataScopeKiller
+ {
+ void shutdown();
+ };
+
interface DataScopeServerBase
{
void ping();
StringVec listVars();
boolean existVar(in string varName) raises (SALOME::SALOME_Exception);
void deleteVar(in string varName) raises (SALOME::SALOME_Exception);
- void shutdownIfNotHostedByDSM();
+ boolean shutdownIfNotHostedByDSM(out DataScopeKiller killer) raises (SALOME::SALOME_Exception);
ByteVec fetchSerializedContent(in string varName) raises (SALOME::SALOME_Exception);
SeqOfByteVec getAllKeysOfVarWithTypeDict(in string varName) raises (SALOME::SALOME_Exception);
};
BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception);
PickelizedPyObjRdOnlyServer createRdOnlyVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
PickelizedPyObjRdExtServer createRdExtVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
- //PickelizedPyObjRdWrServer createRdWrVar(in string typeName, in string varName) raises (SALOME::SALOME_Exception);
};
interface Transaction
{
};
+ interface TransactionRdWrAccess : Transaction
+ {
+ PickelizedPyObjRdWrServer getVar() raises (SALOME::SALOME_Exception);
+ };
+
typedef sequence<Transaction> ListOfTransaction;
interface KeyWaiter
interface DataScopeServerTransaction : DataScopeServerBase
{
+ string getAccessOfVar(in string varName) raises (SALOME::SALOME_Exception);
Transaction createRdOnlyVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
Transaction createRdExtVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
Transaction createRdWrVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
Transaction addKeyValueInVarErrorIfAlreadyExisting(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception);
void addKeyValueInVarErrorIfAlreadyExistingNow(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception);
Transaction removeKeyInVarErrorIfNotAlreadyExisting(in string varName, in ByteVec keyValue) raises (SALOME::SALOME_Exception);
+ TransactionRdWrAccess createWorkingVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
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);
enforcedRelease();
}
+CORBA::Long BasicDataServer::getRCValue()
+{
+ return getCounter();
+}
+
PortableServer::POA_var BasicDataServer::getPOA() const
{
return _father->getPOA();
void Register();
void UnRegister();
void Destroy();
+ CORBA::Long getRCValue();
public:
DataScopeServerBase *getFather() const { return _father; }
std::string getVarNameCpp() const { return _var_name; }
std::size_t DataScopeServerBase::COUNTER=0;
-DataScopeServerBase::DataScopeServerBase(CORBA::ORB_ptr orb, const std::string& scopeName):_globals(0),_locals(0),_pickler(0),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName)
+void DataScopeKiller::shutdown()
{
+ Py_Finalize();
+ _orb->shutdown(0);
}
-DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):_globals(0),_locals(0),_pickler(0),_name(other._name),_vars(other._vars)
+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)
{
}
// _globals is borrowed ref -> do nothing
Py_XDECREF(_locals);
Py_XDECREF(_pickler);
+ for(std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator it=_vars.begin();it!=_vars.end();it++)
+ {
+ BasicDataServer *obj((*it).second);
+ if(obj)
+ {
+ obj->decrRef();
+ }
+ }
}
/*!
}
std::size_t pos(std::distance(allNames.begin(),it));
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin());
- (*it0).first->UnRegister();
+ for(std::size_t ii=0;ii<pos;ii++,it0++);
+ (*it0).second->decrRef();
_vars.erase(it0);
}
-void DataScopeServerBase::shutdownIfNotHostedByDSM()
+CORBA::Boolean DataScopeServerBase::shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer)
{
SALOME_NamingService ns(_orb);
CORBA::Object_var obj(ns.Resolve(DataServerManager::NAME_IN_NS));
SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(obj));
if(CORBA::is_nil(dsm))
- return ;
+ throw Exception("Unable to reach in the NS the unique DataServerManager instance of the Session !");
// destroy ref in the naming service
std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name));
ns.Destroy_Name(fullScopeName.c_str());
catch(...) { ret=0; }
//
if(!ret)
- _orb->shutdown(0);
+ {
+ enforcedRelease();
+ killer=SALOME::DataScopeKiller::_duplicate(_killer);
+ return true;
+ }
else
{
+ ret->_remove_ref();
enforcedRelease();
+ killer=SALOME::DataScopeKiller::_duplicate(_killer);
+ return false;
}
}
return ret;
}
+void DataScopeServerBase::moveStatusOfVarFromRdWrToRdOnly(const std::string& varName)
+{
+ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName));
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it);
+ PickelizedPyObjRdWrServer *varc(dynamic_cast<PickelizedPyObjRdWrServer *>(p.second));
+ if(!varc)
+ throw Exception("DataScopeServerBase::moveStatusOfVarFromRdWrToRdOnly : var is not a RdWr !");
+ PyObject *pyobj(varc->getPyObj()); Py_XINCREF(pyobj);
+ PickelizedPyObjRdOnlyServer *newVar(new PickelizedPyObjRdOnlyServer(this,varName,pyobj));
+ CORBA::Object_var obj(newVar->activate());
+ SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj));
+ p.first=obj2; p.second=newVar;
+ varc->decrRef();
+}
+
+void DataScopeServerBase::moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName)
+{
+ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it(retrieveVarInternal4(varName));
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * >& p(*it);
+ PickelizedPyObjRdOnlyServer *varc(dynamic_cast<PickelizedPyObjRdOnlyServer *>(p.second));
+ if(!varc)
+ throw Exception("DataScopeServerBase::moveStatusOfVarFromRdOnlyToRdWr : var is not a RdWr !");
+ PyObject *pyobj(varc->getPyObj()); Py_XINCREF(pyobj);
+ PickelizedPyObjRdWrServer *newVar(new PickelizedPyObjRdWrServer(this,varName,pyobj));
+ CORBA::Object_var obj(newVar->activate());
+ SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj));
+ p.first=obj2; p.second=newVar;
+ varc->decrRef();
+}
+
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator DataScopeServerBase::retrieveVarInternal3(const std::string& varName) const
{
std::vector<std::string> allNames(getAllVarNames());
std::vector<std::string>::iterator it(std::find(allNames.begin(),allNames.end(),varName));
if(it==allNames.end())
{
- std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal : name \"" << varName << "\" does not exists ! Possibilities are :";
+ std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal3 : name \"" << varName << "\" does not exists ! Possibilities are :";
std::copy(allNames.begin(),allNames.end(),std::ostream_iterator<std::string>(oss,", "));
throw Exception(oss.str());
}
return it0;
}
+std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator DataScopeServerBase::retrieveVarInternal4(const std::string& varName)
+{
+ std::vector<std::string> allNames(getAllVarNames());
+ std::vector<std::string>::iterator it(std::find(allNames.begin(),allNames.end(),varName));
+ if(it==allNames.end())
+ {
+ std::ostringstream oss; oss << "DataScopeServerBase::retrieveVarInternal4 : name \"" << varName << "\" does not exists ! Possibilities are :";
+ std::copy(allNames.begin(),allNames.end(),std::ostream_iterator<std::string>(oss,", "));
+ throw Exception(oss.str());
+ }
+ std::size_t pos(std::distance(allNames.begin(),it));
+ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator it0(_vars.begin());
+ for(std::size_t i=0;i<pos;i++,it0++);
+ return it0;
+}
+
///////
-DataScopeServer::DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName):DataScopeServerBase(orb,scopeName)
+DataScopeServer::DataScopeServer(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):DataScopeServerBase(orb,killer,scopeName)
{
}
return SALOME::PickelizedPyObjRdExtServer::_narrow(ret);
}
-/*!
- * Called remotely -> to protect against throw
- */
SALOME::PickelizedPyObjRdWrServer_ptr DataScopeServer::createRdWrVar(const char *typeName, const char *varName)
{
std::string varNameCpp(varName),typeNameCpp(typeName);
////////
-DataScopeServerTransaction::DataScopeServerTransaction(CORBA::ORB_ptr orb, const std::string& scopeName):DataScopeServerBase(orb,scopeName)
+DataScopeServerTransaction::DataScopeServerTransaction(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):DataScopeServerBase(orb,killer,scopeName)
{
CORBA::Object_var obj(_orb->resolve_initial_references("RootPOA"));
PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
{
}
+char *DataScopeServerTransaction::getAccessOfVar(const char *varName)
+{
+ std::string varNameCpp(varName);
+ checkExistingVar(varNameCpp);
+ BasicDataServer *var(retrieveVarInternal2(varName));
+ if(!var)
+ throw Exception("DataScopeServerTransaction::getAccessOfVar : variable is NULL !");
+ PickelizedPyObjServer *varc(dynamic_cast<PickelizedPyObjServer *>(var));
+ if(!varc)
+ throw Exception("DataScopeServerTransaction::getAccessOfVar : variable is not of type PickelizedPyObjServer !");
+ std::string ret(varc->getAccessStr());
+ return CORBA::string_dup(ret.c_str());
+}
+
void DataScopeServerTransaction::createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
{
checkNotAlreadyExistingVar(varName);
return SALOME::Transaction::_narrow(obj);
}
+SALOME::TransactionRdWrAccess_ptr DataScopeServerTransaction::createWorkingVarTransac(const char *varName, const SALOME::ByteVec& constValue)
+{
+ std::string varNameCpp(varName);
+ checkNotAlreadyExistingVar(varName);
+ PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,varNameCpp,constValue));
+ CORBA::Object_var obj(tmp->activate());
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(obj),tmp);
+ _vars.push_back(p);
+ //
+ TransactionMorphRdWrIntoRdOnly *ret(new TransactionMorphRdWrIntoRdOnly(this,varName));
+ CORBA::Object_var obj2(ret->activate());
+ return SALOME::TransactionRdWrAccess::_narrow(obj2);
+}
+
SALOME::KeyWaiter_ptr DataScopeServerTransaction::waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal)
{
PickelizedPyObjServer *pickelObj(checkVarExistingAndDict(varName));
namespace SALOMESDS
{
+ class SALOMESDS_EXPORT DataScopeKiller : public POA_SALOME::DataScopeKiller
+ {
+ public:
+ DataScopeKiller(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb)) { }
+ void shutdown();
+ private:
+ CORBA::ORB_var _orb;
+ };
+
class KeyWaiter;
class PickelizedPyObjServer;
class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder
{
public:
- DataScopeServerBase(CORBA::ORB_ptr orb, const std::string& scopeName);
+ DataScopeServerBase(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
DataScopeServerBase(const DataScopeServerBase& other);
void ping();
char *getScopeName();
SALOME::StringVec *listVars();
CORBA::Boolean existVar(const char *varName);
SALOME::BasicDataServer_ptr retrieveVarInternal(const char *varName);
- BasicDataServer *retrieveVarInternal2(const std::string& varName);
void deleteVar(const char *varName);
- void shutdownIfNotHostedByDSM();
+ CORBA::Boolean shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer);
SALOME::ByteVec *fetchSerializedContent(const char *varName);
SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName);
~DataScopeServerBase();
public:
+ BasicDataServer *retrieveVarInternal2(const std::string& varName);
void initializePython(int argc, char *argv[]);
void registerToSalomePiDict() const;
void setPOA(PortableServer::POA_var poa);
void checkNotAlreadyExistingVar(const std::string& varName) const;
void checkExistingVar(const std::string& varName) const;
PickelizedPyObjServer *checkVarExistingAndDict(const std::string& varName);
+ public:
+ void moveStatusOfVarFromRdWrToRdOnly(const std::string& varName);
+ void moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName);
protected:
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const;
+ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal4(const std::string& varName);
protected:
PyObject *_globals;
PyObject *_locals;
CORBA::ORB_var _orb;
std::string _name;
std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars;
+ SALOME::DataScopeKiller_var _killer;
static std::size_t COUNTER;
};
class SALOMESDS_EXPORT DataScopeServer : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServer
{
public:
- DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName);
+ DataScopeServer(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
DataScopeServer(const DataScopeServer& other);
SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); }
SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction
{
public://not remotely callable
- DataScopeServerTransaction(CORBA::ORB_ptr orb, const std::string& scopeName);
+ DataScopeServerTransaction(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
DataScopeServerTransaction(const DataScopeServerTransaction& other);
~DataScopeServerTransaction();
void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
void notifyKey(PyObject *keyObj, PyObject *valueObj);
SALOME::ByteVec *waitForMonoThrRev(SALOME::KeyWaiter_ptr kw);
public://remotely callable
+ char *getAccessOfVar(const char *varName);
SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue);
SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue);
SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue);
SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
void addKeyValueInVarErrorIfAlreadyExistingNow(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
SALOME::Transaction_ptr removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const SALOME::ByteVec& key);
+ SALOME::TransactionRdWrAccess_ptr createWorkingVarTransac(const char *varName, const SALOME::ByteVec& constValue);
SALOME::KeyWaiter_ptr waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal);
SALOME::KeyWaiter_ptr waitForKeyInVarAndKillIt(const char *varName, const SALOME::ByteVec& keyVal, SALOME::Transaction_out transac);
void atomicApply(const SALOME::ListOfTransaction& transactions);
DataServerManager::DataServerManager(int argc, char *argv[], CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_orb(CORBA::ORB::_duplicate(orb))
{
- DataScopeServer *dftScope(new DataScopeServer(orb,DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM
+ DataScopeServer *dftScope(new DataScopeServer(orb,SALOME::DataScopeKiller::_nil(),DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM
PortableServer::POAManager_var pman(poa->the_POAManager());
CORBA::PolicyList policies;
policies.length(1);
void DataServerManager::removeDataScope(const char *scopeName)
{
SALOME::DataScopeServerBase_var scs(getScopePtrGivenName(scopeName));
- scs->shutdownIfNotHostedByDSM();
+ SALOME::DataScopeKiller_ptr killer;
+ if(scs->shutdownIfNotHostedByDSM(killer))
+ killer->shutdown();
+ CORBA::release(killer);
}
void DataServerManager::cleanScopesInNS()
{
std::vector<std::string> scopeNames(listOfScopesCpp());
for(std::vector<std::string>::const_iterator it=scopeNames.begin();it!=scopeNames.end();it++)
- getScopePtrGivenName(*it)->shutdownIfNotHostedByDSM();
+ {
+ SALOME::DataScopeServerBase_var scope(getScopePtrGivenName(*it));
+ SALOME::DataScopeKiller_ptr killer;
+ if(scope->shutdownIfNotHostedByDSM(killer))
+ killer->shutdown();
+ CORBA::release(killer);
+ }
}
std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& scopeName)
using namespace SALOMESDS;
-PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+const char PickelizedPyObjRdExtServer::ACCESS_REPR[]="RdExt";
+
+PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServerModifiable(father,varName,value)
{
}
//! obj is consumed
-PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServerModifiable(father,varName,obj)
{
}
throw Exception("PickelizedPyObjRdExtServer::checkDictSetitemRdExtness : specified key of __setitem__ already exists ! RdExt property is not applied !");
}
}
+
+std::string PickelizedPyObjRdExtServer::getAccessStr() const
+{
+ return std::string(ACCESS_REPR);
+}
namespace SALOMESDS
{
- class PickelizedPyObjRdExtServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdExtServer
+ class PickelizedPyObjRdExtServer : public PickelizedPyObjServerModifiable, public virtual POA_SALOME::PickelizedPyObjRdExtServer
{
public:
PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
~PickelizedPyObjRdExtServer();
SALOME::PickelizedPyObjRdExtServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
+ public:
+ std::string getAccessStr() const;
private:
void checkRdExtnessOf(const std::string& methodName, PyObject *argsPy);
void checkListRdExtnessOf(const std::string& methodName, PyObject *argsPy);
void checkDictRdExtnessOf(const std::string& methodName, PyObject *argsPy);
void checkDictSetitemRdExtness(PyObject *argsPy);
+ public:
+ static const char ACCESS_REPR[];
};
}
using namespace SALOMESDS;
+const char PickelizedPyObjRdOnlyServer::ACCESS_REPR[]="RdOnly";
+
PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
{
}
PickelizedPyObjRdOnlyServer::~PickelizedPyObjRdOnlyServer()
{
}
+
+void PickelizedPyObjRdOnlyServer::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value)
+{
+ throw Exception("PickelizedPyObjRdOnlyServer::addKeyValueErrorIfAlreadyExisting : incompatible with RdOnly !");
+}
+
+std::string PickelizedPyObjRdOnlyServer::getAccessStr() const
+{
+ return std::string(ACCESS_REPR);
+}
PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
~PickelizedPyObjRdOnlyServer();
+ public:
+ void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value);
+ std::string getAccessStr() const;
+ public:
+ static const char ACCESS_REPR[];
};
}
using namespace SALOMESDS;
-PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
+const char PickelizedPyObjRdWrServer::ACCESS_REPR[]="RdWr";
+
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServerModifiable(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
{
}
-PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServerModifiable(father,varName,value)
{
}
//! obj is consumed
-PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServerModifiable(father,varName,obj)
{
}
setSerializedContentInternal(newValue);
}
-/*!
- * Called remotely -> to protect against throw
- */
SALOME::PickelizedPyObjRdWrServer_ptr PickelizedPyObjRdWrServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
{
if(!_self)
CORBA::Object_var obj(poa->id_to_reference(id));
return SALOME::PickelizedPyObjRdWrServer::_narrow(obj);
}
+
+void PickelizedPyObjRdWrServer::addKeyValueHard(PyObject *key, PyObject *value)
+{
+ bool isOK(PyDict_SetItem(_self,key,value)==0);
+ if(!isOK)
+ throw Exception("PickelizedPyObjRdWrServer::addKeyValueHard : error when trying to add key,value to dict !");
+}
+
+void PickelizedPyObjRdWrServer::removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key)
+{
+ checkKeyPresent(key);
+ if(PyDict_DelItem(_self,key)!=0)
+ throw Exception("PickelizedPyObjRdWrServer::removeKeyInVarErrorIfNotAlreadyExisting : error during deletion of key in dict !");
+}
+
+std::string PickelizedPyObjRdWrServer::getAccessStr() const
+{
+ return std::string(ACCESS_REPR);
+}
namespace SALOMESDS
{
- class PickelizedPyObjRdWrServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdWrServer
+ class PickelizedPyObjRdWrServer : public PickelizedPyObjServerModifiable, public virtual POA_SALOME::PickelizedPyObjRdWrServer
{
public:
PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName);
~PickelizedPyObjRdWrServer();
void setSerializedContent(const SALOME::ByteVec& newValue);
SALOME::PickelizedPyObjRdWrServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
+ public:
+ std::string getAccessStr() const;
+ void addKeyValueHard(PyObject *key, PyObject *value);
+ void removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key);
+ public:
+ static const char ACCESS_REPR[];
};
}
void PickelizedPyObjServer::addKeyValueHard(PyObject *key, PyObject *value)
{
- bool isOK(PyDict_SetItem(_self,key,value)==0);
- if(!isOK)
- throw Exception("PickelizedPyObjServer::addKeyValueHard : error when trying to add key,value to dict !");
-}
-
-void PickelizedPyObjServer::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value)
-{
- checkKeyNotAlreadyPresent(key);
- bool isOK(PyDict_SetItem(_self,key,value)==0);
- if(!isOK)
- throw Exception("PickelizedPyObjServer::addKeyValueErrorIfAlreadyExisting : error when trying to add key,value to dict !");
+ std::ostringstream oss; oss << "PickelizedPyObjServer::addKeyValueHard : var \"" << getVarNameCpp() << "\" is not permitted to alter its value !";
+ throw Exception(oss.str());
}
void PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key)
{
- checkKeyPresent(key);
- if(PyDict_DelItem(_self,key)!=0)
- throw Exception("PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting : error during deletion of key in dict !");
+ std::ostringstream oss; oss << "PickelizedPyObjServer::removeKeyInVarErrorIfNotAlreadyExisting : var \"" << getVarNameCpp() << "\" is not permitted to alter its value !";
+ throw Exception(oss.str());
}
void PickelizedPyObjServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
}
Py_XDECREF(retPy);
}
+
+PickelizedPyObjServerModifiable::PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+{
+}
+
+PickelizedPyObjServerModifiable::PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+{
+}
+
+void PickelizedPyObjServerModifiable::addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value)
+{
+ checkKeyNotAlreadyPresent(key);
+ bool isOK(PyDict_SetItem(_self,key,value)==0);
+ if(!isOK)
+ throw Exception("PickelizedPyObjServerModifiable::addKeyValueErrorIfAlreadyExisting : error when trying to add key,value to dict !");
+}
public:
PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
- ~PickelizedPyObjServer();
+ virtual ~PickelizedPyObjServer();
void setSerializedContent(const SALOME::ByteVec& newValue);
SALOME::ByteVec *fetchSerializedContent();
public:
bool isDict();
void checkKeyNotAlreadyPresent(PyObject *key);
void checkKeyPresent(PyObject *key);
- void addKeyValueHard(PyObject *key, PyObject *value);
- void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value);
- void removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key);
PyObject *getPyObj() const { return _self; }
+ public:
+ virtual void addKeyValueHard(PyObject *key, PyObject *value);
+ virtual void removeKeyInVarErrorIfNotAlreadyExisting(PyObject *key);
+ virtual void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value) = 0;
+ virtual std::string getAccessStr() const = 0;
public:
static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
static void FromCppToByteSeq(const std::string& strToBeConv, SALOME::ByteVec& ret);
PyObject *_self;
PortableServer::POA_var _poa;
};
+
+ class PickelizedPyObjServerModifiable : public PickelizedPyObjServer
+ {
+ public:
+ PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
+ PickelizedPyObjServerModifiable(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
+ void addKeyValueErrorIfAlreadyExisting(PyObject *key, PyObject *value);
+ };
}
#endif
public:
void incrRef() const;
bool decrRef() const;
+ int getCounter() const { return _cnt; }
protected:
RefCountServ();
RefCountServ(const RefCountServ& other);
#include "SALOMESDS_Transaction.hxx"
#include "SALOMESDS_Exception.hxx"
#include "SALOMESDS_PickelizedPyObjServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
#include <sstream>
}
/*!
- TODO : To be implemented.
+ * no implementation it is not a bug !
*/
void TransactionVarCreate::notify()
{
}
/*!
- * not implementation it is not a bug !
+ * no implementation it is not a bug !
*/
void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::notify()
{
{
Py_XDECREF(_key);
}
+
+TransactionMorphRdWrIntoRdOnly::TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName):Transaction(dsct,varName)
+{
+}
+
+SALOME::PickelizedPyObjRdWrServer_ptr TransactionMorphRdWrIntoRdOnly::getVar()
+{
+ SALOME::BasicDataServer_var obj(_dsct->retrieveVarInternal(_var_name.c_str()));
+ SALOME::PickelizedPyObjRdWrServer_ptr ret(SALOME::PickelizedPyObjRdWrServer::_narrow(obj));
+ if(CORBA::is_nil(ret))
+ {
+ std::ostringstream oss; oss << "TransactionMorphRdWrIntoRdOnly::getVar : var \"" << _var_name << "\" has not expected PickelizedPyObjRdWrServer type !";
+ throw Exception(oss.str());
+ }
+ return ret;
+}
+
+void TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure()
+{
+ BasicDataServer *var(_dsct->retrieveVarInternal2(_var_name));
+ if(!var)
+ throw Exception("TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure : Returned var is NULL !");
+ PickelizedPyObjRdWrServer *varc(dynamic_cast<PickelizedPyObjRdWrServer *>(var));
+ if(!varc)
+ throw Exception("TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure : Returned var has not expected type !");
+}
+
+void TransactionMorphRdWrIntoRdOnly::perform()
+{
+ _dsct->moveStatusOfVarFromRdWrToRdOnly(_var_name);
+}
+
+void TransactionMorphRdWrIntoRdOnly::rollBack()
+{
+ _dsct->moveStatusOfVarFromRdOnlyToRdWr(_var_name);
+}
+
+/*!
+ * no implementation it is not a bug !
+ */
+void TransactionMorphRdWrIntoRdOnly::notify()
+{
+}
namespace SALOMESDS
{
class PickelizedPyObjServer;
+ class PickelizedPyObjRdWrServer;
+ class PickelizedPyObjRdExtServer;
class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction, public POAHolder
{
private:
PyObject *_key;
};
+
+ class TransactionMorphRdWrIntoRdOnly : public Transaction, public virtual POA_SALOME::TransactionRdWrAccess
+ {
+ public:
+ TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName);
+ public:
+ SALOME::PickelizedPyObjRdWrServer_ptr getVar();
+ public:
+ void prepareRollBackInCaseOfFailure();
+ void perform();
+ void rollBack();
+ void notify();
+ };
}
#endif
PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
PortableServer::POAManager_var mgr(poa->the_POAManager());
mgr->activate();
+ //
+ SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb));
+ SALOME::DataScopeKiller_var killerObj(killer->_this());
+ //
SALOMESDS::DataScopeServerBase *server(0);
if(!isTransac)
- server=new SALOMESDS::DataScopeServer(orb,scopeName);
+ server=new SALOMESDS::DataScopeServer(orb,killerObj,scopeName);
else
- server=new SALOMESDS::DataScopeServerTransaction(orb,scopeName);
+ server=new SALOMESDS::DataScopeServerTransaction(orb,killerObj,scopeName);
//
CORBA::PolicyList policies;
policies.length(1);
server->registerInNS(serverPtr);
//
orb->run();
- server->_remove_ref();
+ delete killer;
return 0;
}
@classmethod
def IsOK(cls,varPtr):
- return isinstance(varPtr,SALOME._objref_PickelizedPyObjRdExtServer)
+ return isinstance(varPtr,SALOME._objref_PickelizedPyObjRdExtServer) or isinstance(varPtr,SALOME._objref_PickelizedPyObjRdWrServer)
pass
class InvokatorImpossibleStyle(InvokatorStyle):
dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
self.assertTrue(isCreated)
#
- t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+ t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]}))
dss.atomicApply([t0])
#
+ self.assertEqual(dss.getAccessOfVar(varName),"RdWr")
+ #
t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
dss.atomicApply([t1])
#
t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
dss.atomicApply([t0])
#
+ self.assertEqual(dss.getAccessOfVar(varName),"RdExt")
+ #
self.assertRaises(SALOME.SALOME_Exception,dss.addKeyValueInVarErrorIfAlreadyExisting,varName,obj2Str("ab"),obj2Str([7,8,9,10]))#raises because ab is already a key !
t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
dss.atomicApply([t1])
dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
self.assertTrue(isCreated)
#
- t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+ t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]}))
dss.atomicApply([t0])
#
t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
self.assertTrue(isCreated)
#
- t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+ t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]}))
dss.atomicApply([t0])
#
t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)]
self.assertEqual(keys,['ab','cd'])
+ def testTransaction6(self):
+ """ Test to test RdWr global vars with transaction"""
+ scopeName="Scope1"
+ varName="a"
+ dsm=salome.naming_service.Resolve("/DataServerManager")
+ dsm.cleanScopesInNS()
+ if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+ dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+ self.assertTrue(isCreated)
+ #
+ t0=dss.createWorkingVarTransac(varName,obj2Str({}))
+ a=SalomeSDSClt.GetHandlerFromRef(t0.getVar())
+ self.assertEqual(dss.getAccessOfVar(varName),"RdWr")
+ # play
+ a["ab"]=4
+ self.assertEqual(a.local_copy(),{"ab":4})
+ a["cd"]=[5]
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
+ a["cd"].append(77)
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
+ a.__setitem__("ef",["a","bb"])
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
+ a["ef"].append("ccc")
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
+ a["gh"]=a
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
+ a["gh"]["cd"].append(99) ; a["cd"].append(88)
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
+ # WARNING here not problem to overwrite
+ a["gh"]=7
+ self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":7})
+ # end of play
+ self.assertTrue(isinstance(a,SalomeSDSClt.Dict))
+ self.assertTrue(isinstance(a,SalomeSDSClt.WrappedType))# important for EEM
+ # commit : RdWr->RdOnly
+ dss.atomicApply([t0])
+ #
+ self.assertEqual(dss.getAccessOfVar(varName),"RdOnly") # after atomicApply the var is readOnly. Impossible to change its value !
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":7})
+ dsm.cleanScopesInNS()
+ del a # very important kill Ref before removingDataScope...
+ if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+ pass
+
def setUp(self):
salome.salome_init()
pass