Orocos Real-Time Toolkit
2.8.3
|
Manages connections between ports. More...
#include <rtt/internal/ConnectionManager.hpp>
Public Types | |
typedef boost::tuple< boost::shared_ptr< ConnID >, base::ChannelElementBase::shared_ptr, ConnPolicy > | ChannelDescriptor |
A Channel (= connection) is described by an opaque ConnID object, the first element of the channel and the policy of the channel. More... | |
Public Member Functions | |
ConnectionManager (base::PortInterface *port) | |
Creates a connection manager to manage the connections of port. More... | |
~ConnectionManager () | |
void | addConnection (ConnID *port_id, base::ChannelElementBase::shared_ptr channel_input, ConnPolicy policy) |
Helper method for port-to-port connection establishment. More... | |
bool | removeConnection (ConnID *port_id) |
void | disconnect () |
Disconnect all connections. More... | |
bool | connected () const |
Returns true if there is at least one channel registered in this port's list of outputs. More... | |
bool | disconnect (base::PortInterface *port) |
Removes the channel that connects this port to port . More... | |
template<typename Pred > | |
bool | delete_if (Pred pred) |
template<typename Pred > | |
void | select_reader_channel (Pred pred, bool copy_old_data) |
Selects a connection as the current channel if pred(connection) is true. More... | |
template<typename Pred > | |
ChannelDescriptor * | find_if (Pred pred, bool copy_old_data) |
bool | isSingleConnection () const |
Returns true if this manager manages only one connection. More... | |
base::ChannelElementBase * | getCurrentChannel () const |
Returns the first added channel or if select_if was called, the selected channel. More... | |
std::list< ChannelDescriptor > | getChannels () const |
Returns a list of all channels managed by this object. More... | |
void | clear () |
Clears (removes) all data in the manager's connections. More... | |
void | lock () const |
Locks the mutex protecting the channel element list. More... | |
void | unlock () const |
Unlocks the mutex protecting the channel element list. More... | |
Protected Member Functions | |
void | updateCurrentChannel (bool reset_current) |
bool | findMatchingPort (ConnID const *conn_id, ChannelDescriptor const &descriptor) |
Helper method for disconnect(PortInterface*) More... | |
bool | eraseConnection (ChannelDescriptor &descriptor) |
Helper method for disconnect() More... | |
Protected Attributes | |
os::Mutex | connection_resize_mtx |
os::Mutex for when it is needed to resize the connections list More... | |
base::PortInterface * | mport |
The port for which we manage connections. More... | |
std::list< ChannelDescriptor > | connections |
A list of all our connections. More... | |
ChannelDescriptor * | cur_channel |
Optimisation in case only one channel is to be managed. More... | |
RTT::os::Mutex | connection_lock |
Lock that should be taken before the list of connections is accessed or modified. More... | |
Manages connections between ports.
This class is used for input and output ports in order to manage their channels. TODO: use the mutex lock !!!
Definition at line 76 of file ConnectionManager.hpp.
typedef boost::tuple<boost::shared_ptr<ConnID>, base::ChannelElementBase::shared_ptr, ConnPolicy> RTT::internal::ConnectionManager::ChannelDescriptor |
A Channel (= connection) is described by an opaque ConnID object, the first element of the channel and the policy of the channel.
The policy is only given for read-only access, modifying it will not have any effect on the connection.
Definition at line 85 of file ConnectionManager.hpp.
RTT::internal::ConnectionManager::ConnectionManager | ( | base::PortInterface * | port | ) |
Creates a connection manager to manage the connections of port.
port | The port whose connections to manage. |
Definition at line 61 of file ConnectionManager.cpp.
RTT::internal::ConnectionManager::~ConnectionManager | ( | ) |
Definition at line 67 of file ConnectionManager.cpp.
References disconnect().
void RTT::internal::ConnectionManager::addConnection | ( | ConnID * | port_id, |
base::ChannelElementBase::shared_ptr | channel_input, | ||
ConnPolicy | policy | ||
) |
Helper method for port-to-port connection establishment.
This is the last step in adding a connection to an output port and also validates if the connection is sound.
Definition at line 130 of file ConnectionManager.cpp.
References connection_lock, connections, cur_channel, and lock().
Referenced by RTT::base::OutputPortInterface::addConnection().
void RTT::internal::ConnectionManager::clear | ( | ) |
Clears (removes) all data in the manager's connections.
After this call, all channels will return NoData, until new data is written.
Definition at line 80 of file ConnectionManager.cpp.
References RTT::internal::clearChannel(), connection_lock, connections, and lock().
Referenced by RTT::internal::clearChannel().
bool RTT::internal::ConnectionManager::connected | ( | ) | const |
Returns true if there is at least one channel registered in this port's list of outputs.
Definition at line 126 of file ConnectionManager.cpp.
References connections.
Referenced by RTT::base::OutputPortInterface::connected().
|
inline |
Definition at line 118 of file ConnectionManager.hpp.
Referenced by RTT::OutputPort< T >::setDataSample(), and RTT::OutputPort< T >::write().
void RTT::internal::ConnectionManager::disconnect | ( | ) |
Disconnect all connections.
Definition at line 115 of file ConnectionManager.cpp.
References connection_lock, connections, cur_channel, eraseConnection(), and lock().
Referenced by RTT::base::OutputPortInterface::disconnect(), eraseConnection(), removeConnection(), ~ConnectionManager(), and RTT::base::OutputPortInterface::~OutputPortInterface().
bool RTT::internal::ConnectionManager::disconnect | ( | base::PortInterface * | port | ) |
Removes the channel that connects this port to port
.
Definition at line 98 of file ConnectionManager.cpp.
References RTT::base::PortInterface::getPortID(), and removeConnection().
|
protected |
Helper method for disconnect()
Unconditionally removes the given connection and return true
Definition at line 104 of file ConnectionManager.cpp.
References disconnect(), and mport.
Referenced by disconnect().
|
inline |
Definition at line 157 of file ConnectionManager.hpp.
|
protected |
Helper method for disconnect(PortInterface*)
This method removes the channel listed in descriptor
from the list of output channels if port
has the same id that the one listed in descriptor
.
Definition at line 85 of file ConnectionManager.cpp.
References RTT::internal::ConnID::isSameID().
Referenced by removeConnection().
|
inline |
Returns a list of all channels managed by this object.
Definition at line 193 of file ConnectionManager.hpp.
|
inline |
Returns the first added channel or if select_if was called, the selected channel.
Definition at line 186 of file ConnectionManager.hpp.
Referenced by RTT::InputPort< T >::getDataSample().
|
inline |
Returns true if this manager manages only one connection.
Definition at line 179 of file ConnectionManager.hpp.
|
inline |
Locks the mutex protecting the channel element list.
Definition at line 207 of file ConnectionManager.hpp.
Referenced by addConnection(), clear(), disconnect(), and removeConnection().
bool RTT::internal::ConnectionManager::removeConnection | ( | ConnID * | port_id | ) |
Definition at line 139 of file ConnectionManager.cpp.
References connection_lock, connections, cur_channel, disconnect(), findMatchingPort(), lock(), mport, and updateCurrentChannel().
Referenced by disconnect(), and RTT::base::OutputPortInterface::removeConnection().
|
inline |
Selects a connection as the current channel if pred(connection) is true.
It will first check the current channel ( getCurrentChannel() ), if that does not satisfy pred, iterate over all connections. If none satisfy pred, the current channel remains unchanged.
pred |
Definition at line 143 of file ConnectionManager.hpp.
Referenced by RTT::InputPort< T >::read().
|
inline |
Unlocks the mutex protecting the channel element list.
Definition at line 214 of file ConnectionManager.hpp.
|
protected |
Definition at line 90 of file ConnectionManager.cpp.
References connections, and cur_channel.
Referenced by removeConnection().
|
mutableprotected |
Lock that should be taken before the list of connections is accessed or modified.
Definition at line 260 of file ConnectionManager.hpp.
Referenced by addConnection(), clear(), disconnect(), and removeConnection().
|
protected |
os::Mutex for when it is needed to resize the connections list
Definition at line 238 of file ConnectionManager.hpp.
|
protected |
A list of all our connections.
Only non-null if two or more connections were added.
Definition at line 249 of file ConnectionManager.hpp.
Referenced by addConnection(), clear(), connected(), disconnect(), removeConnection(), and updateCurrentChannel().
|
protected |
Optimisation in case only one channel is to be managed.
Definition at line 254 of file ConnectionManager.hpp.
Referenced by addConnection(), disconnect(), removeConnection(), and updateCurrentChannel().
|
protected |
The port for which we manage connections.
Definition at line 243 of file ConnectionManager.hpp.
Referenced by eraseConnection(), and removeConnection().