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

A component's data input port. More...

#include <rtt/InputPort.hpp>

Inheritance diagram for RTT::InputPort< T >:
RTT::base::InputPortInterface RTT::base::PortInterface

Public Member Functions

 InputPort (std::string const &name="unnamed", ConnPolicy const &default_policy=ConnPolicy())
 
virtual ~InputPort ()
 
FlowStatus read (base::DataSourceBase::shared_ptr source)
 
FlowStatus read (base::DataSourceBase::shared_ptr source, bool copy_old_data)
 Reads the port and updates the value hold by the given data source. More...
 
FlowStatus readNewest (base::DataSourceBase::shared_ptr source, bool copy_old_data=true)
 Read all new samples that are available on this port, and returns the last one. More...
 
FlowStatus read (typename base::ChannelElement< T >::reference_t sample)
 
FlowStatus read (typename base::ChannelElement< T >::reference_t sample, bool copy_old_data)
 Reads a sample from the connection. More...
 
FlowStatus readNewest (typename base::ChannelElement< T >::reference_t sample, bool copy_old_data=true)
 Read all new samples that are available on this port, and returns the last one. More...
 
void getDataSample (T &sample)
 Get a sample of the data on this port, without actually reading the port's data. More...
 
virtual const types::TypeInfogetTypeInfo () const
 Returns the types::TypeInfo object for the port's type. More...
 
virtual base::PortInterfaceclone () const
 Create a clone of this port with the same name. More...
 
virtual base::PortInterfaceantiClone () const
 Create the anti-clone (inverse port) of this port with the same name A port for reading will return a new port for writing and vice versa. More...
 
base::DataSourceBasegetDataSource ()
 Returns a base::DataSourceBase interface to read this port. More...
 
virtual bool createStream (ConnPolicy const &policy)
 Creates a data stream from or to this port using connection-less transports. More...
 
virtual ServicecreatePortObject ()
 Create accessor Object for this Port, for addition to a TaskContext Object interface. More...
 
void clear ()
 Clears the connection. More...
 
ConnPolicy getDefaultPolicy () const
 
virtual bool addConnection (internal::ConnID *port_id, ChannelElementBase::shared_ptr channel_input, ConnPolicy const &policy)
 Adds a user created connection to this port. More...
 
virtual bool removeConnection (internal::ConnID *cid)
 Removes the input channel. More...
 
virtual void disconnect ()
 Removes any connection that either go to or come from this port and removes all callbacks and cleans up the NewDataOnPortEvent. More...
 
virtual bool disconnect (PortInterface *port)
 Removes the channel that connects this port to port. More...
 
virtual bool connected () const
 Returns true if this port is connected. More...
 
virtual bool channelReady (base::ChannelElementBase::shared_ptr channel, ConnPolicy const &policy)
 Call this to indicate that the connection leading to this port is ready to use. More...
 
void signalInterface (bool true_false)
 When called with true, will signal the DataFlowInterface when new data is available. More...
 
virtual bool connectTo (PortInterface *other, ConnPolicy const &policy)
 Connects this port with other, using the given policy. More...
 
virtual bool connectTo (PortInterface *other)
 Connects this port with other, using the default policy of the input. More...
 
virtual const internal::ConnectionManagergetManager () const
 Returns the connection manager of this port (if any). More...
 
virtual base::ChannelElementBase::shared_ptr buildRemoteChannelOutput (base::OutputPortInterface &output_port, types::TypeInfo const *type_info, base::InputPortInterface &input, const ConnPolicy &policy)
 This method is analoguous to the static ConnFactory::buildChannelOutput. More...
 
virtual internal::ConnIDgetPortID () const
 Returns the identity of this port in a ConnID object. More...
 
const std::string & getName () const
 Get the name of this Port. More...
 
bool setName (const std::string &name)
 Change the name of this unconnected Port. More...
 
const std::string & getDescription () const
 Get the documentation of this port. More...
 
PortInterfacedoc (const std::string &desc)
 Set the documentation of this port. More...
 
