Orocos Real-Time Toolkit  2.8.3
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RTT::mqueue::MQChannelElement< T > Class Template Reference

Implements the a ChannelElement using message queues. More...

#include <rtt/transports/mqueue/MQChannelElement.hpp>

Inheritance diagram for RTT::mqueue::MQChannelElement< T >:
RTT::base::ChannelElement< T > RTT::mqueue::MQSendRecv RTT::base::ChannelElementBase

Public Types

typedef T value_t
 
typedef boost::intrusive_ptr< ChannelElement< T > > shared_ptr
 
typedef boost::call_traits< T >::param_type param_t
 
typedef boost::call_traits< T >::reference reference_t
 

Public Member Functions

 MQChannelElement (base::PortInterface *port, types::TypeMarshaller const &transport, const ConnPolicy &policy, bool is_sender)
 Create a channel element for remote data exchange. More...
 
 ~MQChannelElement ()
 
virtual bool inputReady ()
 This is called by an input port when it is ready to receive data. More...
 
virtual bool data_sample (typename base::ChannelElement< T >::param_t sample)
 
bool signal ()
 Signal will cause a read-write cycle to transfer the data from the data/buffer element to the message queue and vice versa. More...
 
FlowStatus read (typename base::ChannelElement< T >::reference_t sample, bool copy_old_data)
 Read from the message queue. More...
 
bool write (typename base::ChannelElement< T >::param_t sample)
 Write to the message queue. More...
 
virtual bool isRemoteElement () const
 This function may be used to identify, if the current element uses a network transport, to send the data to the next Element in the logical chain. More...
 
virtual std::string getRemoteURI () const
 This function returns the URI of the next channel element in the logical chain. More...
 
virtual std::string getLocalURI () const
 This function return the URI of this element. More...
 
virtual std::string getElementName () const
 Returns the class name of this element. More...
 
shared_ptr getOutput ()
 
shared_ptr getInput ()
 
virtual bool data_sample (param_t sample)
 Provides a data sample to initialize this connection. More...
 
virtual value_t data_sample ()
 
virtual bool write (param_t sample)
 Writes a new sample on this connection. More...
 
virtual FlowStatus read (reference_t sample, bool copy_old_data)
 Reads a sample from the connection. More...
 
void removeInput ()
 Removes the input channel (if any). More...
 
ChannelElementBase::shared_ptr getInputEndPoint ()
 Returns the first input channel element of this connection. More...
 
ChannelElementBase::shared_ptr getOutputEndPoint ()
 Returns the last output channel element of this connection. More...
 
void setOutput (shared_ptr output)
 Sets the output of this channel element to output and sets the input of output to this. More...
 
virtual void clear ()
 Clears any data stored by the channel. More...
 
virtual void disconnect (bool forward)
 Performs a disconnection of this channel's endpoints. More...
 
virtual PortInterfacegetPort () const
 Gets the port this channel element is connected to. More...
 
virtual internal::ConnIDgetConnID () const
 Gets the Connection ID of this channel. More...
 
void setupStream (base::DataSourceBase::shared_ptr ds, base::PortInterface *port, ConnPolicy const &policy, bool is_sender)
 
void cleanupStream ()
 
virtual void mqNewSample (base::DataSourceBase::shared_ptr ds)
 Adapts the mq send/receive buffer size according to the data in mqdata_source, or the value set in mdata_size;. More...
 
virtual bool mqReady (base::DataSourceBase::shared_ptr ds, base::ChannelElementBase *chan)
 Works only in receive mode, waits for a new sample and adapts the receive buffer to match it's size. More...
 
bool mqRead (base::DataSourceBase::shared_ptr ds)
 Read from the message queue. More...
 
bool mqWrite (base::DataSourceBase::shared_ptr ds)
 Write to the message queue. More...
 

Protected Member Functions

void ref ()
 Increases the reference count. More...
 
void deref ()
 Decreases the reference count, and deletes the object if it is zero. More...
 

Protected Attributes

types::TypeMarshaller const & mtransport
 Transport marshaller used for size calculations and data updates. More...
 
void * marshaller_cookie
 A private blob that is returned by mtransport.getCookie(). More...
 
mqd_t mqdes
 MQueue file descriptor. More...
 
char * buf
 Send/Receive buffer. More...
 
bool mis_sender
 True if this object is a sender. More...
 
bool minit_done
 True if setupStream() was called, false after cleanupStream(). More...
 
int max_size
 The size of buf. More...
 
std::string mqname
 The name of the queue, as specified in the ConnPolicy when creating the stream, or self-calculated when that name was empty. More...
 
int mdata_size
 The size of the data, as specified in the ConnPolicy when creating the stream, or calculated using the transport when that size was zero. More...
 

Detailed Description

template<typename T>
class RTT::mqueue::MQChannelElement< T >

Implements the a ChannelElement using message queues.

It converts the C++ calls into MQ messages and vice versa.

Todo:

This class can be refactored into a base class with generic mqueue code and a subclass with type specific info.

This is an inspiration for a generic, transport independent channel element.

Definition at line 62 of file MQChannelElement.hpp.

Member Typedef Documentation

template<typename T>
typedef boost::call_traits<T>::param_type RTT::base::ChannelElement< T >::param_t
inherited

Definition at line 59 of file ChannelElement.hpp.

template<typename T>
typedef boost::call_traits<T>::reference RTT::base::ChannelElement< T >::reference_t
inherited

Definition at line 60 of file ChannelElement.hpp.

template<typename T>
typedef boost::intrusive_ptr< ChannelElement<T> > RTT::base::ChannelElement< T >::shared_ptr
inherited

Definition at line 58 of file ChannelElement.hpp.

template<typename T>
typedef T RTT::base::ChannelElement< T >::value_t
inherited

Definition at line 57 of file ChannelElement.hpp.

Constructor & Destructor Documentation

template<typename T>
RTT::mqueue::MQChannelElement< T >::MQChannelElement ( base::PortInterface port,
types::TypeMarshaller const &  transport,
const ConnPolicy policy,
bool  is_sender 
)
inline

Create a channel element for remote data exchange.

Parameters
transportThe type specific object that will be used to marshal the data.

Definition at line 74 of file MQChannelElement.hpp.

References RTT::mqueue::MQSendRecv::setupStream().

template<typename T>
RTT::mqueue::MQChannelElement< T >::~MQChannelElement ( )
inline

Definition at line 85 of file MQChannelElement.hpp.

References RTT::mqueue::MQSendRecv::cleanupStream().

Member Function Documentation

void MQSendRecv::cleanupStream ( )
inherited
void ChannelElementBase::clear ( )
virtualinherited

Clears any data stored by the channel.

It means that ChannelElement::read() will return false afterwards (provided that no new data has been written on the meantime of course)

By default, the channel element forwards the calls to its input

Reimplemented in RTT::internal::ChannelBufferElement< T >, and RTT::internal::ChannelDataElement< T >.

Definition at line 117 of file ChannelInterface.cpp.

References RTT::base::ChannelElementBase::getInput().

Referenced by RTT::internal::ChannelDataElement< T >::clear(), and RTT::internal::ChannelBufferElement< T >::clear().

template<typename T>
virtual bool RTT::base::ChannelElement< T >::data_sample ( param_t  sample)
inlinevirtualinherited

Provides a data sample to initialize this connection.

This is used before the first write() in order to inform this connection of the size of the data. As such enough storage space can be allocated before the actual writing begins.

Returns
false if an error occured that requires the channel to be invalidated.

Reimplemented in RTT::internal::ChannelBufferElement< T >, and RTT::internal::ChannelDataElement< T >.

Definition at line 82 of file ChannelElement.hpp.

References RTT::base::ChannelElement< T >::data_sample(), and RTT::base::ChannelElement< T >::getOutput().

Referenced by RTT::base::ChannelElement< T >::data_sample(), RTT::InputPort< T >::getDataSample(), and RTT::mqueue::MQChannelElement< T >::inputReady().

template<typename T>
virtual value_t RTT::base::ChannelElement< T >::data_sample ( )
inlinevirtualinherited
template<typename T>
virtual bool RTT::mqueue::MQChannelElement< T >::data_sample ( typename base::ChannelElement< T >::param_t  sample)
inlinevirtual
void ChannelElementBase::deref ( )
protectedinherited

Decreases the reference count, and deletes the object if it is zero.

Definition at line 165 of file ChannelInterface.cpp.

References oro_atomic_dec_and_test().

Referenced by RTT::corba::RemoteChannelElement< T >::_remove_ref(), and RTT::base::intrusive_ptr_release().

void ChannelElementBase::disconnect ( bool  forward)
virtualinherited

Performs a disconnection of this channel's endpoints.

If forward is true, then the disconnection is initiated by the input endpoint. Otherwise, it has been initiated by the output endpoint.

Reimplemented in RTT::corba::RemoteChannelElement< T >, RTT::internal::ConnOutputEndpoint< T >, and RTT::internal::ConnInputEndpoint< T >.

Definition at line 76 of file ChannelInterface.cpp.

References RTT::base::ChannelElementBase::getInput(), and RTT::base::ChannelElementBase::getOutput().

Referenced by RTT::internal::ConnInputEndpoint< T >::disconnect(), RTT::internal::ConnOutputEndpoint< T >::disconnect(), RTT::corba::RemoteChannelElement< T >::disconnect(), and RTT::corba::RemoteChannelElement< T >::remoteDisconnect().

internal::ConnID * ChannelElementBase::getConnID ( ) const
virtualinherited

Gets the Connection ID of this channel.

This is only stored in connection endpoints.

Returns
null if no ConnID is associated with this element.

Reimplemented in RTT::internal::ConnOutputEndpoint< T >, and RTT::internal::ConnInputEndpoint< T >.

Definition at line 136 of file ChannelInterface.cpp.

template<typename T>
virtual std::string RTT::mqueue::MQChannelElement< T >::getElementName ( ) const
inlinevirtual

Returns the class name of this element.

This is primary useful for special case handling in the connection tracking.

Returns
The name of the class of the ChannelElement

Reimplemented from RTT::base::ChannelElementBase.

Definition at line 197 of file MQChannelElement.hpp.

template<typename T>
shared_ptr RTT::base::ChannelElement< T >::getInput ( )
inlineinherited
ChannelElementBase::shared_ptr ChannelElementBase::getInputEndPoint ( )
inherited

Returns the first input channel element of this connection.

Will return the channel element the furthest away from the input port, or this if none.

Returns
getInput() ? getInput()->getInputEndPoint() : this

Definition at line 97 of file ChannelInterface.cpp.

References RTT::base::ChannelElementBase::getInput().

template<typename T>
virtual std::string RTT::mqueue::MQChannelElement< T >::getLocalURI ( ) const
inlinevirtual

This function return the URI of this element.

The URI must be unique.

Returns
URI of this element.

Reimplemented from RTT::base::ChannelElementBase.

Definition at line 187 of file MQChannelElement.hpp.

References RTT::base::ChannelElementBase::getInput(), RTT::base::ChannelElementBase::getLocalURI(), and RTT::mqueue::MQSendRecv::mqname.

template<typename T>
shared_ptr RTT::base::ChannelElement< T >::getOutput ( )
inlineinherited
ChannelElementBase::shared_ptr ChannelElementBase::getOutputEndPoint ( )
inherited

Returns the last output channel element of this connection.

Will return the channel element the furthest away from the output port, or this if none.

Returns
getOutput() ? getOutput()->getOutputEndPoint() : this

Definition at line 102 of file ChannelInterface.cpp.

References RTT::base::ChannelElementBase::getOutput().

PortInterface * ChannelElementBase::getPort ( ) const
virtualinherited

Gets the port this channel element is connected to.

Returns
null if no port is connected to this element, the port (or a proxy representing the port) otherwise.

Reimplemented in RTT::internal::ConnOutputEndpoint< T >, and RTT::internal::ConnInputEndpoint< T >.

Definition at line 132 of file ChannelInterface.cpp.

template<typename T>
virtual std::string RTT::mqueue::MQChannelElement< T >::getRemoteURI ( ) const
inlinevirtual

This function returns the URI of the next channel element in the logical chain.

The URI must be unique. E.g: In the local case output->getLocalURI() In the remote case the URI of the remote channel element.

Returns
URI of the next element.

Reimplemented from RTT::base::ChannelElementBase.

Definition at line 177 of file MQChannelElement.hpp.

References RTT::base::ChannelElementBase::getOutput(), RTT::base::ChannelElementBase::getRemoteURI(), and RTT::mqueue::MQSendRecv::mqname.

template<typename T>
virtual bool RTT::mqueue::MQChannelElement< T >::inputReady ( )
inlinevirtual

This is called by an input port when it is ready to receive data.

Each channel element has the responsibility to pass this notification on to the next, in the direction of the output.

Returns
false if a fatal connection failure was encountered and the channel needs to be destroyed.

Reimplemented from RTT::base::ChannelElementBase.

Definition at line 89 of file MQChannelElement.hpp.

References RTT::base::ChannelElement< T >::data_sample(), RTT::base::ChannelElement< T >::getOutput(), RTT::mqueue::MQSendRecv::mqReady(), and RTT::internal::ValueDataSource< T >::rvalue().

template<typename T>
virtual bool RTT::mqueue::MQChannelElement< T >::isRemoteElement ( ) const
inlinevirtual

This function may be used to identify, if the current element uses a network transport, to send the data to the next Element in the logical chain.

Returns
true if a network transport is used.

Reimplemented from RTT::base::ChannelElementBase.

Definition at line 172 of file MQChannelElement.hpp.

void MQSendRecv::mqNewSample ( base::DataSourceBase::shared_ptr  ds)
virtualinherited

Adapts the mq send/receive buffer size according to the data in mqdata_source, or the value set in mdata_size;.

Parameters
sample

Definition at line 188 of file MQSendRecv.cpp.

References RTT::mqueue::MQSendRecv::buf, RTT::types::TypeMarshaller::getSampleSize(), RTT::mqueue::MQSendRecv::max_size, RTT::mqueue::MQSendRecv::mdata_size, and RTT::mqueue::MQSendRecv::mtransport.

Referenced by RTT::mqueue::MQChannelElement< T >::data_sample().

bool MQSendRecv::mqRead ( base::DataSourceBase::shared_ptr  ds)
inherited

Read from the message queue.

Parameters
samplestores the resulting data sample.
Returns
true if an item could be read.

Definition at line 246 of file MQSendRecv.cpp.

References RTT::mqueue::MQSendRecv::buf, RTT::mqueue::MQSendRecv::marshaller_cookie, RTT::mqueue::MQSendRecv::max_size, RTT::mqueue::MQSendRecv::mqdes, RTT::mqueue::MQSendRecv::mtransport, and RTT::types::TypeMarshaller::updateFromBlob().

Referenced by RTT::mqueue::MQChannelElement< T >::signal().

bool MQSendRecv::mqReady ( base::DataSourceBase::shared_ptr  ds,
base::ChannelElementBase chan 
)
virtualinherited
bool MQSendRecv::mqWrite ( base::DataSourceBase::shared_ptr  ds)
inherited

Write to the message queue.

Parameters
dsthe data sample to write
is_data_sampletrue if the sample is used for initialization, false if it is a proper write
Returns
true if it could be sent.

Definition at line 261 of file MQSendRecv.cpp.

