Version: 9.16.0
Superv_Component_i.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
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.
10//
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.
15//
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
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23// File : Superv_Component_i.hxx
24// Author : André RIBES (EDF), Eric Fayolle (EDF)
25// Module : KERNEL
26//
27#ifndef _SUPERV_COMPONENT_I_HXX_
28#define _SUPERV_COMPONENT_I_HXX_
29
30#include "DSC_i.hxx"
31#include "base_port.hxx"
32#include "uses_port.hxx"
33#include "provides_port.hxx"
34#include "port_factory.hxx"
35
36#include "DSC_Exception.hxx"
37#include <vector>
38
52 public Engines_DSC_i,
53 virtual public POA_Engines::Superv_Component
54{
55public:
56 Superv_Component_i(CORBA::ORB_ptr orb,
57 PortableServer::POA_ptr poa,
58 PortableServer::ObjectId * contId,
59 const char *instanceName,
60 const char *interfaceName,
61 bool notif = false);
62 Superv_Component_i(CORBA::ORB_ptr orb,
63 PortableServer::POA_ptr poa,
64 Engines::Container_ptr container,
65 const char *instanceName,
66 const char *interfaceName,
67 bool notif = false,
68 bool regist = false );
69 virtual ~Superv_Component_i();
70
71 // Exceptions declarations.
72 // There are defined on the Superv_Component_i.cxx to avoid problems
73 // from dlopen.
83
88 {return NULL;}
89
93 virtual provides_port * create_provides_data_and_control_port(const char* /*port_type*/)
94 {return NULL;}
95
100 {return NULL;}
101
105 virtual uses_port * create_uses_data_and_control_port(const char* /*port_type*/)
106 {return NULL;}
107
118 virtual provides_port * create_provides_data_port(const std::string& port_fab_type);
119
120
131 virtual uses_port * create_uses_data_port(const std::string& port_fab_type);
132
141 virtual void add_port(const char * port_fab_type,
142 const char * port_type,
143 const char * port_name);
144
154 template < typename SpecificPortType >
155 SpecificPortType * add_port(const char * port_fab_type,
156 const char * port_type,
157 const char * port_name);
158
165 virtual void add_port(provides_port * port,
166 const char* provides_port_name);
167
174 virtual void add_port(uses_port * port,
175 const char* uses_port_name);
176
183 virtual void get_port(provides_port *& port,
184 const char* provides_port_name);
185
192 virtual void get_port(uses_port *& port,
193 const char* uses_port_name);
194
203 virtual void get_uses_port_names(std::vector<std::string> & port_names,
204 const std::string servicename="") const;
205
212 template <typename SpecificPortType >
213 SpecificPortType * get_port( const char * port_name);
214
218 virtual void provides_port_changed(const char* provides_port_name,
219 int connection_nbr,
220 const Engines::DSC::Message message);
221
225 virtual void uses_port_changed(const char* uses_port_name,
226 Engines::DSC::uses_port * new_uses_port,
227 const Engines::DSC::Message message);
228
229
238 static void register_factory(const std::string & factory_name,
239 port_factory * factory_ptr);
240
247 virtual port_factory * get_factory(const std::string & factory_name);
248
251 static long dscTimeOut;
252 static void setTimeOut();
253 void beginService(const char *serviceName);
254
255
256 // This method is implemented by default since it is a very specific usage.
257 // It also permits to not break compatibility with older components.
258 virtual CORBA::Boolean init_service_with_multiple(const char* /*service_name*/,
260 {
261 return true;
262 }
263
264private:
265 // Factory map
266 typedef std::map<std::string, port_factory*> factory_map_t;
268
269 /*-------------------------------------------------*/
270 // A Superv_Component port.
272 superv_port_t():u_ref(NULL),p_ref(NULL){};
274 {
275 if(u_ref)delete u_ref;
276 if(p_ref)
277 {
278 // do not delete CORBA servant : deactivate it and then call _remove_ref or delete
279 PortableServer::ServantBase* servant=dynamic_cast<PortableServer::ServantBase*>(p_ref);
280 if(servant)
281 {
282 PortableServer::POA_var poa =servant->_default_POA();
283 PortableServer::ObjectId_var oid = poa->servant_to_id(servant);
284 poa->deactivate_object(oid);
285 servant->_remove_ref();
286 }
287 }
288 };
289 // For uses ports.
291 // For provides ports.
293 };
294
295 typedef std::map<std::string, superv_port_t *> superv_ports;
296
297 /*-------------------------------------------------*/
298 /*-------------------------------------------------*/
299
301 superv_ports::iterator my_superv_ports_it;
302};
303
304
305
306template < typename SpecificPortType > SpecificPortType *
307Superv_Component_i::add_port(const char * port_fab_type,
308 const char * port_type,
309 const char * port_name)
310
311{
312 assert(port_fab_type);
313 assert(port_type);
314 assert(port_name);
315 SpecificPortType * retPort;
316
317 if (SALOME::VerbosityActivated())
318 std::cout << "---- Superv_Component_i::add_port : Mark 0 ---- " << port_name << "----" << std::endl;
319
320 std::string s_port_type(port_type);
321 if (s_port_type == "provides") {
323 add_port(port, port_name);
324 retPort = dynamic_cast<SpecificPortType *>(port);
325 if ( retPort == NULL ) { delete port;
326 throw BadCast( LOC("Can't cast to asked port type " ));
327 }
328 }
329 else if (s_port_type == "uses") {
330 uses_port * port = create_uses_data_port(port_fab_type);
331 add_port(port, port_name);
332 if (SALOME::VerbosityActivated())
333 {
334 std::cout << "---- Superv_Component_i::add_port : Mark 1 ---- " << port << "----" << std::endl;
335 std::cout << "---- Superv_Component_i::add_port : Mark 1 ---- get_repository_id()" << port->get_repository_id() << std::endl;
336 }
337 retPort = dynamic_cast<SpecificPortType *>(port);
338 if (SALOME::VerbosityActivated())
339 std::cout << "---- Superv_Component_i::add_port : Mark 2 ---- " << retPort << "----" << std::endl;
340
341 if ( retPort == NULL ) { delete port;
342 throw BadCast( LOC("Can't cast to asked port type " ));
343 }
344 }
345 else
346 throw BadType(LOC(OSS()<< "port_type must be either 'provides' either 'uses' not "
347 << port_type));
348
349 return retPort;
350}
351
352
353template <typename SpecificPortType > SpecificPortType *
354Superv_Component_i::get_port( const char * port_name)
355
356{
357 assert(port_name);
358
359 SpecificPortType * retPort;
360 base_port * port;
361
362 my_superv_ports_it = my_superv_ports.find(port_name);
364 {
365 throw PortNotDefined( LOC(OSS()<< "Port " << port_name <<" does not exist"));
366 }
367
368 superv_port_t * superv_port = my_superv_ports[port_name];
369 try {
370 if ( superv_port->p_ref != NULL ) {
371 port = superv_port->p_ref;
372 Ports::Port_var portref=Engines_DSC_interface::get_provides_port(port_name, false);
373 }
374 else if ( superv_port->u_ref != NULL ) {
375 port = superv_port->u_ref;
377 delete portseq;
378 } else {
379 throw UnexpectedState( LOC(OSS()<< "Internal Error superv_port struct is inconsistent "));
380
381 }
382 } catch (const Engines::DSC::PortNotDefined&) {
383 throw PortNotDefined( LOC(OSS()<< "port "
384 << port_name <<" does not exist."));
385 } catch (const Engines::DSC::PortNotConnected&) {
386 throw PortNotConnected( LOC(OSS()<< "port " << port_name
387 << " is not connected."));
388 }
389
390 retPort = dynamic_cast<SpecificPortType *>(port);
391 if ( retPort == NULL ) {
392 throw BadCast( LOC("Can't cast to required port type " ));
393 }
394
395 return retPort;
396}
397
398
399#endif
#define DSC_EXCEPTION(Derived)
Definition: DSC_Exception.hxx:161
#define LOC(message)
Definition: DSC_Exception.hxx:55
char * instanceName()
CORBA method: return name of the instance, unique in this Container.
Definition: Component_i.cxx:238
char * interfaceName()
CORBA method: return name of the component class.
Definition: Component_i.cxx:249
This class implements the interface Engines::DSC.
Definition: DSC_i.hxx:52
virtual Engines::DSC::uses_port * get_uses_port(const char *uses_port_name)
Definition: DSC_i.hxx:107
virtual Ports::Port_ptr get_provides_port(const char *provides_port_name, const CORBA::Boolean connection_error)
Definition: DSC_interface.cxx:109
port_type
Definition: DSC_interface.hxx:138
Class OSS is useful when streaming data through a function that expect a string as parameter.
Definition: DSC_Exception.hxx:65
This class implements DSC_User component.
Definition: Superv_Component_i.hxx:54
virtual void add_port(const char *port_fab_type, const char *port_type, const char *port_name)
Adds a port to the component.
Definition: Superv_Component_i.cxx:156
virtual void uses_port_changed(const char *uses_port_name, Engines::DSC::uses_port *new_uses_port, const Engines::DSC::Message message)
Definition: Superv_Component_i.cxx:301
virtual port_factory * get_factory(const std::string &factory_name)
Get a factory from the component.
Definition: Superv_Component_i.cxx:92
virtual CORBA::Boolean init_service_with_multiple(const char *, const Engines::Superv_Component::seq_multiple_param &)
Definition: Superv_Component_i.hxx:258
virtual void provides_port_changed(const char *provides_port_name, int connection_nbr, const Engines::DSC::Message message)
Definition: Superv_Component_i.cxx:290
virtual provides_port * create_provides_control_port()
Definition: Superv_Component_i.hxx:87
superv_ports::iterator my_superv_ports_it
Definition: Superv_Component_i.hxx:301
virtual ~Superv_Component_i()
Definition: Superv_Component_i.cxx:72
std::map< std::string, port_factory * > factory_map_t
Definition: Superv_Component_i.hxx:266
static void register_factory(const std::string &factory_name, port_factory *factory_ptr)
Add a factory the component.
Definition: Superv_Component_i.cxx:80
static void setTimeOut()
Definition: Superv_Component_i.cxx:327
virtual uses_port * create_uses_control_port()
Definition: Superv_Component_i.hxx:99
static long dscTimeOut
Definition: Superv_Component_i.hxx:251
void beginService(const char *serviceName)
Definition: Superv_Component_i.cxx:340
static factory_map_t _factory_map
Definition: Superv_Component_i.hxx:267
virtual uses_port * create_uses_data_and_control_port(const char *)
Definition: Superv_Component_i.hxx:105
virtual void get_uses_port_names(std::vector< std::string > &port_names, const std::string servicename="") const
Gets the list of the ports of a service.
Definition: Superv_Component_i.cxx:316
Superv_Component_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId *contId, const char *instanceName, const char *interfaceName, bool notif=false)
Definition: Superv_Component_i.cxx:43
virtual provides_port * create_provides_data_and_control_port(const char *)
Definition: Superv_Component_i.hxx:93
virtual provides_port * create_provides_data_port(const std::string &port_fab_type)
This method permits to create a provides port provided by the platform.
Definition: Superv_Component_i.cxx:106
virtual uses_port * create_uses_data_port(const std::string &port_fab_type)
This method permits to create a uses port provided by the platform.
Definition: Superv_Component_i.cxx:131
std::map< std::string, superv_port_t * > superv_ports
Definition: Superv_Component_i.hxx:295
superv_ports my_superv_ports
Definition: Superv_Component_i.hxx:300
virtual void get_port(provides_port *&port, const char *provides_port_name)
Gets the provides port already added in the component.
Definition: Superv_Component_i.cxx:249
Definition: base_port.hxx:36
This class is an abstract for all the DSC ports factories that have to be registered into the compone...
Definition: port_factory.hxx:37
This class implements a DSC_User provides C++ port.
Definition: provides_port.hxx:41
This class implements a DSC_User uses C++ port.
Definition: uses_port.hxx:44
This exception is raised when you try to use a port that is not connected.
Definition: DSC_Engines.idl:90
This exception is raised when a port is used before it is added to the component.
Definition: DSC_Engines.idl:84
Message
This enumeration is used when the connection of a port (uses or provides) is changed.
Definition: DSC_Engines.idl:79
sequence< Ports::Port > uses_port
a uses port
Definition: DSC_Engines.idl:73
sequence< multiple_param > seq_multiple_param
Definition: DSC_Engines.idl:365
poa
Definition: SALOME_ContainerPy.py:377
container
Definition: TestComponentPy.py:63
port
Definition: salome_instance.py:114
orb
Definition: salome.py:122
Definition: Superv_Component_i.hxx:76
Definition: Superv_Component_i.hxx:74
Definition: Superv_Component_i.hxx:82
Definition: Superv_Component_i.hxx:75
Definition: Superv_Component_i.hxx:81
Definition: Superv_Component_i.hxx:78
Definition: Superv_Component_i.hxx:80
Definition: Superv_Component_i.hxx:79
Definition: Superv_Component_i.hxx:77
Definition: Superv_Component_i.hxx:271
uses_port * u_ref
Definition: Superv_Component_i.hxx:290
provides_port * p_ref
Definition: Superv_Component_i.hxx:292
~superv_port_t()
Definition: Superv_Component_i.hxx:273
superv_port_t()
Definition: Superv_Component_i.hxx:272