virtual bool isLocal () const
 Returns true if this port is located on this process, and false otherwise. More...
 
virtual int serverProtocol () const
 Returns the protocol over which this port can be accessed. More...
 
void setInterface (DataFlowInterface *iface)
 Once a port is added to a DataFlowInterface, it gets a pointer to that interface. More...
 
DataFlowInterfacegetInterface () const
 Returns the DataFlowInterface this port belongs to or null if it was not added to such an interface. More...
 

Protected Member Functions

void signal ()
 The ConnOutputEndpoint signals that new data is available. More...
 

Protected Attributes

internal::ConnectionManager cmanager
 
ConnPolicy default_policy
 
bool msignal_interface
 
DataFlowInterfaceiface
 

Friends

class internal::ConnOutputEndpoint< T >
 

Detailed Description

template<typename T>
class RTT::InputPort< T >

A component's data input port.

An Orocos input port is used to receive data samples from a distant publisher. The InputPort is read() and returns true if a sample is available.

Ideally, your algorithm should not assume a certain connection policy being used from output to input. So it should work on data connections and buffer connections.

Definition at line 63 of file InputPort.hpp.

Constructor & Destructor Documentation

template<typename T>
RTT::InputPort< T >::InputPort ( std::string const &  name = "unnamed",
ConnPolicy const &  default_policy = ConnPolicy() 
)
inline

Definition at line 96 of file InputPort.hpp.

template<typename T>
virtual RTT::InputPort< T >::~InputPort ( )
inlinevirtual

Definition at line 100 of file InputPort.hpp.

References RTT::base::InputPortInterface::disconnect().

Member Function Documentation

bool InputPortInterface::addConnection ( internal::ConnID cid,
ChannelElementBase::shared_ptr  channel_input,
ConnPolicy const &  policy 
)
virtualinherited

Adds a user created connection to this port.

This is an advanced method, prefer to use connectTo and createStream.

Implements RTT::base::PortInterface.

Reimplemented in RTT::corba::RemoteInputPort, and RTT::corba::RemotePort< base::InputPortInterface >.

Definition at line 100 of file InputPortInterface.cpp.

template<typename T>
virtual base::PortInterface* RTT::InputPort< T >::antiClone ( ) const
inlinevirtual

Create the anti-clone (inverse port) of this port with the same name A port for reading will return a new port for writing and vice versa.

Implements RTT::base::PortInterface.

Definition at line 207 of file InputPort.hpp.

References RTT::base::PortInterface::getName().

base::ChannelElementBase::shared_ptr InputPortInterface::buildRemoteChannelOutput ( base::OutputPortInterface output_port,
types::TypeInfo const *  type_info,
base::InputPortInterface input,
const ConnPolicy policy 
)
virtualinherited

This method is analoguous to the static ConnFactory::buildChannelOutput.

It is provided for remote connection building: for these connections, no template can be used and therefore the connection setup should be done based on the types::TypeInfo object

Reimplemented in RTT::corba::RemoteInputPort.

Definition at line 170 of file InputPortInterface.cpp.

bool InputPortInterface::channelReady ( base::ChannelElementBase::shared_ptr  channel,
RTT::ConnPolicy const &  policy 
)
virtualinherited

Call this to indicate that the connection leading to this port is ready to use.

The input port will check its channel elements by sending an inputReady() message. If this succeeds, this function returns true and the input port is ready to use (this->connected() == true). If sending inputReady() returns failure, this method returns false and the connection is aborted (this->connected() == false).

Reimplemented in RTT::corba::RemoteInputPort.

Definition at line 107 of file InputPortInterface.cpp.

References RTT::Error.

Referenced by RTT::internal::ConnFactory::createAndCheckConnection(), RTT::internal::ConnFactory::createAndCheckStream(), and RTT::corba::CDataFlowInterface_i::deregisterChannel().

void InputPortInterface::clear ( )
inherited

Clears the connection.

After call to read() will return false after clear() has been called

Definition at line 155 of file InputPortInterface.cpp.

Referenced by RTT::InputPort< T >::createPortObject(), and RTT::internal::InputPortSource< T >::reset().

template<typename T>
virtual base::PortInterface* RTT::InputPort< T >::clone ( ) const
inlinevirtual

Create a clone of this port with the same name.

Implements RTT::base::PortInterface.

Definition at line 199 of file InputPort.hpp.

References RTT::base::PortInterface::getName().

bool InputPortInterface::connected ( ) const
virtualinherited

Returns true if this port is connected.

Implements RTT::base::PortInterface.

Reimplemented in RTT::corba::RemotePort< base::InputPortInterface >.

Definition at line 152 of file InputPortInterface.cpp.

bool InputPortInterface::connectTo ( PortInterface other,
ConnPolicy const &  policy 
)
virtualinherited

Connects this port with other, using the given policy.

Unlike OutputPortInterface::createConnection, other can be the write port and this the read port.

Returns
true on success, false on failure

Implements RTT::base::PortInterface.

Definition at line 85 of file InputPortInterface.cpp.

References RTT::base::OutputPortInterface::createConnection(), RTT::Error, and RTT::base::PortInterface::getName().

bool InputPortInterface::connectTo ( PortInterface other)
virtualinherited

Connects this port with other, using the default policy of the input.

Unlike OutputPortInterface::createConnection, other can be the write port and this the read port.

Returns
true on success, false on failure

Implements RTT::base::PortInterface.

Definition at line 95 of file InputPortInterface.cpp.

template<typename T>
virtual Service* RTT::InputPort< T >::createPortObject ( )
inlinevirtual

Create accessor Object for this Port, for addition to a TaskContext Object interface.

Reimplemented from RTT::base::PortInterface.

Definition at line 228 of file InputPort.hpp.

References RTT::base::InputPortInterface::clear(), RTT::base::PortInterface::createPortObject(), and RTT::base::PortInterface::doc().

template<typename T>
virtual bool RTT::InputPort< T >::createStream ( ConnPolicy const &  policy)
inlinevirtual

Creates a data stream from or to this port using connection-less transports.

Typically, policy.transport and policy.name_id must be properly filled in such that the data stream can be set up and input and output port can find each other. You need to call this method on two ports (input and output) using the same transport and (probably) same name_id.

Parameters
policyThe connection policy describing how the stream must be set up.

Implements RTT::base::PortInterface.

Definition at line 218 of file InputPort.hpp.

References RTT::internal::ConnFactory::createStream().

void InputPortInterface::disconnect ( )
virtualinherited

Removes any connection that either go to or come from this port and removes all callbacks and cleans up the NewDataOnPortEvent.

Implements RTT::base::PortInterface.

Reimplemented in RTT::corba::RemotePort< base::InputPortInterface >.

Definition at line 160 of file InputPortInterface.cpp.

Referenced by RTT::InputPort< T >::~InputPort().

bool InputPortInterface::disconnect ( PortInterface port)
virtualinherited

Removes the channel that connects this port to port.

All other ports or callbacks remain unaffected.

Implements RTT::base::PortInterface.

Reimplemented in RTT::corba::RemoteInputPort.

Definition at line 165 of file InputPortInterface.cpp.

PortInterface & PortInterface::doc ( const std::string &  desc)
inherited

Set the documentation of this port.

Parameters
descThe description of the port
Returns
a reference to this object.

Definition at line 60 of file PortInterface.cpp.

References RTT::base::PortInterface::iface, and RTT::DataFlowInterface::setPortDescription().

Referenced by RTT::InputPort< T >::createPortObject().

template<typename T>
void RTT::InputPort< T >::getDataSample ( T &  sample)
inline

Get a sample of the data on this port, without actually reading the port's data.

It's the complement of OutputPort::setDataSample() and serves to retrieve the size of a variable sized data type T. Returns default T if !connected() or if the OutputPort did not use setDataSample(). Returns an example T otherwise. In case multiple inputs are connected to this port a sample from the currently read connection will be returned.

Definition at line 184 of file InputPort.hpp.

References RTT::base::InputPortInterface::cmanager, RTT::base::ChannelElement< T >::data_sample(), and RTT::internal::ConnectionManager::getCurrentChannel().

Referenced by RTT::internal::InputPortSource< T >::InputPortSource().

template<typename T>
base::DataSourceBase* RTT::InputPort< T >::getDataSource ( )
inlinevirtual

Returns a base::DataSourceBase interface to read this port.

The returned data source is always a new object.

Implements RTT::base::InputPortInterface.

Definition at line 213 of file InputPort.hpp.

ConnPolicy InputPortInterface::getDefaultPolicy ( ) const
inherited
const std::string& RTT::base::PortInterface::getDescription ( ) const
inlineinherited

Get the documentation of this port.

Returns
A description.

Definition at line 91 of file PortInterface.hpp.

DataFlowInterface * PortInterface::getInterface ( ) const
inherited

Returns the DataFlowInterface this port belongs to or null if it was not added to such an interface.

Definition at line 95 of file PortInterface.cpp.

References RTT::base::PortInterface::iface.

Referenced by RTT::corba::RemoteInputPort::buildRemoteChannelOutput(), RTT::corba::RemoteOutputPort::createConnection(), and RTT::mqueue::MQSendRecv::setupStream().

virtual const internal::ConnectionManager* RTT::base::InputPortInterface::getManager ( ) const
inlinevirtualinherited

Returns the connection manager of this port (if any).

This method provides access to the internals of this port in order to allow connection introspection.

Returns
null if no such manager is available, or the manager otherwise.
See also
ConnectionManager::getChannels() for a list of all connections of this port.

Implements RTT::base::PortInterface.

Definition at line 159 of file InputPortInterface.hpp.

const std::string& RTT::base::PortInterface::getName ( ) const
inlineinherited
ConnID * PortInterface::getPortID ( ) const
virtualinherited
template<typename T>
virtual const types::TypeInfo* RTT::InputPort< T >::getTypeInfo ( ) const
inlinevirtual

Returns the types::TypeInfo object for the port's type.

Implements RTT::base::PortInterface.

Definition at line 193 of file InputPort.hpp.

References RTT::internal::DataSourceTypeInfo< T >::getTypeInfo().

bool PortInterface::isLocal ( ) const
virtualinherited

Returns true if this port is located on this process, and false otherwise.

Definition at line 67 of file PortInterface.cpp.

References RTT::base::PortInterface::serverProtocol().

Referenced by RTT::internal::ConnFactory::createAndCheckOutOfBandConnection(), and RTT::internal::ConnFactory::createConnection().

template<typename T>
FlowStatus RTT::InputPort< T >::read ( base::DataSourceBase::shared_ptr  source)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 103 of file InputPort.hpp.

Referenced by RTT::internal::InputPortSource< T >::evaluate(), RTT::InputPort< T >::read(), and RTT::InputPort< T >::readNewest().

template<typename T>
FlowStatus RTT::InputPort< T >::read ( base::DataSourceBase::shared_ptr  source,
bool  copy_old_data 
)
inlinevirtual

Reads the port and updates the value hold by the given data source.

This is only valid for local ports.

source has to be an assignable data source

Reimplemented from RTT::base::InputPortInterface.

Definition at line 106 of file InputPort.hpp.

References RTT::Error, RTT::NoData, RTT::InputPort< T >::read(), and RTT::internal::AssignableDataSource< T >::set().

template<typename T>
FlowStatus RTT::InputPort< T >::read ( typename base::ChannelElement< T >::reference_t  sample)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 137 of file InputPort.hpp.

References RTT::InputPort< T >::read().

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

Reads a sample from the connection.

sample is a reference which will get updated if a new sample is available.

The method returns an enum FlowStatus, which describes what type of sample (old or new data) or if a sample was returned (no data)

