Salome HOME
ConnectionManager in no corba mode.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Fri, 17 Dec 2021 15:09:24 +0000 (16:09 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Fri, 17 Dec 2021 15:09:24 +0000 (16:09 +0100)
src/runtime/CMakeLists.txt
src/runtime/CORBANode.cxx
src/runtime/ConnectionManager.cxx [new file with mode: 0644]
src/runtime/ConnectionManager.hxx [new file with mode: 0644]
src/runtime/RuntimeSALOME.cxx
src/runtime/RuntimeSALOME.hxx

index c0e74f647788925c391c9b40eb486f02b9da7400..c10900ca6fc0bc5d0dfc09cc6161565462a5a3ad 100644 (file)
@@ -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               
index 1f9dedc8bf3951d2377401345c4374467b210740..681ca77f560a378b1430ab5108f10f55ec31924e 100644 (file)
@@ -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<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)
         {
diff --git a/src/runtime/ConnectionManager.cxx b/src/runtime/ConnectionManager.cxx
new file mode 100644 (file)
index 0000000..fafe62f
--- /dev/null
@@ -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 <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();
+    }
+}
diff --git a/src/runtime/ConnectionManager.hxx b/src/runtime/ConnectionManager.hxx
new file mode 100644 (file)
index 0000000..43fa727
--- /dev/null
@@ -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 <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
index d41e67033d8f7176ac4a4dd74b899801f77815d7..7af875af7ab5a3f3b3c483d2a1020b0aeedf7673 100644 (file)
@@ -247,6 +247,7 @@ RuntimeSALOME::~RuntimeSALOME()
     {
       delete (*pt).second;
     }
+  _connectionManager.ShutdownWithExit();
 }
 
 void RuntimeSALOME::loadModulCatalog()
index c41f288571849d03514360ca7901aa03d748477b..39311a46223fca9c948cf84883cc2d65edbb81fc 100644 (file)
@@ -22,7 +22,7 @@
 #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
@@ -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;
     };
   }
 }