From c86eaee72b707fc499beda1f5fa4bee75d7c5d20 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 10 Jul 2015 15:10:22 +0200 Subject: [PATCH] First draft. --- idl/SALOME_SDS.idl | 13 +++ src/Launcher/SALOME_LauncherServer.cxx | 4 + src/SALOMESDS/CMakeLists.txt | 2 + src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx | 29 +++++++ src/SALOMESDS/SALOMESDS_BasicDataServer.cxx | 2 +- src/SALOMESDS/SALOMESDS_BasicDataServer.hxx | 2 +- src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 9 ++ src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 1 + src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 21 +++-- src/SALOMESDS/SALOMESDS_DataServerManager.hxx | 3 + src/SALOMESDS/SALOMESDS_RefCountServ.hxx | 5 +- src/SALOMESDS/SALOMESDS_Transaction.cxx | 61 +++++++++++++ src/SALOMESDS/SALOMESDS_Transaction.hxx | 65 ++++++++++++++ .../SALOMESDS_TransactionFactory.cxx | 85 +++++++++++++++++++ .../SALOMESDS_TransactionFactory.hxx | 61 +++++++++++++ 15 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 src/SALOMESDS/SALOMESDS_Transaction.cxx create mode 100644 src/SALOMESDS/SALOMESDS_Transaction.hxx create mode 100644 src/SALOMESDS/SALOMESDS_TransactionFactory.cxx create mode 100644 src/SALOMESDS/SALOMESDS_TransactionFactory.hxx diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 333dee788..d6c6a6690 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -62,6 +62,7 @@ module SALOME void ping(); string getScopeName(); StringVec listVars(); + boolean existVar(in string varName) raises (SALOME::SALOME_Exception); BasicDataServer retrieveVar(in string varName) raises (SALOME::SALOME_Exception); void deleteVar(in string varName) raises (SALOME::SALOME_Exception); PickelizedPyObjRdOnlyServer createRdOnlyVar(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); @@ -83,4 +84,16 @@ module SALOME void cleanScopesInNS(); void shutdownScopes() raises (SALOME::SALOME_Exception); }; + + interface Transaction + { + }; + + typedef sequence ListOfTransaction; + + interface TransactionFactory + { + Transaction createRdOnlyVar(in string varName, in string scopeName, in ByteVec constValue) raises (SALOME::SALOME_Exception); + void atomicApply(in ListOfTransaction transactions) raises (SALOME::SALOME_Exception); + }; }; diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx index d1ffcb03b..b5b87cdb1 100644 --- a/src/Launcher/SALOME_LauncherServer.cxx +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -22,6 +22,7 @@ #include "SALOME_Launcher.hxx" #include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_TransactionFactory.hxx" #include "utilities.h" #include #include @@ -102,6 +103,9 @@ int main(int argc, char* argv[]) SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(argc,argv,orb,root_poa)); dsm->_remove_ref(); // + SALOMESDS::TransactionFactory *tf(new SALOMESDS::TransactionFactory(dsm)); + tf->_remove_ref(); + // orb->run(); orb->destroy(); } diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt index f049fb543..2f58f3ddf 100644 --- a/src/SALOMESDS/CMakeLists.txt +++ b/src/SALOMESDS/CMakeLists.txt @@ -44,6 +44,8 @@ SET(SalomeSDS_SOURCES SALOMESDS_PickelizedPyObjRdOnlyServer.cxx SALOMESDS_PickelizedPyObjRdExtServer.cxx SALOMESDS_PickelizedPyObjRdWrServer.cxx + SALOMESDS_TransactionFactory.cxx + SALOMESDS_Transaction.cxx ) ADD_LIBRARY(SalomeSDS ${SalomeSDS_SOURCES}) diff --git a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx index ce199141f..249829e86 100644 --- a/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx +++ b/src/SALOMESDS/SALOMESDS_AutoRefCountPtr.hxx @@ -23,8 +23,16 @@ #include "SALOMESDS_Exception.hxx" +#include "omniORB4/CORBA.h" + namespace SALOMESDS { + class POAHolder + { + public: + virtual PortableServer::POA_var getPOA() const = 0; + }; + template class AutoRefCountPtr { @@ -73,6 +81,27 @@ namespace SALOMESDS ptr->incrRef(); return ret; } + + template + class AutoServantPtr + { + public: + AutoServantPtr(T *ptr=0):_ptr(ptr) { } + ~AutoServantPtr() { destroyPtr(); } + bool operator==(const AutoServantPtr& other) const { return _ptr==other._ptr; } + bool operator==(const T *other) const { return _ptr==other; } + AutoServantPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } + T *operator->() { return _ptr ; } + const T *operator->() const { return _ptr; } + T& operator*() { return *_ptr; } + const T& operator*() const { return *_ptr; } + operator T *() { return _ptr; } + operator const T *() const { return _ptr; } + private: + void destroyPtr() { if(!_ptr) return; } + private: + T *_ptr; + }; } #endif diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx index f72154b1f..8b6ce446d 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.cxx @@ -64,7 +64,7 @@ void BasicDataServer::Destroy() enforcedRelease(); } -PortableServer::POA_var BasicDataServer::getPOA() +PortableServer::POA_var BasicDataServer::getPOA() const { return _father->getPOA(); } diff --git a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx index 5ceec0ada..e87da002b 100644 --- a/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx +++ b/src/SALOMESDS/SALOMESDS_BasicDataServer.hxx @@ -46,7 +46,7 @@ namespace SALOMESDS public: std::string getVarNameCpp() const { return _var_name; } protected: - PortableServer::POA_var getPOA(); + PortableServer::POA_var getPOA() const; protected: DataScopeServer *_father; private: diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 6fdeb890f..9eceedac1 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -90,6 +90,15 @@ SALOME::StringVec *DataScopeServer::listVars() return ret; } +CORBA::Boolean DataScopeServer::existVar(const char *varName) +{ + std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator it(_vars.begin()); + for(;it!=_vars.end();it++) + if((*it).second->getVarNameCpp()==varName) + return true; + return false; +} + SALOME::BasicDataServer_ptr DataScopeServer::retrieveVar(const char *varName) { std::string varNameCpp(varName); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 7cf7f6d6d..e00c082a6 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -45,6 +45,7 @@ namespace SALOMESDS void ping(); char *getScopeName(); SALOME::StringVec *listVars(); + 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); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 08e4954b3..358f7a6a6 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -97,14 +97,7 @@ SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope() CORBA::Boolean DataServerManager::isAliveAndKicking(const char *scopeName) { SALOME::DataScopeServer_var scopePtr(getScopePtrGivenName(scopeName)); - CORBA::Boolean ret(true); - try - { - scopePtr->ping(); - } - catch(...) - { ret=false; } - return ret; + return IsAliveAndKicking(scopePtr); } SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName) @@ -202,6 +195,18 @@ std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& return oss.str(); } +CORBA::Boolean DataServerManager::IsAliveAndKicking(SALOME::DataScopeServer_ptr scopePtr) +{ + CORBA::Boolean ret(true); + try + { + scopePtr->ping(); + } + catch(...) + { ret=false; } + return ret; +} + std::vector DataServerManager::listOfScopesCpp() { SALOME_NamingService ns(_orb); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx index 944efc8c6..2d52c6af0 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -49,7 +49,10 @@ namespace SALOMESDS void removeDataScope(const char *scopeName); void cleanScopesInNS(); void shutdownScopes(); + public: + CORBA::ORB_var getORB() { return _orb; } static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName); + static CORBA::Boolean IsAliveAndKicking(SALOME::DataScopeServer_ptr scopePtr); public: static const char NAME_IN_NS[]; static const char DFT_SCOPE_NAME_IN_NS[]; diff --git a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx index bcc7f3568..7a0438eb8 100644 --- a/src/SALOMESDS/SALOMESDS_RefCountServ.hxx +++ b/src/SALOMESDS/SALOMESDS_RefCountServ.hxx @@ -21,16 +21,15 @@ #ifndef __SALOMESDS_REFCOUNTSERV_HXX__ #define __SALOMESDS_REFCOUNTSERV_HXX__ -#include +#include "SALOMESDS_AutoRefCountPtr.hxx" namespace SALOMESDS { - class RefCountServ : public virtual PortableServer::ServantBase + class RefCountServ : public virtual PortableServer::ServantBase, public POAHolder { public: void incrRef() const; bool decrRef() const; - virtual PortableServer::POA_var getPOA() = 0; protected: void enforcedRelease(); RefCountServ(); diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx new file mode 100644 index 000000000..4bb1f960a --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2015 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_Transaction.hxx" +#include "SALOMESDS_TransactionFactory.hxx" +#include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_Exception.hxx" + +#include + +using namespace SALOMESDS; + +void Transaction::checkAliveAndKicking() +{ + SALOME::DataScopeServer_var dsc(_tf->getDSM()->retriveDataScope(_scope_name.c_str())); + if(!DataServerManager::IsAliveAndKicking(dsc)) + throw Exception("Transaction::checkAliveAndKicking : not alive !"); +} + +void Transaction::FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector& ret) +{ + std::size_t sz(bsToBeConv.length()); + ret.resize(sz); + unsigned char *buf(const_cast(&ret[0])); + for(std::size_t i=0;igetDSM()->retriveDataScope(_scope_name.c_str())); + if(!DataServerManager::IsAliveAndKicking(dsc)) + throw Exception("TransactionVarCreate::checkAliveAndKicking : not alive !"); + if(dsc->existVar(_var_name.c_str())) + { + std::ostringstream oss; oss << "TransactionVarCreate::checkAliveAndKicking : var \"" << _var_name << "\" already exists in scope named \"" << _scope_name << "\" !"; + throw Exception(oss.str()); + } +} diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx new file mode 100644 index 000000000..a1cdfaac6 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -0,0 +1,65 @@ +// Copyright (C) 2007-2015 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) + +#ifndef __SALOMESDS_TRANSACTION_HXX__ +#define __SALOMESDS_TRANSACTION_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) + +#include "SALOMESDS_Defines.hxx" + +#include +#include + +namespace SALOMESDS +{ + class TransactionFactory; + + class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction + { + public: + Transaction(TransactionFactory *tf, const std::string& varName, const std::string& scopeName):_tf(tf),_var_name(varName),_scope_name(scopeName) { } + virtual void checkAliveAndKicking(); + public: + static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector& ret); + protected: + TransactionFactory *_tf; + std::string _var_name; + std::string _scope_name; + }; + + class TransactionVarCreate : public Transaction + { + public: + TransactionVarCreate(TransactionFactory *tf, const std::string& varName, const std::string& scopeName, const SALOME::ByteVec& constValue); + void checkAliveAndKicking(); + protected: + std::vector _data; + }; + + class TransactionRdOnlyVarCreate : public TransactionVarCreate + { + public: + TransactionRdOnlyVarCreate(TransactionFactory *tf, const std::string& varName, const std::string& scopeName, const SALOME::ByteVec& constValue):TransactionVarCreate(tf,varName,scopeName,constValue) { } + }; +} + +#endif diff --git a/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx b/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx new file mode 100644 index 000000000..8af10f1f7 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_TransactionFactory.cxx @@ -0,0 +1,85 @@ +// Copyright (C) 2007-2015 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_TransactionFactory.hxx" +#include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_AutoRefCountPtr.hxx" +#include "SALOMESDS_Transaction.hxx" +#include "SALOME_NamingService.hxx" +#include "SALOMESDS_Exception.hxx" + +#include + +using namespace SALOMESDS; + +const char TransactionFactory::NAME_IN_NS[]="/TransactionFactory"; + +TransactionFactory::TransactionFactory(DataServerManager *dsm):_dsm(dsm) +{ + if(!_dsm) + throw Exception("TransactionFactory : null pointer !"); + CORBA::ORB_var orb(_dsm->getORB()); + CORBA::Object_var obj0(orb->resolve_initial_references("RootPOA")); + _poa=PortableServer::POA::_narrow(obj0); + // + PortableServer::ObjectId_var id(_poa->activate_object(this)); + CORBA::Object_var obj(_poa->id_to_reference(id)); + SALOME::TransactionFactory_var obj2(SALOME::TransactionFactory::_narrow(obj)); + // publish Data server manager in NS + SALOME_NamingService ns(orb); + ns.Register(obj2,NAME_IN_NS); +} + +SALOME::Transaction_ptr TransactionFactory::createRdOnlyVar(const char *varName, const char *scopeName, const SALOME::ByteVec& constValue) +{ + TransactionRdOnlyVarCreate *ret(new TransactionRdOnlyVarCreate(this,varName,scopeName,constValue)); + ret->checkAliveAndKicking(); + PortableServer::ObjectId_var id(_poa->activate_object(ret)); + CORBA::Object_var obj(_poa->id_to_reference(id)); + return SALOME::Transaction::_narrow(obj); +} + +void TransactionFactory::atomicApply(const SALOME::ListOfTransaction& transactions) +{ + std::size_t sz(transactions.length()); + std::vector< AutoServantPtr > transactionsCpp; + for(std::size_t i=0;ireference_to_servant(transactions[i]); + elt=dynamic_cast(eltBase); + } + catch(...) + { + std::ostringstream oss; oss << "TransactionFactory::atomicApply : the elt #" << i << " is invalid !"; + throw Exception(oss.str()); + } + if(!elt) + { + std::ostringstream oss; oss << "TransactionFactory::atomicApply : the elt #" << i << " is null ?"; + throw Exception(oss.str()); + } + elt->_remove_ref(); + transactionsCpp[i]=elt; + } +} diff --git a/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx b/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx new file mode 100644 index 000000000..2e9507331 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_TransactionFactory.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2015 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) + +#ifndef __SALOMESDS_TRANSACTIONFACTORY_HXX__ +#define __SALOMESDS_TRANSACTIONFACTORY_HXX__ + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SALOME_SDS) +#include "SALOMESDS_Defines.hxx" +#include "SALOMESDS_AutoRefCountPtr.hxx" + +#include +#include + +namespace SALOMESDS +{ + class DataServerManager; + + class SALOMESDS_EXPORT TransactionFactory : public virtual POA_SALOME::TransactionFactory + { + public: + TransactionFactory(DataServerManager *dsm); + DataServerManager *getDSM() const { return _dsm; } + PortableServer::POA_var getPOA() const { return _poa; } + public: + 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); + SALOME::ByteVec *waitForKeyInVar(const char *varName, const char *scopeName, const SALOME::ByteVec& constKey); + SALOME::ByteVec *waitForKeyInVarAndKillIt(const char *varName, const char *scopeName, const SALOME::ByteVec& constKey, SALOME::Transaction_out transaction); + void atomicApply(const SALOME::ListOfTransaction& transactions); + public: + static const char NAME_IN_NS[]; + private: + DataServerManager *_dsm; + //! multi thread poa + PortableServer::POA_var _poa; + }; +} + +#endif -- 2.39.2