With the argument

  • copy_old_data one can specify, if sample should be updated in the case that the return type is equal to RTT::OldData. In case
  • copy_old_data is false and an old sample is available, the method will still return RTT::OldData but the sample will not be updated

Definition at line 151 of file InputPort.hpp.

References RTT::base::InputPortInterface::cmanager, RTT::NoData, and RTT::internal::ConnectionManager::select_reader_channel().

template<typename T>
FlowStatus RTT::InputPort< T >::readNewest ( base::DataSourceBase::shared_ptr  source,
bool  copy_old_data = true 
)
inline

Read all new samples that are available on this port, and returns the last one.

Returns RTT::NewData if at least one new sample was available, and either RTT::OldData or RTT::NoData otherwise.

Definition at line 124 of file InputPort.hpp.

References RTT::Error, RTT::NoData, and RTT::internal::AssignableDataSource< T >::set().

template<typename T>
FlowStatus RTT::InputPort< T >::readNewest ( typename base::ChannelElement< T >::reference_t  sample,
bool  copy_old_data = true 
)
inline

Read all new samples that are available on this port, and returns the last one.

Returns RTT::NewData if at least one new sample was available, and either RTT::OldData or RTT::NoData otherwise.

Definition at line 166 of file InputPort.hpp.

References RTT::NewData, and RTT::InputPort< T >::read().

bool InputPortInterface::removeConnection ( internal::ConnID cid)
virtualinherited

Removes the input channel.

Returns true if the provided channel was actually a channel of this port, and false otherwise.

You should usually not use this directly. Use disconnect() instead.

Implements RTT::base::PortInterface.

Definition at line 133 of file InputPortInterface.cpp.

Referenced by RTT::internal::ConnFactory::createStream(), and RTT::internal::ConnOutputEndpoint< T >::disconnect().

int PortInterface::serverProtocol ( ) const
virtualinherited
void PortInterface::setInterface ( DataFlowInterface iface)
inherited

Once a port is added to a DataFlowInterface, it gets a pointer to that interface.

This allows advanced ports to track back to which component they belong.

Definition at line 91 of file PortInterface.cpp.

References RTT::base::PortInterface::iface.

Referenced by RTT::DataFlowInterface::addLocalPort(), and RTT::corba::CDataFlowInterface_i::deregisterChannel().

bool PortInterface::setName ( const std::string &  name)
inherited

Change the name of this unconnected Port.

One can only change the name when it is not yet connected.

Return values
trueif !this->connected(), the name has changed.
falseif this->connected(), the name has not been changed.

Definition at line 51 of file PortInterface.cpp.

References RTT::base::PortInterface::connected().

Referenced by RTT::DataFlowInterface::addEventPort(), RTT::TaskContext::addEventPort(), RTT::DataFlowInterface::addPort(), and RTT::TaskContext::addPort().

void InputPortInterface::signal ( )
protectedinherited

The ConnOutputEndpoint signals that new data is available.

Definition at line 139 of file InputPortInterface.cpp.

Referenced by RTT::internal::ConnOutputEndpoint< T >::signal().

void InputPortInterface::signalInterface ( bool  true_false)
inherited

When called with true, will signal the DataFlowInterface when new data is available.

Definition at line 144 of file InputPortInterface.cpp.

Referenced by RTT::DataFlowInterface::addLocalEventPort().

Friends And Related Function Documentation

template<typename T>
friend class internal::ConnOutputEndpoint< T >
friend

Definition at line 65 of file InputPort.hpp.

Member Data Documentation

internal::ConnectionManager RTT::base::InputPortInterface::cmanager
protectedinherited
ConnPolicy RTT::base::InputPortInterface::default_policy
protectedinherited

Definition at line 70 of file InputPortInterface.hpp.

DataFlowInterface* RTT::base::PortInterface::iface
protectedinherited
bool RTT::base::InputPortInterface::msignal_interface
protectedinherited

Definition at line 74 of file InputPortInterface.hpp.


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