void fetchAndGetAccessOfVar(in string varName, out string access, out ByteVec data) 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 createRdExtVarFreeStyleTransac(in string varName, in ByteVec constValue, in ByteVec sha1) raises (SALOME::SALOME_Exception);
Transaction createRdExtInitVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
Transaction createRdWrVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception);
Transaction addKeyValueInVarHard(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception);
SALOMESDS_PickelizedPyObjRdWrServer.cxx
SALOMESDS_Transaction.cxx
SALOMESDS_KeyWaiter.cxx
+ SALOMESDS_Sha1Keeper.cxx
)
ADD_LIBRARY(SalomeSDS ${SalomeSDS_SOURCES})
return ret;
}
-void DataScopeServerBase::checkNotAlreadyExistingVar(const std::string& varName) const
+bool DataScopeServerBase::isExistingVar(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())
+ return it!=allNames.end();
+}
+
+void DataScopeServerBase::checkNotAlreadyExistingVar(const std::string& varName) const
+{
+ if(isExistingVar(varName))
{
std::ostringstream oss; oss << "DataScopeServerBase::checkNotAlreadyExistingVar : name \"" << varName << "\" already exists !";
throw Exception(oss.str());
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));
+ PickelizedPyObjRdExtInitServer *newVar(varc0->buildInitInstanceFrom(varName));
newVar->incrNbClients();
CORBA::Object_var obj(newVar->activate());
SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj));
{
if(varc0->decrNbClients())
{
- PyObject *pyobj(varc0->getPyObj()); Py_XINCREF(pyobj);
- PickelizedPyObjRdExtServer *newVar(new PickelizedPyObjRdExtServer(this,varName,pyobj));
+ PickelizedPyObjRdExtServer *newVar(varc0->buildStdInstanceFrom(varName));
CORBA::Object_var obj(newVar->activate());
SALOME::BasicDataServer_var obj2(SALOME::BasicDataServer::_narrow(obj));
p.first=obj2; p.second=newVar;
_vars.push_back(p);
}
+void DataScopeServerTransaction::createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::vector<unsigned char>&& sha1)
+{
+ if(!isExistingVar(varName))
+ {
+ PickelizedPyObjRdExtFreeStyleServer *tmp(new PickelizedPyObjRdExtFreeStyleServer(this,varName,constValue,std::move(sha1)));
+ CORBA::Object_var ret(tmp->activate());
+ std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp);
+ _vars.push_back(p);
+ }
+ else
+ {
+ BasicDataServer *ds(retrieveVarInternal2(varName));
+ if(!ds)
+ {
+ std::ostringstream oss;
+ oss << "DataScopeServerTransaction::createRdExtVarFreeStyleInternal : internal error 1 for varname \"" << varName << "\"!";
+ throw Exception(oss.str());
+ }
+ Sha1Keeper *ds2(dynamic_cast<Sha1Keeper *>(ds));
+ if(!ds2)
+ {
+ std::ostringstream oss;
+ oss << "DataScopeServerTransaction::createRdExtVarFreeStyleInternal : varname \"" << varName << "\" already exists with a non RdExtFreeStyle type !";
+ throw Exception(oss.str());
+ }
+ ds2->checkSha1(varName,sha1);
+ }
+}
+
void DataScopeServerTransaction::createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue)
{
checkNotAlreadyExistingVar(varName);
return SALOME::Transaction::_narrow(obj);
}
+SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1)
+{// no check on varName done here. Will be done on perform
+ TransactionRdExtVarFreeStyleCreate *ret(new TransactionRdExtVarFreeStyleCreate(this,varName,constValue,sha1));
+ CORBA::Object_var obj(ret->activate());
+ return SALOME::Transaction::_narrow(obj);
+}
+
SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue)
{
checkNotAlreadyExistingVar(varName);
static std::string BuildTmpVarNameFrom(const std::string& varName);
public:
std::vector< std::string> getAllVarNames() const;
+ bool isExistingVar(const std::string& varName) const;
void checkNotAlreadyExistingVar(const std::string& varName) const;
void checkExistingVar(const std::string& varName) const;
PickelizedPyObjServer *checkVarExistingAndDict(const std::string& varName);
~DataScopeServerTransaction();
void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
+ void createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::vector<unsigned char>&& sha1);
void createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
PortableServer::POA_var getPOA4KeyWaiter() const { return _poa_for_key_waiter; }
void fetchAndGetAccessOfVar(const char *varName, CORBA::String_out access, SALOME::ByteVec_out data);
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 createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1);
SALOME::Transaction_ptr createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue);
SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue);
SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
// Author : Anthony GEAY (EDF R&D)
#include "SALOMESDS_PickelizedPyObjRdExtInitServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
#include "SALOMESDS_DataScopeServer.hxx"
#include "SALOMESDS_Exception.hxx"
Py_XDECREF(_self_deep_copy);
}
+PickelizedPyObjRdExtServer *PickelizedPyObjRdExtInitServer::buildStdInstanceFrom(const std::string& varName)
+{
+ PyObject *pyobj(this->getPyObj()); Py_XINCREF(pyobj);
+ return new PickelizedPyObjRdExtServer(getFather(),varName,pyobj);
+}
+
std::string PickelizedPyObjRdExtInitServer::getAccessStr() const
{
return std::string(ACCESS_REPR);
Py_XDECREF(mod);
return ret;
}
+
+PickelizedPyObjRdExtServer *PickelizedPyObjRdExtInitFreeStyleServer::buildStdInstanceFrom(const std::string& varName)
+{
+ PyObject *pyobj(this->getPyObj()); Py_XINCREF(pyobj);
+ return new PickelizedPyObjRdExtFreeStyleServer(getFather(),varName,pyobj,std::move(_sha1));
+}
#include <Python.h>
#include "SALOMESDS_PickelizedPyObjServer.hxx"
+#include "SALOMESDS_Sha1Keeper.hxx"
namespace SALOMESDS
{
+ class PickelizedPyObjRdExtServer;
+
/*!
* State during the producer/consumer phase. Activated by TransactionMultiKeyAddSession transaction returned by dss.addMultiKeyValueSession.
*/
PickelizedPyObjRdExtInitServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value);
PickelizedPyObjRdExtInitServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj);
~PickelizedPyObjRdExtInitServer();
+ virtual PickelizedPyObjRdExtServer *buildStdInstanceFrom(const std::string& varName);
public:
std::string getAccessStr() const;
SALOME::ByteVec *fetchSerializedContent();
public:
static const char ACCESS_REPR[];
};
+
+ class PickelizedPyObjRdExtInitFreeStyleServer : public PickelizedPyObjRdExtInitServer, public Sha1Keeper
+ {
+ public:
+ PickelizedPyObjRdExtInitFreeStyleServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj, std::vector<unsigned char>&& sha1):PickelizedPyObjRdExtInitServer(father,varName,obj),Sha1Keeper(std::move(sha1)) { }
+ PickelizedPyObjRdExtServer *buildStdInstanceFrom(const std::string& varName) override;
+ };
}
#endif
// Author : Anthony GEAY (EDF R&D)
#include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
+#include "SALOMESDS_PickelizedPyObjRdExtInitServer.hxx"
#include "SALOMESDS_DataScopeServer.hxx"
#include "SALOMESDS_Exception.hxx"
return SALOME::PickelizedPyObjRdExtServer::_narrow(obj);
}
+PickelizedPyObjRdExtInitServer *PickelizedPyObjRdExtServer::buildInitInstanceFrom(const std::string& varName)
+{
+ PyObject *pyobj(this->getPyObj()); Py_XINCREF(pyobj);
+ return new PickelizedPyObjRdExtInitServer(getFather(),varName,pyobj);
+}
+
void PickelizedPyObjRdExtServer::checkRdExtnessOf(const std::string& methodName, PyObject *argsPy)
{
if(!_self)
{
return std::string(ACCESS_REPR);
}
+
+
+PickelizedPyObjRdExtInitServer *PickelizedPyObjRdExtFreeStyleServer::buildInitInstanceFrom(const std::string& varName)
+{
+ PyObject *pyobj(this->getPyObj()); Py_XINCREF(pyobj);
+ return new PickelizedPyObjRdExtInitFreeStyleServer(getFather(),varName,pyobj,std::move(_sha1));
+}
#include <Python.h>
#include "SALOMESDS_PickelizedPyObjServer.hxx"
+#include "SALOMESDS_Sha1Keeper.hxx"
namespace SALOMESDS
{
+ class PickelizedPyObjRdExtInitServer;
+
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();
+ virtual ~PickelizedPyObjRdExtServer();
SALOME::PickelizedPyObjRdExtServer_ptr invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
+ virtual PickelizedPyObjRdExtInitServer *buildInitInstanceFrom(const std::string& varName);
public:
std::string getAccessStr() const;
private:
public:
static const char ACCESS_REPR[];
};
+
+ class PickelizedPyObjRdExtFreeStyleServer : public PickelizedPyObjRdExtServer, public Sha1Keeper
+ {
+ public:
+ PickelizedPyObjRdExtFreeStyleServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value, std::vector<unsigned char>&& sha1):PickelizedPyObjRdExtServer(father,varName,value),Sha1Keeper(std::move(sha1)) { }
+ PickelizedPyObjRdExtFreeStyleServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj, std::vector<unsigned char>&& sha1):PickelizedPyObjRdExtServer(father,varName,obj),Sha1Keeper(std::move(sha1)) { }
+ PickelizedPyObjRdExtInitServer *buildInitInstanceFrom(const std::string& varName) override;
+ };
}
#endif
--- /dev/null
+// Copyright (C) 2018 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOMESDS_Sha1Keeper.hxx"
+#include "SALOMESDS_Exception.hxx"
+
+#include <sstream>
+
+void SALOMESDS::Sha1Keeper::checkSha1(const std::string& varName, const std::vector<unsigned char>& sha1) const
+{
+ if(sha1!=_sha1)
+ {
+ std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSha1 : SHA1 check fails ! Attempt of corruption of rdext data ! It means that var \"" << varName << "\" has been created but with an initial value different from the new value !";
+ throw Exception(oss.str());
+ }
+}
--- /dev/null
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#pragma once
+
+#include <vector>
+#include <string>
+
+namespace SALOMESDS
+{
+ class Sha1Keeper
+ {
+ public:
+ Sha1Keeper(std::vector<unsigned char>&& sha1):_sha1(std::move(sha1)) { }
+ void checkSha1(const std::string& varName, const std::vector<unsigned char>& sha1) const;
+ virtual ~Sha1Keeper() { }
+ protected:
+ //! This sha1 is a discriminant key that allows RdExt "FreeStyle" methods to ensure that a "creation" over an already present var is legal or illegal.
+ std::vector<unsigned char> _sha1;
+ };
+}
+
}
void TransactionVarCreate::prepareRollBackInCaseOfFailure()
-{//nothing it is not a bug
+{
checkNotAlreadyExisting();
}
_dsct->createRdExtVarInternal(_var_name,data2);
}
+TransactionRdExtVarFreeStyleCreate::TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1):TransactionRdExtVarCreate(dsct,varName,constValue)
+{
+ FromByteSeqToVB(sha1,_sha1);
+}
+
+void TransactionRdExtVarFreeStyleCreate::prepareRollBackInCaseOfFailure()
+{//nothing it is not a bug
+}
+
+void TransactionRdExtVarFreeStyleCreate::perform()
+{
+ SALOME::ByteVec data2;
+ FromVBToByteSeq(_data,data2);
+ _dsct->createRdExtVarFreeStyleInternal(_var_name,data2,std::move(_sha1));
+}
+
void TransactionRdExtInitVarCreate::perform()
{
SALOME::ByteVec data2;
void perform();
};
+ class TransactionRdExtVarFreeStyleCreate : public TransactionRdExtVarCreate
+ {
+ public:
+ TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1);
+ void prepareRollBackInCaseOfFailure();
+ void perform();
+ protected:
+ std::vector<unsigned char> _sha1;
+ };
+
class TransactionRdExtInitVarCreate : public TransactionVarCreate
{
public:
self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
pass
+ def testTransaction8(self):
+ """ EDF 16833 """
+ scopeName="ScopePP"
+ dsm=salome.naming_service.Resolve("/DataServerManager")
+ dsm.cleanScopesInNS()
+ if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+ dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+ self.assertTrue(isCreated)
+
+ value={"a":1,"b":2}
+ value2={'a':1,'c':3,'b':2}
+
+ varName="abc"
+ t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1") # sha1 is the key used to compare the initial value
+ dss.atomicApply([t0])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value)
+ t1=dss.addMultiKeyValueSession(varName)
+ t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))
+ dss.atomicApply([t1])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2)
+ t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1") # key is the same as original one -> OK
+ dss.atomicApply([t2])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2) # value2 remains untouched
+ t3=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha2")
+ self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t3]) # sha2 != sha1 -> rejected
+ pass
+
+ def testTransaction9(self):
+ """ EDF 16833 : use case 2. Trying to createRdExt during add key session"""
+ scopeName="ScopePP"
+ dsm=salome.naming_service.Resolve("/DataServerManager")
+ dsm.cleanScopesInNS()
+ if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+ dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+ self.assertTrue(isCreated)
+
+ value={"a":1,"b":2}
+ value2={'a':1,'c':3,'b':2}
+
+ varName="abc"
+ t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1")
+ dss.atomicApply([t0])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value)
+ t1=dss.addMultiKeyValueSession(varName)
+ t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1")
+ dss.atomicApply([t2])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value)
+ t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))
+ dss.atomicApply([t1])
+ self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2)
+ pass
+
+
def testLockToDump(self):
""" Test to check that holdRequests method. This method wait for clean server status and hold it until activeRequests is called.
Warning this method expects a not overloaded machine to be run because test is based on ellapse time.