References RTT::mqueue::MQSendRecv::buf, RTT::Error, RTT::types::TypeMarshaller::fillBlob(), RTT::mqueue::MQSendRecv::marshaller_cookie, RTT::mqueue::MQSendRecv::max_size, RTT::mqueue::MQSendRecv::mqdes, and RTT::mqueue::MQSendRecv::mtransport.

Referenced by RTT::mqueue::MQChannelElement< T >::data_sample(), and RTT::mqueue::MQChannelElement< T >::write().

template<typename T>
virtual FlowStatus RTT::base::ChannelElement< T >::read ( reference_t  sample,
bool  copy_old_data 
)
inlinevirtualinherited

Reads a sample from the connection.

sample is a reference which will get updated if a sample is available. The method returns true if a sample was available, and false otherwise. If false is returned, then sample is not modified by the method

Reimplemented in RTT::internal::ChannelBufferElement< T >, and RTT::internal::ChannelDataElement< T >.

Definition at line 116 of file ChannelElement.hpp.

References RTT::base::ChannelElement< T >::getInput(), RTT::NoData, and RTT::base::ChannelElement< T >::read().

Referenced by RTT::base::ChannelElement< T >::read(), RTT::corba::RemoteChannelElement< T >::read(), and RTT::mqueue::MQChannelElement< T >::signal().

template<typename T>
FlowStatus RTT::mqueue::MQChannelElement< T >::read ( typename base::ChannelElement< T >::reference_t  sample,
bool  copy_old_data 
)
inline

Read from the message queue.

Parameters
samplestores the resulting data sample.
Returns
true if an item could be read.

Definition at line 156 of file MQChannelElement.hpp.

void ChannelElementBase::ref ( )
protectedinherited
void RTT::base::ChannelElementBase::removeInput ( )
inherited

Removes the input channel (if any).

This call may delete channels from memory.

void ChannelElementBase::setOutput ( shared_ptr  output)
inherited

Sets the output of this channel element to output and sets the input of output to this.

This implies that this channel element becomes the input of output. There is no setInput function since this function does both setting input and output of this and output.

Parameters
outputthe next element in chain.

Definition at line 69 of file ChannelInterface.cpp.

Referenced by RTT::internal::ConnFactory::buildBufferedChannelInput(), RTT::internal::ConnFactory::buildBufferedChannelOutput(), RTT::internal::ConnFactory::buildChannelInput(), and RTT::corba::CDataFlowInterface_i::deregisterChannel().

void MQSendRecv::setupStream ( base::DataSourceBase::shared_ptr  ds,
base::PortInterface port,
ConnPolicy const &  policy,
bool  is_sender 
)
inherited
template<typename T>
bool RTT::mqueue::MQChannelElement< T >::signal ( )
inlinevirtual

Signal will cause a read-write cycle to transfer the data from the data/buffer element to the message queue and vice versa.

Note: this virtual function is a bit abused. For a sending MQ, signal triggers a direct read on the data element. For a receiving MQ, signal is used by the dispatcher thread to provoque a read from the MQ and forward it to the next channel element.

In the sending case, signal could trigger a dispatcher thread that does the read/write cycle, but that seems only causing overhead. The receiving case must use a thread which blocks on all mq file descriptors.

Returns
true in case the forwarding could be done, false otherwise.

Reimplemented from RTT::base::ChannelElementBase.

Definition at line 132 of file MQChannelElement.hpp.

References RTT::base::ChannelElement< T >::getInput(), RTT::base::ChannelElement< T >::getOutput(), RTT::mqueue::MQSendRecv::mis_sender, RTT::mqueue::MQSendRecv::mqRead(), RTT::NewData, RTT::base::ChannelElement< T >::read(), RTT::internal::ValueDataSource< T >::rvalue(), RTT::internal::ValueDataSource< T >::set(), RTT::base::ChannelElement< T >::write(), and RTT::mqueue::MQChannelElement< T >::write().

template<typename T>
virtual bool RTT::base::ChannelElement< T >::write ( param_t  sample)
inlinevirtualinherited

Writes a new sample on this connection.

