Orocos Real-Time Toolkit
2.5.0
|
A component's data output port. More...
#include <rtt/OutputPort.hpp>
Public Member Functions | |
OutputPort (std::string const &name="unnamed", bool keep_last_written_value=true) | |
Creates a named Output port. | |
void | keepNextWrittenValue (bool keep) |
void | keepLastWrittenValue (bool keep) |
Change the setting for keeping the last written value. | |
bool | keepsLastWrittenValue () const |
Returns true if this port records the last written value. | |
T | getLastWrittenValue () const |
Returns the last written value written to this port, in case it is kept by this port, otherwise, returns a default T(). | |
bool | getLastWrittenValue (T &sample) const |
Reads the last written value written to this port, in case it is kept by this port, otherwise, returns false. | |
virtual base::DataSourceBase::shared_ptr | getDataSource () const |
Returns a Data source that stores the last written value, or a null pointer if this port does not keep its last written value. | |
void | setDataSample (const T &sample) |
Provides this port a data sample that is representative for the samples being used in write(). | |
void | write (const T &sample) |
Writes a new sample to all receivers (if any). | |
void | write (base::DataSourceBase::shared_ptr source) |
Write this port using the value stored in source. | |
virtual const types::TypeInfo * | getTypeInfo () const |
Returns the types::TypeInfo object for the port's type. | |
virtual base::PortInterface * | clone () const |
Create a clone of this port with the same name. | |
virtual base::PortInterface * | antiClone () 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. | |
virtual bool | createConnection (base::InputPortInterface &input_port, ConnPolicy const &policy) |
Connects this write port to the given read port, using the given policy. | |
virtual bool | createStream (ConnPolicy const &policy) |
Creates a data stream from or to this port using connection-less transports. | |
virtual Service * | createPortObject () |
Create accessor Object for this Port, for addition to a TaskContext Object interface. | |
virtual bool | addConnection (internal::ConnID *port_id, ChannelElementBase::shared_ptr channel_input, ConnPolicy const &policy) |
Adds a new connection to this output port and initializes the connection if required by policy. | |
virtual void | disconnect () |
Removes any connection that either go to or come from this port. | |
virtual bool | disconnect (PortInterface *port) |
Removes the channel that connects this port to port . | |
virtual bool | connected () const |
Returns true if there is at least one channel registered in this port's list of outputs. | |
bool | createDataConnection (InputPortInterface &sink, int lock_policy=ConnPolicy::LOCK_FREE) |
Connects this write port to the given read port, using a single-data policy with the given locking mechanism. | |
bool | createBufferConnection (InputPortInterface &sink, int size, int lock_policy=ConnPolicy::LOCK_FREE) |
Connects this write port to the given read port, using a buffered policy, with the buffer of the given size and the given locking mechanism. | |
bool | createConnection (InputPortInterface &sink) |
Connects this write port to the given read port, using as policy the default policy of the sink port. | |
virtual bool | removeConnection (internal::ConnID *cid) |
Removes the connection associated with this channel, and the channel as well. | |
virtual bool | connectTo (PortInterface *other, ConnPolicy const &policy) |
Connects this port with other, using the given policy. | |
virtual bool | connectTo (PortInterface *other) |
Connects this port with other, using the default policy of the input. | |
virtual const internal::ConnectionManager * | getManager () const |
Returns the connection manager of this port (if any). | |
virtual internal::ConnID * | getPortID () const |
Returns the identity of this port in a ConnID object. | |
const std::string & | getName () const |
Get the name of this Port. | |
bool | setName (const std::string &name) |
Change the name of this unconnected Port. | |
const std::string & | getDescription () const |
Get the documentation of this port. | |
PortInterface & | doc (const std::string &desc) |
Set the documentation of this port. | |
virtual internal::ConnFactory * | getConnFactory () |
The ChannelFactory object that allows to build the ChannelElement chain needed to build connections to or from this port. | |
virtual bool | isLocal () const |
Returns true if this port is located on this process, and false otherwise. | |
virtual int | serverProtocol () const |
Returns the protocol over which this port can be accessed. | |
void | setInterface (DataFlowInterface *iface) |
Once a port is added to a DataFlowInterface, it gets a pointer to that interface. | |
DataFlowInterface * | getInterface () const |
Returns the DataFlowInterface this port belongs to or null if it was not added to such an interface. | |
Protected Attributes | |
internal::ConnectionManager | cmanager |
DataFlowInterface * | iface |
Friends | |
class | internal::ConnInputEndpoint< T > |
A component's data output port.
An Orocos OutputPort is a send-and-forget mechanism. The publisher writes data samples into the OutputPort and the underlying middleware will communicate it to all subscribers. An output port without subscribers is not an error on the component level (it may be at the system level, which can inspect the status with calling connected() ).
The data written into an OutputPort should be copyable and should provide a copy constructor in case it's not plain old data. If you want the RTT to transport your data over the network, or use it in scripting, you need to register your data class with the RTT type system.
Definition at line 70 of file OutputPort.hpp.
RTT::OutputPort< T >::OutputPort | ( | std::string const & | name = "unnamed" , |
bool | keep_last_written_value = true |
||
) | [inline] |
Creates a named Output port.
name | The name of this port, unique among the ports of a TaskContext. |
keep_last_written_value | Defaults to true. You need keep_last_written_value == true in two cases: * You're sending dynamically sized objects through this port in real-time. In that case, you need to write() to this port such an object before a connection is created. That object will be used to allocate enough data storage in each there-after created connection. If you would set keep_last_written_value == false in this use case, several memory allocations will happen during the initial writes, after which none will happen anymore. * You want to have an input to have the last written data available from before its connection was created, such that it is immediately initialized. The keep_last_written_value incurs a space overhead of one thread-safe data storage container. This is about the same size as one extra connection. |
Definition at line 165 of file OutputPort.hpp.
References RTT::OutputPort< T >::keepLastWrittenValue().
bool OutputPortInterface::addConnection | ( | internal::ConnID * | port_id, |
ChannelElementBase::shared_ptr | channel_input, | ||
ConnPolicy const & | policy | ||
) | [virtual, inherited] |
Adds a new connection to this output port and initializes the connection if required by policy.
Use with care. Allows you to add any arbitrary connection to this output port. It is your responsibility to do any further bookkeeping, such as informing the input that a new output has been added.
Implements RTT::base::PortInterface.
Definition at line 72 of file OutputPortInterface.cpp.
References RTT::internal::ConnectionManager::addConnection(), and RTT::base::OutputPortInterface::connectionAdded().
Referenced by RTT::internal::ConnFactory::createAndCheckStream().
bool OutputPortInterface::connected | ( | ) | const [virtual, inherited] |
Returns true if there is at least one channel registered in this port's list of outputs.
Returns true if this port is connected.
Implements RTT::base::PortInterface.
Definition at line 59 of file OutputPortInterface.cpp.
References RTT::internal::ConnectionManager::connected().
bool OutputPortInterface::connectTo | ( | PortInterface * | other, |
ConnPolicy const & | policy | ||
) | [virtual, inherited] |
Connects this port with other, using the given policy.
Unlike OutputPortInterface::createConnection, other can be the write port and this
the read port.
Implements RTT::base::PortInterface.
Definition at line 100 of file OutputPortInterface.cpp.
References RTT::base::OutputPortInterface::createConnection().
bool OutputPortInterface::connectTo | ( | PortInterface * | other | ) | [virtual, inherited] |
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.
Implements RTT::base::PortInterface.
Definition at line 108 of file OutputPortInterface.cpp.
References RTT::base::OutputPortInterface::createConnection().
virtual bool RTT::OutputPort< T >::createStream | ( | ConnPolicy const & | policy | ) | [inline, virtual] |
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.
policy | The connection policy describing how the stream must be set up. |
Implements RTT::base::PortInterface.
Definition at line 304 of file OutputPort.hpp.
PortInterface & PortInterface::doc | ( | const std::string & | desc | ) | [inherited] |
Set the documentation of this port.
desc | The description of the port |
Definition at line 60 of file PortInterface.cpp.
References RTT::DataFlowInterface::setPortDescription().
Referenced by RTT::InputPort< T >::createPortObject().
const std::string& RTT::base::PortInterface::getDescription | ( | ) | const [inline, inherited] |
Get the documentation of this port.
Definition at line 91 of file PortInterface.hpp.
T RTT::OutputPort< T >::getLastWrittenValue | ( | ) | const [inline] |
Returns the last written value written to this port, in case it is kept by this port, otherwise, returns a default T().
Definition at line 194 of file OutputPort.hpp.
Referenced by RTT::internal::ConnFactory::createConnection(), and RTT::OutputPort< T >::createPortObject().
bool RTT::OutputPort< T >::getLastWrittenValue | ( | T & | sample | ) | const [inline] |
Reads the last written value written to this port, in case it is kept by this port, otherwise, returns false.
sample | The data sample to store the value into. |
Definition at line 205 of file OutputPort.hpp.
virtual const internal::ConnectionManager* RTT::base::OutputPortInterface::getManager | ( | ) | const [inline, virtual, inherited] |
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.
Implements RTT::base::PortInterface.
Definition at line 142 of file OutputPortInterface.hpp.
void RTT::OutputPort< T >::keepLastWrittenValue | ( | bool | new_flag | ) | [inline, virtual] |
Change the setting for keeping the last written value.
Setting this to false will clear up any unneeded storage. If set, this port can initialize new connections with a data sample and allows real-time data transport of dynamically sized objects over its newly created connections.
Implements RTT::base::OutputPortInterface.
Definition at line 182 of file OutputPort.hpp.
Referenced by RTT::OutputPort< T >::OutputPort().
void RTT::OutputPort< T >::setDataSample | ( | const T & | sample | ) | [inline] |
Provides this port a data sample that is representative for the samples being used in write().
The sample will not be delivered to receivers, and only passed on to the underlying communication channel to allow it to allocate enough memory to hold the sample. You only need to call this in case you want to transfer dynamically sized objects in real-time over this OutputPort.
sample |
Definition at line 230 of file OutputPort.hpp.
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 92 of file PortInterface.cpp.
Referenced by RTT::DataFlowInterface::addLocalPort().
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.
true | if !this->connected(), the name has changed. |
false | if 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 RTT::OutputPort< T >::write | ( | const T & | sample | ) | [inline] |
Writes a new sample to all receivers (if any).
sample | The new sample to send out. |
Definition at line 245 of file OutputPort.hpp.
Referenced by RTT::OutputPort< T >::createPortObject(), and RTT::OutputPort< T >::write().