Version: 9.15.0
ConnectionManager Class Reference

This class implements the interface Engines::ConnectionManager. It is used to make connections between CALCIUM ports. More...

#include <ConnectionManager.hxx>

Collaboration diagram for ConnectionManager:

Classes

struct  connection_infos
 

Public Types

typedef short connectionId
 

Public Member Functions

 ConnectionManager ()
 
 ~ConnectionManager ()
 
ConnectionManager::connectionId connect (Engines::DSC_ptr uses_component, const char *uses_port_name, Engines::DSC_ptr provides_component, const char *provides_port_name)
 
void disconnect (ConnectionManager::connectionId id, Engines::DSC::Message message)
 
void ShutdownWithExit ()
 

Private Types

typedef std::map< Engines::ConnectionManager::connectionId, connection_infos * > ids_type
 
typedef std::map< Engines::ConnectionManager::connectionId, connection_infos * >::iterator ids_it_type
 

Private Attributes

ids_type _ids
 
int _current_id
 
std::mutex _mutex
 

Detailed Description

This class implements the interface Engines::ConnectionManager. It is used to make connections between CALCIUM ports.

Definition at line 38 of file ConnectionManager.hxx.

Member Typedef Documentation

◆ connectionId

Definition at line 44 of file ConnectionManager.hxx.

◆ ids_it_type

typedef std::map<Engines::ConnectionManager::connectionId, connection_infos *>::iterator ConnectionManager::ids_it_type
private

Definition at line 78 of file ConnectionManager.hxx.

◆ ids_type

typedef std::map<Engines::ConnectionManager::connectionId, connection_infos *> ConnectionManager::ids_type
private

Definition at line 76 of file ConnectionManager.hxx.

Constructor & Destructor Documentation

◆ ConnectionManager()

ConnectionManager::ConnectionManager ( )

Definition at line 23 of file ConnectionManager.cxx.

24 : _ids()
25 , _current_id(0)
26 , _mutex()
27 {
28 }

◆ ~ConnectionManager()

ConnectionManager::~ConnectionManager ( )

Definition at line 30 of file ConnectionManager.cxx.

31 {
32 }

Member Function Documentation

◆ connect()

ConnectionManager::connectionId ConnectionManager::connect ( Engines::DSC_ptr  uses_component,
const char *  uses_port_name,
Engines::DSC_ptr  provides_component,
const char *  provides_port_name 
)

connect two CALCIUM ports of two components.

Definition at line 35 of file ConnectionManager.cxx.

39 {
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);
45 
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);
53 
54  // Creating a new connection id.
56  _current_id += 1;
57  // Adding the new connection into the map.
58  _ids[rtn_id] = infos;
59 
60  return rtn_id;
61 }

References _current_id, _ids, _mutex, ConnectionManager::connection_infos::provides_component, ConnectionManager::connection_infos::provides_port, ConnectionManager::connection_infos::provides_port_name, ConnectionManager::connection_infos::uses_component, and ConnectionManager::connection_infos::uses_port_name.

Referenced by gui.browser_catalog.Browser::init().

◆ disconnect()

void ConnectionManager::disconnect ( ConnectionManager::connectionId  id,
Engines::DSC::Message  message 
)

releases a connection performed with ConnectionManager::connect.

Definition at line 64 of file ConnectionManager.cxx.

66 {
67  std::unique_lock<std::mutex> lock(_mutex);
68  int err=0;
69  // Connection id exist ?
70  ids_it_type ids_it = _ids.find(id);
71  if (ids_it == _ids.end())
72  return;
73 
74  // TODO
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;
78  try
79  {
80  infos->provides_component->disconnect_provides_port(infos->provides_port_name.c_str(), message);
81  }
82  catch(CORBA::SystemException& ex)
83  {
84  std::cerr << "Problem in disconnect(CORBA::SystemException) provides port: " << infos->provides_port_name.c_str() << std::endl;
85  err=1;
86  }
87  try
88  {
89  infos->uses_component->disconnect_uses_port(infos->uses_port_name.c_str(),
90  infos->provides_port, message);
91  }
92  catch(CORBA::SystemException& ex)
93  {
94  std::cerr << "Problem in disconnect(CORBA::SystemException) uses port: " << infos->uses_port_name.c_str() << std::endl;
95  err=1;
96  }
97  delete infos;
98  _ids.erase(id);
99 
100  if(err)
101  throw Engines::DSC::BadPortReference();
102 }
std::map< Engines::ConnectionManager::connectionId, connection_infos * >::iterator ids_it_type

References _ids, _mutex, testCppPluginInvokation::ex, ConnectionManager::connection_infos::provides_component, ConnectionManager::connection_infos::provides_port, ConnectionManager::connection_infos::provides_port_name, ConnectionManager::connection_infos::uses_component, and ConnectionManager::connection_infos::uses_port_name.

Referenced by ShutdownWithExit().

◆ ShutdownWithExit()

void ConnectionManager::ShutdownWithExit ( )

Shutdown the ConnectionManager process.

Definition at line 105 of file ConnectionManager.cxx.

106 {
107  ids_it_type ids_it = _ids.begin();
108  while(ids_it != _ids.end())
109  {
110  disconnect(ids_it->first, Engines::DSC::RemovingConnection);
111  ids_it = _ids.begin();
112  }
113 }
void disconnect(ConnectionManager::connectionId id, Engines::DSC::Message message)

References _ids, and disconnect().

Member Data Documentation

◆ _current_id

int ConnectionManager::_current_id
private

Definition at line 81 of file ConnectionManager.hxx.

Referenced by connect().

◆ _ids

ids_type ConnectionManager::_ids
private

Definition at line 80 of file ConnectionManager.hxx.

Referenced by connect(), disconnect(), and ShutdownWithExit().

◆ _mutex

std::mutex ConnectionManager::_mutex
private

Definition at line 82 of file ConnectionManager.hxx.

Referenced by connect(), and disconnect().


The documentation for this class was generated from the following files: