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 // File : ConnectionManager_i.cxx
24 // Author : André RIBES (EDF)
27 #include "ConnectionManager_i.hxx"
35 const char * ConnectionManager_i::_ConnectionManagerNameInNS = "/ConnectionManager";
37 ConnectionManager_i::ConnectionManager_i(CORBA::ORB_ptr orb) {
38 _orb = CORBA::ORB::_duplicate(orb) ;
39 _NS = new SALOME_NamingService(orb);
40 CORBA::Object_var obref = _this();
42 _NS->Register(obref, _ConnectionManagerNameInNS);
45 pthread_mutex_init(&mutex, NULL);
48 ConnectionManager_i::~ConnectionManager_i()
53 Engines::ConnectionManager::connectionId
54 ConnectionManager_i::connect(Engines::DSC_ptr uses_component,
55 const char* uses_port_name,
56 Engines::DSC_ptr provides_component,
57 const char* provides_port_name)
60 Ports::Port_var p_port = provides_component->get_provides_port(provides_port_name, false);
61 uses_component->connect_uses_port(uses_port_name, p_port);
62 provides_component->connect_provides_port(provides_port_name);
64 // Creating a new connection id.
65 // We use a mutex for multithreaded applications.
66 pthread_mutex_lock(&mutex);
67 Engines::ConnectionManager::connectionId rtn_id = current_id;
69 pthread_mutex_unlock(&mutex);
71 // Creating a new structure containing connection's infos.
72 connection_infos * infos = new connection_infos();
73 infos->uses_component = Engines::DSC::_duplicate(uses_component);
74 infos->uses_port_name = uses_port_name;
75 infos->provides_component = Engines::DSC::_duplicate(provides_component);
76 infos->provides_port_name = provides_port_name;
77 infos->provides_port = Ports::Port::_duplicate(p_port);
79 // Adding the new connection into the map.
86 ConnectionManager_i::disconnect(Engines::ConnectionManager::connectionId id,
87 Engines::DSC::Message message)
90 // Connection id exist ?
91 ids_it = ids.find(id);
92 if (ids_it == ids.end())
93 throw Engines::ConnectionManager::BadId();
96 // We need to catch exceptions if one of these disconnect operation fails.
97 connection_infos * infos = ids[id];
100 infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), message);
102 catch(CORBA::SystemException& ex)
104 std::cerr << "Problem in disconnect(CORBA::SystemException) provides port: " << infos->provides_port_name << std::endl;
109 infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(),
110 infos->provides_port, message);
112 catch(CORBA::SystemException& ex)
114 std::cerr << "Problem in disconnect(CORBA::SystemException) uses port: " << infos->uses_port_name << std::endl;
121 throw Engines::DSC::BadPortReference();
125 ConnectionManager_i::ShutdownWithExit()
127 _NS->Destroy_Name(_ConnectionManagerNameInNS);
128 ids_it = ids.begin();
129 while(ids_it != ids.end())
131 disconnect(ids_it->first, Engines::DSC::RemovingConnection);
132 ids_it = ids.begin();
135 if(!CORBA::is_nil(_orb))
141 ConnectionManager_i::getPID()
145 (CORBA::Long)getpid();
147 (CORBA::Long)_getpid();