interface DataScopeServerTransaction : DataScopeServerBase
{
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);
void atomicApply(in ListOfTransaction transactions) raises (SALOME::SALOME_Exception);
};
int BasicDataServer::POA_CNT=0;
-BasicDataServer::BasicDataServer(DataScopeServer *father, const std::string& varName):_father(father),_var_name(varName)
+BasicDataServer::BasicDataServer(DataScopeServerBase *father, const std::string& varName):_father(father),_var_name(varName)
{
PortableServer::POA_var poa(_father->getPOA());
PortableServer::POAManager_var pman(poa->the_POAManager());
namespace SALOMESDS
{
- class DataScopeServer;
+ class DataScopeServerBase;
class BasicDataServer : public RefCountServ, public virtual POA_SALOME::BasicDataServer
{
public:
- BasicDataServer(DataScopeServer *father, const std::string& varName);
+ BasicDataServer(DataScopeServerBase *father, const std::string& varName);
SALOME::DataScopeServer_ptr getMyDataScopeServer();
char *getVarName();
char *getScopeName();
protected:
PortableServer::POA_var getPOA() const { return _poa; }
protected:
- DataScopeServer *_father;
+ DataScopeServerBase *_father;
private:
std::string _var_name;
PortableServer::POA_var _poa;
{
}
+void DataScopeServerTransaction::createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
+{
+ checkNotAlreadyExistingVar(varName);
+ PickelizedPyObjRdOnlyServer *tmp(new PickelizedPyObjRdOnlyServer(this,varName,constValue));
+ CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
+ _vars.push_back(p);
+}
+
+void DataScopeServerTransaction::createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
+{
+ checkNotAlreadyExistingVar(varName);
+ PickelizedPyObjRdExtServer *tmp(new PickelizedPyObjRdExtServer(this,varName,constValue));
+ CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
+ 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);
+ PickelizedPyObjRdWrServer *tmp(new PickelizedPyObjRdWrServer(this,varName,constValue));
+ CORBA::Object_var ret(activateWithDedicatedPOA(tmp));
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
+ _vars.push_back(p);
+}
+
SALOME::Transaction_ptr DataScopeServerTransaction::createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue)
{
- TransactionRdOnlyVarCreate *ret(new TransactionRdOnlyVarCreate(varName,constValue));
+ TransactionRdOnlyVarCreate *ret(new TransactionRdOnlyVarCreate(this,varName,constValue));
+ ret->checkNotAlreadyExisting();
+ PortableServer::ObjectId_var id(_poa->activate_object(ret));
+ CORBA::Object_var obj(_poa->id_to_reference(id));
+ return SALOME::Transaction::_narrow(obj);
+}
+
+SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue)
+{
+ TransactionRdExtVarCreate *ret(new TransactionRdExtVarCreate(this,varName,constValue));
+ ret->checkNotAlreadyExisting();
+ PortableServer::ObjectId_var id(_poa->activate_object(ret));
+ CORBA::Object_var obj(_poa->id_to_reference(id));
+ return SALOME::Transaction::_narrow(obj);
+}
+
+SALOME::Transaction_ptr DataScopeServerTransaction::createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue)
+{
+ TransactionRdWrVarCreate *ret(new TransactionRdWrVarCreate(this,varName,constValue));
+ ret->checkNotAlreadyExisting();
PortableServer::ObjectId_var id(_poa->activate_object(ret));
CORBA::Object_var obj(_poa->id_to_reference(id));
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"); _must_rollback=mustRollback; t->prepareRollBackInCaseOfFailure(); }
+ void operate() { _ptr->perform(); }
+ ~TrustTransaction() { if(!_ptr) return ; if(*_must_rollback) _ptr->rollBack(); }
+private:
+ bool *_must_rollback;
+ Transaction *_ptr;
+};
+
void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& transactions)
{
std::size_t sz(transactions.length());
transactionsCpp[i]=elt;
transactionsCpp[i].setHolder(this);
}
- for(std::size_t i=0;i<sz;i++)
- transactionsCpp[i]->prepareRollBackInCaseOfFailure();
+ {// important do not merge loops !
+ std::vector<TrustTransaction> transactions2(sz);
+ bool mustRollback(true);
+ for(std::size_t i=0;i<sz;i++)
+ transactions2[i].setTransaction(transactionsCpp[i],&mustRollback);
+ for(std::size_t i=0;i<sz;i++)
+ transactions2[i].operate();
+ mustRollback=false;
+ }
}
DataScopeServerTransaction::~DataScopeServerTransaction()
CORBA::Boolean existVar(const char *varName);
SALOME::BasicDataServer_ptr retrieveVar(const char *varName);
void deleteVar(const char *varName);
- SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
- SALOME::PickelizedPyObjRdExtServer_ptr createRdExtVar(const char *varName, const SALOME::ByteVec& constValue);
- SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName);
void shutdownIfNotHostedByDSM();
~DataScopeServerBase();
public:
PyObject *getPickler() const { return _pickler; }
PortableServer::POA_var getPOA() const { return _poa; }
CORBA::ORB_var getORB() { return _orb; }
+ std::string getScopeNameCpp() const { return _name; }
static std::string BuildTmpVarNameFrom(const std::string& varName);
- protected:
+ public:
std::vector< std::string> getAllVarNames() const;
CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds);
void checkNotAlreadyExistingVar(const std::string& varName);
class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction
{
- public:
+ public://not remotely callable
DataScopeServerTransaction(CORBA::ORB_ptr orb, const std::string& scopeName);
DataScopeServerTransaction(const DataScopeServerTransaction& other);
+ ~DataScopeServerTransaction();
+ void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
+ void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
+ void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
+ public://remotely callable
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);
void atomicApply(const SALOME::ListOfTransaction& transactions);
- ~DataScopeServerTransaction();
};
- /*SALOME::Transaction_ptr createRdOnlyVar(const char *varName, const char *scopeName, const SALOME::ByteVec& constValue);
- SALOME::Transaction_ptr createRdExtVar(const char *varName, const char *scopeName, const SALOME::ByteVec& constValue);
- SALOME::Transaction_ptr createRdWrVar(const char *varName, const char *scopeName, const SALOME::ByteVec& constValue);
+ /*
SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const char *scopeName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const char *scopeName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
SALOME::Transaction_ptr removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const char *scopeName, const SALOME::ByteVec& key);
using namespace SALOMESDS;
-PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
{
}
//! obj is consumed
-PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+PickelizedPyObjRdExtServer::PickelizedPyObjRdExtServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
{
}
class PickelizedPyObjRdExtServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdExtServer
{
public:
- PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
- PickelizedPyObjRdExtServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+ 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);
private:
using namespace SALOMESDS;
-PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
+PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):PickelizedPyObjServer(father,varName,value)
{
}
-PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+PickelizedPyObjRdOnlyServer::PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
{
}
class PickelizedPyObjRdOnlyServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdOnlyServer
{
public:
- PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
- PickelizedPyObjRdOnlyServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+ PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
+ PickelizedPyObjRdOnlyServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
~PickelizedPyObjRdOnlyServer();
};
}
using namespace SALOMESDS;
-PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName):PickelizedPyObjServer(father,varName,CreateDftObjFromType(father->getGlobals(),typeName))
{
}
-PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *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):PickelizedPyObjServer(father,varName,value)
{
}
//! obj is consumed
-PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
+PickelizedPyObjRdWrServer::PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):PickelizedPyObjServer(father,varName,obj)
{
}
class PickelizedPyObjRdWrServer : public PickelizedPyObjServer, public virtual POA_SALOME::PickelizedPyObjRdWrServer
{
public:
- PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& typeName, const std::string& varName);
- PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
- PickelizedPyObjRdWrServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+ PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& typeName, const std::string& varName);
+ PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
+ PickelizedPyObjRdWrServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
~PickelizedPyObjRdWrServer();
void setSerializedContent(const SALOME::ByteVec& newValue);
SALOME::PickelizedPyObjRdWrServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
using namespace SALOMESDS;
-PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value):BasicDataServer(father,varName),_self(0)
+PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value):BasicDataServer(father,varName),_self(0)
{
setSerializedContentInternal(value);
}
//! obj is consumed
-PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(0)
+PickelizedPyObjServer::PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj):BasicDataServer(father,varName),_self(0)
{
setNewPyObj(obj);
}
class PickelizedPyObjServer : public BasicDataServer, public virtual POA_SALOME::PickelizedPyObjServer
{
public:
- PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, const SALOME::ByteVec& value);
- PickelizedPyObjServer(DataScopeServer *father, const std::string& varName, PyObject *obj);
+ PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
+ PickelizedPyObjServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
~PickelizedPyObjServer();
void setSerializedContent(const SALOME::ByteVec& newValue);
SALOME::ByteVec *fetchSerializedContent();
// Author : Anthony GEAY (EDF R&D)
#include "SALOMESDS_Transaction.hxx"
-#include "SALOMESDS_DataServerManager.hxx"
#include "SALOMESDS_Exception.hxx"
#include <sstream>
buf[i]=bsToBeConv[i];
}
-TransactionVarCreate::TransactionVarCreate(const std::string& varName, const SALOME::ByteVec& constValue):Transaction(varName)
+void Transaction::FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret)
+{
+ std::size_t sz(bsToBeConv.size());
+ ret.length(sz);
+ for(std::size_t i=0;i<sz;i++)
+ ret[i]=bsToBeConv[i];
+}
+
+TransactionVarCreate::TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):Transaction(dsct,varName)
{
FromByteSeqToVB(constValue,_data);
}
void TransactionVarCreate::prepareRollBackInCaseOfFailure()
{//nothing it is not a bug
+ checkNotAlreadyExisting();
+}
+
+void TransactionVarCreate::rollBack()
+{
+ if(_dsct->existVar(_var_name.c_str()))
+ _dsct->deleteVar(_var_name.c_str());
+}
+
+void TransactionRdOnlyVarCreate::perform()
+{
+ SALOME::ByteVec data2;
+ FromVBToByteSeq(_data,data2);
+ _dsct->createRdOnlyVarInternal(_var_name,data2);
+}
+
+void TransactionRdExtVarCreate::perform()
+{
+ SALOME::ByteVec data2;
+ FromVBToByteSeq(_data,data2);
+ _dsct->createRdExtVarInternal(_var_name,data2);
+}
+
+void TransactionRdWrVarCreate::perform()
+{
+ SALOME::ByteVec data2;
+ FromVBToByteSeq(_data,data2);
+ _dsct->createRdWrVarInternal(_var_name,data2);
}
#include CORBA_SERVER_HEADER(SALOME_SDS)
#include "SALOMESDS_Defines.hxx"
+#include "SALOMESDS_Exception.hxx"
+#include "SALOMESDS_DataServerManager.hxx"
#include <string>
#include <vector>
class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction
{
public:
- Transaction(const std::string& varName):_var_name(varName) { }
+ Transaction(DataScopeServerTransaction *dsct, const std::string& varName):_dsct(dsct),_var_name(varName) { if(!_dsct) throw Exception("Transaction constructor error !"); }
std::string getVarName() const { return _var_name; }
virtual void prepareRollBackInCaseOfFailure() = 0;
+ virtual void perform() = 0;
+ virtual void rollBack() = 0;
public:
static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret);
+ static void FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret);
protected:
+ DataScopeServerTransaction *_dsct;
std::string _var_name;
};
class TransactionVarCreate : public Transaction
{
public:
- TransactionVarCreate(const std::string& varName, const SALOME::ByteVec& constValue);
+ TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue);
+ void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); }
void prepareRollBackInCaseOfFailure();
+ void rollBack();
protected:
std::vector<unsigned char> _data;
};
class TransactionRdOnlyVarCreate : public TransactionVarCreate
{
public:
- TransactionRdOnlyVarCreate(const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(varName,constValue) { }
+ TransactionRdOnlyVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
+ void perform();
+ };
+
+ class TransactionRdExtVarCreate : public TransactionVarCreate
+ {
+ public:
+ TransactionRdExtVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
+ void perform();
+ };
+
+ class TransactionRdWrVarCreate : public TransactionVarCreate
+ {
+ public:
+ TransactionRdWrVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
+ void perform();
};
}