sample is the sample to write.

Returns
false if an error occured that requires the channel to be invalidated. In no ways it indicates that the sample has been received by the other side of the channel.

Reimplemented in RTT::internal::ChannelBufferElement< T >, and RTT::internal::ChannelDataElement< T >.

Definition at line 103 of file ChannelElement.hpp.

References RTT::base::ChannelElement< T >::getOutput(), and RTT::base::ChannelElement< T >::write().

Referenced by RTT::mqueue::MQChannelElement< T >::signal(), RTT::base::ChannelElement< T >::write(), and RTT::corba::RemoteChannelElement< T >::write().

template<typename T>
bool RTT::mqueue::MQChannelElement< T >::write ( typename base::ChannelElement< T >::param_t  sample)
inline

Write to the message queue.

Parameters
samplethe data sample to write
Returns
true if it could be sent.

Definition at line 166 of file MQChannelElement.hpp.

References RTT::mqueue::MQSendRecv::mqWrite(), and RTT::internal::LateConstReferenceDataSource< T >::setPointer().

Referenced by RTT::mqueue::MQChannelElement< T >::signal().

Member Data Documentation

char* RTT::mqueue::MQSendRecv::buf
protectedinherited

Send/Receive buffer.

It is initialized to the size of the value provided by the ConnPolicy or, if the policy has a zero data size, the sample given to setupStream

Its size is saved in max_size

Definition at line 79 of file MQSendRecv.hpp.

Referenced by RTT::mqueue::MQSendRecv::cleanupStream(), RTT::mqueue::MQSendRecv::mqNewSample(), RTT::mqueue::MQSendRecv::mqRead(), RTT::mqueue::MQSendRecv::mqReady(), RTT::mqueue::MQSendRecv::mqWrite(), and RTT::mqueue::MQSendRecv::setupStream().

void* RTT::mqueue::MQSendRecv::marshaller_cookie
protectedinherited

A private blob that is returned by mtransport.getCookie().

It is used by the marshallers if they need private internal data to do the marshalling

Definition at line 67 of file MQSendRecv.hpp.

Referenced by RTT::mqueue::MQSendRecv::cleanupStream(), RTT::mqueue::MQSendRecv::mqRead(), RTT::mqueue::MQSendRecv::mqReady(), RTT::mqueue::MQSendRecv::mqWrite(), and RTT::mqueue::MQSendRecv::setupStream().

int RTT::mqueue::MQSendRecv::max_size
protectedinherited
int RTT::mqueue::MQSendRecv::mdata_size
protectedinherited

The size of the data, as specified in the ConnPolicy when creating the stream, or calculated using the transport when that size was zero.

Definition at line 102 of file MQSendRecv.hpp.

Referenced by RTT::mqueue::MQSendRecv::mqNewSample(), and RTT::mqueue::MQSendRecv::setupStream().

bool RTT::mqueue::MQSendRecv::minit_done
protectedinherited

True if setupStream() was called, false after cleanupStream().

Definition at line 87 of file MQSendRecv.hpp.

Referenced by RTT::mqueue::MQSendRecv::cleanupStream(), and RTT::mqueue::MQSendRecv::mqReady().

bool RTT::mqueue::MQSendRecv::mis_sender
protectedinherited
mqd_t RTT::mqueue::MQSendRecv::mqdes
protectedinherited
std::string RTT::mqueue::MQSendRecv::mqname
protectedinherited

The name of the queue, as specified in the ConnPolicy when creating the stream, or self-calculated when that name was empty.

Definition at line 96 of file MQSendRecv.hpp.

Referenced by RTT::mqueue::MQSendRecv::cleanupStream(), RTT::mqueue::MQChannelElement< T >::getLocalURI(), RTT::mqueue::MQChannelElement< T >::getRemoteURI(), and RTT::mqueue::MQSendRecv::setupStream().

types::TypeMarshaller const& RTT::mqueue::MQSendRecv::mtransport
protectedinherited

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