]> SALOME platform Git repositories - modules/kernel.git/blob - src/DSC/DSC_Basic/ConnectionManager_i.cxx
Salome HOME
Fix a long-standing problem with passing wrong values to the --standalone or --embedd...
[modules/kernel.git] / src / DSC / DSC_Basic / ConnectionManager_i.cxx
1 //  Copyright (C) 2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //
21 //
22 //  File   : ConnectionManager_i.cxx
23 //  Author : André RIBES (EDF)
24 //  Module : KERNEL
25
26 #include "ConnectionManager_i.hxx"
27 #include "SALOME_NamingService.hxx"
28
29 ConnectionManager_i::ConnectionManager_i(CORBA::ORB_ptr orb) {
30   SALOME_NamingService * ns = new SALOME_NamingService(orb);
31   const char * ConnectionManagerNameInNS = "/ConnectionManager";
32   ns->Register(_this(), ConnectionManagerNameInNS);
33
34   current_id = 0;
35   pthread_mutex_init(&mutex, NULL);
36 }
37
38 ConnectionManager_i::~ConnectionManager_i() {}
39
40 Engines::ConnectionManager::connectionId
41 ConnectionManager_i::connect(Engines::DSC_ptr uses_component, 
42                              const char* uses_port_name, 
43                              Engines::DSC_ptr provides_component, 
44                              const char* provides_port_name) 
45 throw (Engines::DSC::PortNotDefined,
46        Engines::DSC::BadPortType,
47        Engines::DSC::NilPort) 
48 {
49
50   Ports::Port_ptr p_port = provides_component->get_provides_port(provides_port_name, false);
51   uses_component->connect_uses_port(uses_port_name, p_port);
52   provides_component->connect_provides_port(provides_port_name);
53
54   // Creating a new connection id.
55   // We use a mutex for multithreaded applications.
56   pthread_mutex_lock(&mutex);
57   Engines::ConnectionManager::connectionId rtn_id = current_id;
58   current_id += 1;
59   pthread_mutex_unlock(&mutex);
60
61   // Creating a new structure containing connection's infos.
62   connection_infos * infos = new connection_infos();
63   infos->uses_component = Engines::DSC::_duplicate(uses_component);
64   infos->uses_port_name = uses_port_name;
65   infos->provides_component = Engines::DSC::_duplicate(provides_component);
66   infos->provides_port_name = provides_port_name;
67   infos->provides_port = Ports::Port::_duplicate(p_port);
68
69   // Adding the new connection into the map.
70   ids[rtn_id] = infos;
71
72   return rtn_id;
73 }
74
75 void
76 ConnectionManager_i::disconnect(Engines::ConnectionManager::connectionId id,
77                                 Engines::DSC::Message message)
78 throw (Engines::ConnectionManager::BadId)
79 {
80   // Connection id exist ?
81   ids_it = ids.find(id);
82   if (ids_it == ids.end())
83     throw Engines::ConnectionManager::BadId();
84
85   // TODO
86   // We need to catch exceptions if one of these disconnect operation fails.
87   connection_infos * infos = ids[id];
88   infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(),
89                                                       message);
90   infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(),
91                                               Ports::Port::_duplicate(infos->provides_port),
92                                               message);
93   delete infos;
94   ids.erase(id);
95 }