1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "ConnectionManager.hxx"
26 ConnectionManager::ConnectionManager()
33 ConnectionManager::~ConnectionManager()
37 ConnectionManager::connectionId
38 ConnectionManager::connect(Engines::DSC_ptr uses_component,
39 const char* uses_port_name,
40 Engines::DSC_ptr provides_component,
41 const char* provides_port_name)
43 // We use a mutex for multithreaded applications.
44 std::unique_lock<std::mutex> lock(_mutex);
45 Ports::Port_var p_port = provides_component->get_provides_port(provides_port_name, false);
46 uses_component->connect_uses_port(uses_port_name, p_port);
47 provides_component->connect_provides_port(provides_port_name);
49 // Creating a new structure containing connection's infos.
50 connection_infos * infos = new connection_infos();
51 infos->uses_component = Engines::DSC::_duplicate(uses_component);
52 infos->uses_port_name = uses_port_name;
53 infos->provides_component = Engines::DSC::_duplicate(provides_component);
54 infos->provides_port_name = provides_port_name;
55 infos->provides_port = Ports::Port::_duplicate(p_port);
57 // Creating a new connection id.
58 ConnectionManager::connectionId rtn_id = _current_id;
60 // Adding the new connection into the map.
67 ConnectionManager::disconnect(ConnectionManager::connectionId id,
68 Engines::DSC::Message message)
70 std::unique_lock<std::mutex> lock(_mutex);
72 // Connection id exist ?
73 ids_it_type ids_it = _ids.find(id);
74 if (ids_it == _ids.end())
78 // We need to catch exceptions if one of these disconnect operation fails.
79 // connection_infos * infos = ids[id];
80 connection_infos * infos = ids_it->second;
83 infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), message);
85 catch(CORBA::SystemException& ex)
87 std::cerr << "Problem in disconnect(CORBA::SystemException) provides port: " << infos->provides_port_name.c_str() << std::endl;
92 infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(),
93 infos->provides_port, message);
95 catch(CORBA::SystemException& ex)
97 std::cerr << "Problem in disconnect(CORBA::SystemException) uses port: " << infos->uses_port_name.c_str() << std::endl;
104 throw Engines::DSC::BadPortReference();
108 ConnectionManager::ShutdownWithExit()
110 ids_it_type ids_it = _ids.begin();
111 while(ids_it != _ids.end())
113 disconnect(ids_it->first, Engines::DSC::RemovingConnection);
114 ids_it = _ids.begin();