1 // Copyright (C) 2007-2024 CEA, EDF, 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 : Superv_Component_i.cxx
24 // Author : André RIBES (EDF), Eric Fayolle (EDF)
27 #include "Superv_Component_i.hxx"
29 DSC_EXCEPTION_CXX(Superv_Component_i,BadFabType)
30 DSC_EXCEPTION_CXX(Superv_Component_i,BadType)
31 DSC_EXCEPTION_CXX(Superv_Component_i,BadCast)
32 DSC_EXCEPTION_CXX(Superv_Component_i,UnexpectedState)
33 DSC_EXCEPTION_CXX(Superv_Component_i,PortAlreadyDefined)
34 DSC_EXCEPTION_CXX(Superv_Component_i,PortNotDefined)
35 DSC_EXCEPTION_CXX(Superv_Component_i,PortNotConnected)
36 DSC_EXCEPTION_CXX(Superv_Component_i,NilPort)
37 DSC_EXCEPTION_CXX(Superv_Component_i,BadProperty)
39 std::map<std::string, port_factory*> Superv_Component_i::_factory_map;
40 long Superv_Component_i::dscTimeOut=0;
43 Superv_Component_i::Superv_Component_i(CORBA::ORB_ptr orb,
44 PortableServer::POA_ptr poa,
45 PortableServer::ObjectId * contId,
46 const char *instanceName,
47 const char *interfaceName,
49 Engines_DSC_i(orb, poa, contId, instanceName, interfaceName)
51 if (SALOME::VerbosityActivated())
52 std::cerr << "--Superv_Component_i : MARK 1 ---- " << instanceName << "----" << std::endl;
56 Superv_Component_i::Superv_Component_i(CORBA::ORB_ptr orb,
57 PortableServer::POA_ptr poa,
58 Engines::Container_ptr container,
59 const char *instanceName,
60 const char *interfaceName,
63 Engines_DSC_i(orb, poa, container, instanceName, interfaceName,notif,regist)
65 if (SALOME::VerbosityActivated())
66 std::cerr << "--Superv_Component_i : MARK 1 ---- " << instanceName << "----" << std::endl;
72 Superv_Component_i::~Superv_Component_i()
74 my_superv_ports_it = my_superv_ports.begin();
75 for(;my_superv_ports_it != my_superv_ports.end();my_superv_ports_it++)
76 delete my_superv_ports_it->second;
80 Superv_Component_i::register_factory(const std::string & factory_name,
81 port_factory * factory_ptr)
83 factory_map_t::iterator it = _factory_map.find(factory_name);
85 if (it == _factory_map.end() )
87 _factory_map[factory_name] = factory_ptr;
92 Superv_Component_i::get_factory(const std::string & factory_name)
94 port_factory * rtn_factory = NULL;
95 factory_map_t::iterator it = _factory_map.find(factory_name);
97 if (it != _factory_map.end() )
99 rtn_factory = _factory_map[factory_name];
106 Superv_Component_i::create_provides_data_port(const std::string& port_fab_type)
109 provides_port * rtn_port = NULL;
110 std::string factory_name;
111 std::string type_name;
114 search_result = port_fab_type.find("_");
115 factory_name = port_fab_type.substr(0,search_result);
116 type_name = port_fab_type.substr(search_result+1, port_fab_type.length());
118 port_factory * factory = get_factory(factory_name);
120 rtn_port = factory->create_data_servant(type_name);
123 if (rtn_port == NULL)
124 throw BadFabType( LOC(OSS()<< "No way to get the port factory "
131 Superv_Component_i::create_uses_data_port(const std::string& port_fab_type)
134 uses_port * rtn_proxy = NULL;
135 std::string factory_name;
136 std::string type_name;
139 search_result = port_fab_type.find("_");
140 factory_name = port_fab_type.substr(0,search_result);
141 type_name = port_fab_type.substr(search_result+1, port_fab_type.length());
143 port_factory * factory = get_factory(factory_name);
145 rtn_proxy = factory->create_data_proxy(type_name);
148 if (rtn_proxy == NULL)
149 throw BadFabType( LOC(OSS()<< "No way to get the port factory "
156 Superv_Component_i::add_port(const char * port_fab_type,
157 const char * port_type,
158 const char * port_name)
161 assert(port_fab_type);
165 std::string s_port_type(port_type);
166 if (s_port_type == "provides") {
167 provides_port * port = create_provides_data_port(port_fab_type);
168 add_port(port, port_name);
170 else if (s_port_type == "uses") {
171 if (SALOME::VerbosityActivated())
172 std::cerr << "---- Superv_Component_i::add_port : MARK 1 ---- " << std::endl;
174 uses_port * port = create_uses_data_port(port_fab_type);
175 if (SALOME::VerbosityActivated())
176 std::cerr << "---- Superv_Component_i::add_port : MARK 2 ---- " << std::endl;
178 add_port(port, port_name);
181 throw BadType( LOC(OSS()<< "port_type must be either 'provides' either 'uses' not "
187 Superv_Component_i::add_port(provides_port * port,
188 const char* provides_port_name)
192 assert(provides_port_name);
196 Ports::PortProperties_var portproperties=port->get_port_properties();
197 Ports::Port_var portref=port->get_port_ref();
198 Engines_DSC_interface::add_provides_port(portref,
202 superv_port_t * new_superv_port = new superv_port_t();
203 new_superv_port->p_ref = port;
204 my_superv_ports[provides_port_name] = new_superv_port;
207 catch (const Engines::DSC::PortAlreadyDefined&) {
208 throw PortAlreadyDefined( LOC(OSS()<< "provides port "
209 << provides_port_name <<" already exist."));
211 catch (const Engines::DSC::NilPort&) {
212 throw NilPort( LOC(OSS()<< "provides port pointer is nul."));
214 catch (const Engines::DSC::BadProperty&) {
215 throw BadProperty( LOC(OSS()<< "Property is not well defined"));
220 Superv_Component_i::add_port(uses_port * port,
221 const char* uses_port_name)
225 assert(uses_port_name);
228 Ports::PortProperties_var portproperties=port->get_port_properties();
229 Engines_DSC_interface::add_uses_port(port->get_repository_id(),
232 superv_port_t * new_superv_port = new superv_port_t();
233 new_superv_port->u_ref = port;
234 my_superv_ports[uses_port_name] = new_superv_port;
236 catch (const Engines::DSC::PortAlreadyDefined&) {
237 throw PortAlreadyDefined( LOC(OSS()<< "uses port "
238 << uses_port_name <<" already exists."));
240 catch (const Engines::DSC::NilPort&) {
241 throw NilPort( LOC(OSS()<< "uses port pointer is nul."));
243 catch (const Engines::DSC::BadProperty&) {
244 throw BadProperty( LOC(OSS()<< "Property is not well defined"));
249 Superv_Component_i::get_port(provides_port *& port,
250 const char * provides_port_name)
253 assert(provides_port_name);
256 Ports::Port_var portref=Engines_DSC_interface::get_provides_port(provides_port_name, false);
257 port = my_superv_ports[provides_port_name]->p_ref;
258 } catch (const Engines::DSC::PortNotDefined&) {
259 throw PortNotDefined( LOC(OSS()<< "provides port "
260 << provides_port_name <<" does not exist."));
261 } catch (const Engines::DSC::PortNotConnected&) {
262 throw PortNotConnected( LOC(OSS()<< "provides port " << provides_port_name
263 << " is not connected."));
268 Superv_Component_i::get_port(uses_port *& port,
269 const char * uses_port_name)
272 assert(uses_port_name);
275 Engines::DSC::uses_port * portseq=Engines_DSC_i::get_uses_port(uses_port_name);
277 port = my_superv_ports[uses_port_name]->u_ref;
278 } catch (const Engines::DSC::PortNotDefined&) {
279 throw PortNotDefined( LOC(OSS()<< "uses port "
280 << uses_port_name <<" does not exist."));
281 } catch (const Engines::DSC::PortNotConnected&) {
282 throw PortNotConnected( LOC(OSS()<< "uses port " << uses_port_name
283 << " is not connected."));
290 Superv_Component_i::provides_port_changed(const char* provides_port_name,
292 const Engines::DSC::Message message)
294 my_superv_ports_it = my_superv_ports.find(provides_port_name);
295 if (my_superv_ports_it != my_superv_ports.end())
296 my_superv_ports[provides_port_name]->p_ref->provides_port_changed(connection_nbr,
301 Superv_Component_i::uses_port_changed(const char* uses_port_name,
302 Engines::DSC::uses_port * new_uses_port,
303 const Engines::DSC::Message message)
305 my_superv_ports_it = my_superv_ports.find(uses_port_name);
306 if (my_superv_ports_it != my_superv_ports.end())
307 my_superv_ports[uses_port_name]->u_ref->uses_port_changed(new Engines::DSC::uses_port(*new_uses_port),
309 //delete the copy made by the caller
310 delete new_uses_port;
316 Superv_Component_i::get_uses_port_names(std::vector<std::string> & port_names,
317 const std::string /*servicename*/) const
319 port_names.reserve(my_superv_ports.size());
321 superv_ports::const_iterator it;
323 for (it=my_superv_ports.begin(); it!=my_superv_ports.end();++it)
324 if( (*it).second->p_ref == NULL ) port_names.push_back((*it).first);
327 void Superv_Component_i::setTimeOut()
329 char* valenv=getenv("DSC_TIMEOUT");
332 std::istringstream iss(valenv);
336 Superv_Component_i::dscTimeOut=temp;
340 void Superv_Component_i::beginService(const char *serviceName)
342 Engines_DSC_i::beginService(serviceName);