39 #ifndef ORO_OUTPUT_PORT_HPP 40 #define ORO_OUTPUT_PORT_HPP 83 if (has_initial_sample)
85 T
const& initial_sample = sample->Get();
87 if ( has_last_written_value && policy.
init )
92 log(
Error) <<
"Failed to pass data sample to data channel. Aborting connection."<<endlog();
102 bool has_last_written_value;
106 bool has_initial_sample;
109 bool keeps_next_written_value;
112 bool keeps_last_written_value;
141 OutputPort(std::string
const& name =
"unnamed",
bool keep_last_written_value =
true)
144 , has_last_written_value(false)
145 , has_initial_sample(false)
146 , keeps_next_written_value(false)
147 , keeps_last_written_value(false)
150 if (keep_last_written_value)
158 keeps_next_written_value = keep;
163 keeps_last_written_value = keep;
175 return sample->
Get();
186 if (has_last_written_value)
188 this->sample->Get(sample);
211 this->sample->Set(sample);
212 has_initial_sample =
true;
213 has_last_written_value =
false;
218 log(
Error) <<
"A channel of port " <<
getName() <<
" has been invalidated during setDataSample(), it will be removed" << endlog();
229 has_last_written_value =
false;
234 if (shared_connection) {
235 shared_connection->clear();
245 if (keeps_last_written_value || keeps_next_written_value)
247 keeps_next_written_value =
false;
248 has_initial_sample =
true;
249 this->sample->Set(sample);
251 has_last_written_value = keeps_last_written_value;
255 result =
getEndpoint()->getWriteEndpoint()->write(sample);
257 log(
Error) <<
"A channel of port " <<
getName() <<
" has been invalidated during write(), it will be removed" << endlog();
277 log(
Error) <<
"trying to write from an incompatible data source" << endlog();
314 #ifndef ORO_DISABLE_PORT_DATA_SCRIPTING 327 object->addSynchronousOperation(
"write", write_m,
this).doc(
"Writes a sample on the port.").arg(
"sample",
"");
328 object->addSynchronousOperation(
"last", last_m,
this).doc(
"Returns last written value to this port.");
336 return endpoint.get();
void setDataSample(const T &sample)
Provides this port a data sample that is representative for the samples being used in write()...
DataSource is a base class representing a generic way to read data of type T.
boost::intrusive_ptr< ChannelElement< T > > shared_ptr
virtual result_t get() const =0
Return the data as type T.
boost::intrusive_ptr< SharedConnectionBase > shared_ptr
WriteStatus write(base::DataSourceBase::shared_ptr source)
Write this port using the value stored in source.
boost::shared_ptr< DataObjectInterface< T > > shared_ptr
Used for shared_ptr management.
void clear()
Clears the last written value and all data stored in shared connection buffers.
OutputPort(std::string const &name="unnamed", bool keep_last_written_value=true)
Creates a named Output port.
virtual const types::TypeInfo * getTypeInfo() const
Returns the types::TypeInfo object for the port's type.
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.
void keepLastWrittenValue(bool keep)
Change the setting for keeping the last written value.
virtual FlowStatus Get(reference_t pull, bool copy_old_data=true) const =0
Get a copy of the Data of this data object.
const std::string & getName() const
Get the name of this Port.
virtual base::PortInterface * clone() const
Create a clone of this port with the same name.
virtual internal::ConnInputEndpoint< T > * getEndpoint() const
Returns the input or output endpoint of this port (if any).
A connection policy object describes how a given connection should behave.
The base class of each OutputPort.
We can't use typedefs since C++ doesn't allow it for templated classes without specifying all the tem...
virtual Service * createPortObject()
Create accessor Object for this Port, for addition to a TaskContext Object interface.
This class allows storage and retrieval of operations, ports, attributes and properties provided by a...
static ChannelElement< T > * narrow(ChannelElementBase *e)
Return a pointer to the typed instance of a ChannelElementBase.
static const types::TypeInfo * getTypeInfo()
Return the typeinfo object.
virtual Service * createPortObject()
Create accessor Object for this Port, for addition to a TaskContext Object interface.
virtual const_reference_t rvalue() const =0
Get a const reference to the value of this DataSource.
virtual bool createStream(ConnPolicy const &policy)
Creates a data stream from or to this port using connection-less transports.
static bool createStream(OutputPort< T > &output_port, ConnPolicy const &policy)
Creates, attaches and checks an outbound stream to an Output port.
bool createConnection(InputPortInterface &sink)
Connects this write port to the given read port, using as policy the default policy of the sink port...
A class for representing a user type, and which can build instances of that type. ...
bool keepsLastWrittenValue() const
Returns true if this port records the last written value.
WriteStatus write(const T &sample)
Writes a new sample to all receivers (if any).
virtual bool connected() const
Returns true if there is at least one channel registered in this port's list of outputs.
boost::intrusive_ptr< ChannelElementBase > shared_ptr
boost::intrusive_ptr< DataSource< T > > shared_ptr
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Use this type to store a pointer to an AssignableDataSource.
bool init
If true, one should initialize the connection's value with the last value written on the writer port...
This object represents the default thread-safe data object implementation used by Orocos objects...
virtual base::ChannelElement< T >::shared_ptr getSharedBuffer() const
A DataSource which has set() methods.
Notify the Logger in which 'module' the message occured.
void keepNextWrittenValue(bool keep)
internal::ConnectionManager cmanager
virtual void disconnect()
Removes any connection that either go to or come from this port.
A component's data output port.
virtual WriteStatus data_sample(param_t sample, bool reset=true)
Provides a data sample to initialize this connection.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
virtual WriteStatus write(param_t sample)
Writes a new sample on this connection.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
The base class of every data flow port.
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().
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 kee...
static bool createConnection(OutputPort< T > &output_port, base::InputPortInterface &input_port, ConnPolicy const &policy)
Creates a connection from a local output_port to a local or remote input_port.
A DataSource which is used to read a DataObject.
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...
WriteStatus
Returns the status of a data flow write operation.
virtual bool createConnection(base::InputPortInterface &input_port, ConnPolicy const &policy)
Connects this write port to the given read port, using the given policy.
internal::SharedConnectionBase::shared_ptr getSharedConnection() const
Returns a pointer to the shared connection element this port may be connected to. ...