1 // Copyright (C) 2007-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ConnectionManager.hxx"
23 ConnectionManager::ConnectionManager()
30 ConnectionManager::~ConnectionManager()
34 ConnectionManager::connectionId
35 ConnectionManager::connect(Engines::DSC_ptr uses_component,
36 const char* uses_port_name,
37 Engines::DSC_ptr provides_component,
38 const char* provides_port_name)
40 // We use a mutex for multithreaded applications.
41 std::unique_lock<std::mutex> lock(_mutex);
42 Ports::Port_var p_port = provides_component->get_provides_port(provides_port_name, false);
43 uses_component->connect_uses_port(uses_port_name, p_port);
44 provides_component->connect_provides_port(provides_port_name);
46 // Creating a new structure containing connection's infos.
47 connection_infos * infos = new connection_infos();
48 infos->uses_component = Engines::DSC::_duplicate(uses_component);
49 infos->uses_port_name = uses_port_name;
50 infos->provides_component = Engines::DSC::_duplicate(provides_component);
51 infos->provides_port_name = provides_port_name;
52 infos->provides_port = Ports::Port::_duplicate(p_port);
54 // Creating a new connection id.
55 ConnectionManager::connectionId rtn_id = _current_id;
57 // Adding the new connection into the map.
64 ConnectionManager::disconnect(ConnectionManager::connectionId id,
65 Engines::DSC::Message message)
67 std::unique_lock<std::mutex> lock(_mutex);
69 // Connection id exist ?
70 ids_it_type ids_it = _ids.find(id);
71 if (ids_it == _ids.end())
75 // We need to catch exceptions if one of these disconnect operation fails.
76 // connection_infos * infos = ids[id];
77 connection_infos * infos = ids_it->second;
80 infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), message);
82 catch(CORBA::SystemException& ex)
84 std::cerr << "Problem in disconnect(CORBA::SystemException) provides port: " << infos->provides_port_name.c_str() << std::endl;
89 infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(),
90 infos->provides_port, message);
92 catch(CORBA::SystemException& ex)
94 std::cerr << "Problem in disconnect(CORBA::SystemException) uses port: " << infos->uses_port_name.c_str() << std::endl;
101 throw Engines::DSC::BadPortReference();
105 ConnectionManager::ShutdownWithExit()
107 ids_it_type ids_it = _ids.begin();
108 while(ids_it != _ids.end())
110 disconnect(ids_it->first, Engines::DSC::RemovingConnection);
111 ids_it = _ids.begin();