39 #ifndef ORO_OUTPUT_PORT_HPP 40 #define ORO_OUTPUT_PORT_HPP 78 if (output->write(sample))
82 log(
Error) <<
"A channel of port " <<
getName() <<
" has been invalidated during write(), it will be removed" << endlog();
91 if (output->data_sample(sample))
95 log(
Error) <<
"A channel of port " <<
getName() <<
" has been invalidated during setDataSample(), it will be removed" << endlog();
108 if (has_initial_sample)
110 T
const& initial_sample = sample->Get();
111 if ( channel_el_input->
data_sample(initial_sample) ) {
112 if ( has_last_written_value && policy.
init )
113 return channel_el_input->
write(initial_sample);
117 log(
Error) <<
"Failed to pass data sample to data channel. Aborting connection."<<endlog();
126 bool has_last_written_value;
130 bool has_initial_sample;
133 bool keeps_next_written_value;
136 bool keeps_last_written_value;
165 OutputPort(std::string
const& name =
"unnamed",
bool keep_last_written_value =
true)
167 , has_last_written_value(false)
168 , has_initial_sample(false)
169 , keeps_next_written_value(false)
170 , keeps_last_written_value(false)
173 if (keep_last_written_value)
179 keeps_next_written_value = keep;
184 keeps_last_written_value = keep;
196 return sample->
Get();
207 if (has_last_written_value)
209 this->sample->Get(sample);
232 this->sample->Set(sample);
233 has_initial_sample =
true;
234 has_last_written_value =
false;
247 if (keeps_last_written_value || keeps_next_written_value)
249 keeps_next_written_value =
false;
250 has_initial_sample =
true;
251 this->sample->Set(sample);
253 has_last_written_value = keeps_last_written_value;
273 log(
Error) <<
"trying to write from an incompatible data source" << endlog();
309 #ifndef ORO_DISABLE_PORT_DATA_SCRIPTING 322 object->addSynchronousOperation(
"write", write_m,
this).doc(
"Writes a sample on the port.").arg(
"sample",
"");
323 object->addSynchronousOperation(
"last", last_m,
this).doc(
"Returns last written value to this port.");
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::call_traits< T >::param_type param_t
boost::intrusive_ptr< ChannelElement< T > > shared_ptr
virtual result_t get() const =0
Return the data as type T.
boost::shared_ptr< DataObjectInterface< T > > shared_ptr
Used for shared_ptr management.
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.
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.
bool delete_if(Pred pred)
internal::ConnectionManager cmanager
virtual bool write(param_t sample)
Writes a new sample on this connection.
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...
A typed version of 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.
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 an...
void write(const T &sample)
Writes a new sample to all receivers (if any).
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 void Get(DataType &pull) const =0
Get a copy of the Data of this data object.
A DataSource which has set() methods.
Notify the Logger in which 'module' the message occured.
void keepNextWrittenValue(bool keep)
void write(base::DataSourceBase::shared_ptr source)
Write this port using the value stored in source.
A component's data output port.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
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...
virtual bool data_sample(param_t sample)
Provides a data sample to initialize this connection.
virtual bool createConnection(base::InputPortInterface &input_port, ConnPolicy const &policy)
Connects this write port to the given read port, using the given policy.