From 6b3363988ff481a11301f72ef352b8f9ea7745ac Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Fri, 17 Dec 2021 16:09:24 +0100 Subject: [PATCH] ConnectionManager in no corba mode. --- src/runtime/CMakeLists.txt | 2 + src/runtime/CORBANode.cxx | 14 ++-- src/runtime/ConnectionManager.cxx | 116 ++++++++++++++++++++++++++++++ src/runtime/ConnectionManager.hxx | 86 ++++++++++++++++++++++ src/runtime/RuntimeSALOME.cxx | 1 + src/runtime/RuntimeSALOME.hxx | 5 +- 6 files changed, 213 insertions(+), 11 deletions(-) create mode 100644 src/runtime/ConnectionManager.cxx create mode 100644 src/runtime/ConnectionManager.hxx diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index c0e74f647..c10900ca6 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -85,6 +85,7 @@ SET(_link_LIBRARIES SET(YACSRuntimeSALOME_HEADERS YACSRuntimeSALOMEExport.hxx CalStreamPort.hxx + ConnectionManager.hxx CORBAComponent.hxx CORBACORBAConv.hxx CORBACppConv.hxx @@ -153,6 +154,7 @@ SET(YACSRuntimeSALOME_HEADERS SET(YACSRuntimeSALOME_SOURCES TypeConversions.cxx + ConnectionManager.cxx CORBACORBAConv.cxx CORBAPythonConv.cxx CORBAXMLConv.cxx diff --git a/src/runtime/CORBANode.cxx b/src/runtime/CORBANode.cxx index 1f9dedc8b..681ca77f5 100644 --- a/src/runtime/CORBANode.cxx +++ b/src/runtime/CORBANode.cxx @@ -352,10 +352,7 @@ void SalomeNode::connectService() if(_setOfOutputDataStreamPort.size() == 0)return; CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr(); - SALOME_NamingService_Wrapper NS(getSALOMERuntime()->getOrb()) ; - SALOME_LifeCycleCORBA LCC(&NS) ; - CORBA::Object_var obj = NS.Resolve("/ConnectionManager"); - Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj); + ConnectionManager& manager = getSALOMERuntime()->getConnectionManager(); Engines::Superv_Component_var me=Engines::Superv_Component::_narrow(objComponent); if( CORBA::is_nil(me) ) { @@ -399,7 +396,7 @@ void SalomeNode::connectService() } try { - id=manager->connect(me,port->getName().c_str(),other,(*iterout)->getName().c_str()); + id=manager.connect(me,port->getName().c_str(),other,(*iterout)->getName().c_str()); } catch(Engines::DSC::PortNotDefined& ex) { @@ -473,17 +470,14 @@ void SalomeNode::disconnectService() if(ids.size() == 0) return; - SALOME_NamingService_Wrapper NS(getSALOMERuntime()->getOrb()) ; - SALOME_LifeCycleCORBA LCC(&NS) ; - CORBA::Object_var obj = NS.Resolve("/ConnectionManager"); - Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj); + ConnectionManager& manager = getSALOMERuntime()->getConnectionManager(); std::list::iterator iter; for(iter = ids.begin(); iter != ids.end(); iter++) { DEBTRACE("Trying to disconnect: " << *iter ); try { - manager->disconnect(*iter,Engines::DSC::RemovingConnection); + manager.disconnect(*iter,Engines::DSC::RemovingConnection); } catch(Engines::ConnectionManager::BadId& ex) { diff --git a/src/runtime/ConnectionManager.cxx b/src/runtime/ConnectionManager.cxx new file mode 100644 index 000000000..fafe62f6a --- /dev/null +++ b/src/runtime/ConnectionManager.cxx @@ -0,0 +1,116 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// + +#include "ConnectionManager.hxx" +#include + +ConnectionManager::ConnectionManager() +: _ids() +, _current_id(0) +, _mutex() +{ +} + +ConnectionManager::~ConnectionManager() +{ +} + +ConnectionManager::connectionId +ConnectionManager::connect(Engines::DSC_ptr uses_component, + const char* uses_port_name, + Engines::DSC_ptr provides_component, + const char* provides_port_name) +{ + // We use a mutex for multithreaded applications. + std::unique_lock lock(_mutex); + Ports::Port_var p_port = provides_component->get_provides_port(provides_port_name, false); + uses_component->connect_uses_port(uses_port_name, p_port); + provides_component->connect_provides_port(provides_port_name); + + // Creating a new structure containing connection's infos. + connection_infos * infos = new connection_infos(); + infos->uses_component = Engines::DSC::_duplicate(uses_component); + infos->uses_port_name = uses_port_name; + infos->provides_component = Engines::DSC::_duplicate(provides_component); + infos->provides_port_name = provides_port_name; + infos->provides_port = Ports::Port::_duplicate(p_port); + + // Creating a new connection id. + ConnectionManager::connectionId rtn_id = _current_id; + _current_id += 1; + // Adding the new connection into the map. + _ids[rtn_id] = infos; + + return rtn_id; +} + +void +ConnectionManager::disconnect(ConnectionManager::connectionId id, + Engines::DSC::Message message) +{ + std::unique_lock lock(_mutex); + int err=0; + // Connection id exist ? + ids_it_type ids_it = _ids.find(id); + if (ids_it == _ids.end()) + return; + + // TODO + // We need to catch exceptions if one of these disconnect operation fails. + // connection_infos * infos = ids[id]; + connection_infos * infos = ids_it->second; + try + { + infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), message); + } + catch(CORBA::SystemException& ex) + { + std::cerr << "Problem in disconnect(CORBA::SystemException) provides port: " << infos->provides_port_name << std::endl; + err=1; + } + try + { + infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(), + infos->provides_port, message); + } + catch(CORBA::SystemException& ex) + { + std::cerr << "Problem in disconnect(CORBA::SystemException) uses port: " << infos->uses_port_name << std::endl; + err=1; + } + delete infos; + _ids.erase(id); + + if(err) + throw Engines::DSC::BadPortReference(); +} + +void +ConnectionManager::ShutdownWithExit() +{ + ids_it_type ids_it = _ids.begin(); + while(ids_it != _ids.end()) + { + disconnect(ids_it->first, Engines::DSC::RemovingConnection); + ids_it = _ids.begin(); + } +} diff --git a/src/runtime/ConnectionManager.hxx b/src/runtime/ConnectionManager.hxx new file mode 100644 index 000000000..43fa72778 --- /dev/null +++ b/src/runtime/ConnectionManager.hxx @@ -0,0 +1,86 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// + +#ifndef _CONNECTION_MANAGER_HXX_ +#define _CONNECTION_MANAGER_HXX_ + +#include "YACSRuntimeSALOMEExport.hxx" +#include "DSC_Basic.hxx" + +#include +#include + +#include +#include CORBA_SERVER_HEADER(DSC_Engines) + +/*! \class ConnectionManager + * \brief This class implements the interface Engines::ConnectionManager. + * It is used to make connections between CALCIUM ports. + */ +class YACSRUNTIMESALOME_EXPORT ConnectionManager +{ + public : + ConnectionManager(); + ~ConnectionManager(); + + typedef short connectionId; + + /*! + * connect two CALCIUM ports of two components. + */ + ConnectionManager::connectionId connect(Engines::DSC_ptr uses_component, + const char* uses_port_name, + Engines::DSC_ptr provides_component, + const char* provides_port_name); + + /*! + * releases a connection performed with ConnectionManager::connect. + */ + void disconnect(ConnectionManager::connectionId id, + Engines::DSC::Message message); + + /*! + Shutdown the ConnectionManager process. + */ + void ShutdownWithExit(); + + private : + + struct connection_infos { + Engines::DSC_var uses_component; + std::string uses_port_name; + Engines::DSC_var provides_component; + std::string provides_port_name; + Ports::Port_var provides_port; + }; + + typedef std::map ids_type; + typedef std::map::iterator ids_it_type; + + ids_type _ids; + int _current_id; + std::mutex _mutex; +}; + +#endif diff --git a/src/runtime/RuntimeSALOME.cxx b/src/runtime/RuntimeSALOME.cxx index d41e67033..7af875af7 100644 --- a/src/runtime/RuntimeSALOME.cxx +++ b/src/runtime/RuntimeSALOME.cxx @@ -247,6 +247,7 @@ RuntimeSALOME::~RuntimeSALOME() { delete (*pt).second; } + _connectionManager.ShutdownWithExit(); } void RuntimeSALOME::loadModulCatalog() diff --git a/src/runtime/RuntimeSALOME.hxx b/src/runtime/RuntimeSALOME.hxx index c41f28857..39311a462 100644 --- a/src/runtime/RuntimeSALOME.hxx +++ b/src/runtime/RuntimeSALOME.hxx @@ -22,7 +22,7 @@ #include #include "YACSRuntimeSALOMEExport.hxx" - +#include "ConnectionManager.hxx" // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined #ifdef _POSIX_C_SOURCE #undef _POSIX_C_SOURCE @@ -241,6 +241,7 @@ namespace YACS DynamicAny::DynAnyFactory_ptr getDynFactory() const; omniORBpyAPI* getApi(); PyObject * get_omnipy(); + ConnectionManager& getConnectionManager(){return _connectionManager;} protected: RuntimeSALOME(); // singleton @@ -255,6 +256,8 @@ namespace YACS long _flags; bool _usePython, _useCorba, _useCpp, _useXml; + private: + ConnectionManager _connectionManager; }; } } -- 2.39.2