SET(YACSRuntimeSALOME_HEADERS
YACSRuntimeSALOMEExport.hxx
CalStreamPort.hxx
+ ConnectionManager.hxx
CORBAComponent.hxx
CORBACORBAConv.hxx
CORBACppConv.hxx
SET(YACSRuntimeSALOME_SOURCES
TypeConversions.cxx
+ ConnectionManager.cxx
CORBACORBAConv.cxx
CORBAPythonConv.cxx
CORBAXMLConv.cxx
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) )
{
}
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)
{
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<Engines::ConnectionManager::connectionId>::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)
{
--- /dev/null
+// 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 <iostream>
+
+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<std::mutex> 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<std::mutex> 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();
+ }
+}
--- /dev/null
+// 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 <map>
+#include <mutex>
+
+#include <SALOMEconfig.h>
+#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<Engines::ConnectionManager::connectionId,
+ connection_infos *> ids_type;
+ typedef std::map<Engines::ConnectionManager::connectionId,
+ connection_infos *>::iterator ids_it_type;
+
+ ids_type _ids;
+ int _current_id;
+ std::mutex _mutex;
+};
+
+#endif
{
delete (*pt).second;
}
+ _connectionManager.ShutdownWithExit();
}
void RuntimeSALOME::loadModulCatalog()
#include <Python.h>
#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
DynamicAny::DynAnyFactory_ptr getDynFactory() const;
omniORBpyAPI* getApi();
PyObject * get_omnipy();
+ ConnectionManager& getConnectionManager(){return _connectionManager;}
protected:
RuntimeSALOME(); // singleton
long _flags;
bool _usePython, _useCorba, _useCpp, _useXml;
+ private:
+ ConnectionManager _connectionManager;
};
}
}