YARP
Yet Another Robot Platform
yarp::os::BufferedPort< T > Class Template Reference

A mini-server for performing network communication in the background. More...

#include <yarp/os/BufferedPort.h>

+ Inheritance diagram for yarp::os::BufferedPort< T >:

Detailed Description

template<typename T>
class yarp::os::BufferedPort< T >

A mini-server for performing network communication in the background.

If you are a beginner, you might want to use the yarp::os::Port class first, and then come back to BufferedPort when you want to send and receive messages in the background without having to stop your processing. This is convenient, but requires a little care to understand the life-cycle of objects written to and read from the network (see BufferedPort::read and BufferedPort::write).

By default a BufferedPort attempts to reduce latency between senders and receivers. To do so messages may be dropped by the writer if BufferedPort::write is called too quickly The reader may also drop old messages if BufferedPort::read is not called fast enough, so that new messages can travel with high priority. This policy is sometimes called Oldest Packet Drop (ODP).

If your application cannot afford dropping messages you can change the buffering policy. Use BufferedPort::writeStrict() when writing to a port, this waits for pending transmissions to be finished before writing new data. Call BufferedPort::setStrict() to change the buffering policy to FIFO at the receiver side. In this way all messages will be stored inside the BufferedPort and delivered to the reader. Pay attention that in this case a slow reader may cause increasing latency and memory use.

Methods that can be useful to monitor the status of read and write operations are yarp::os::BufferedPort::getPendingReads() and yarp::os::BufferedPort::isWriting().

See also
For examples and help, see:
Examples:
framerate/main.cpp, os/buffered_port.cpp, os/image_process.cpp, os/image_process_module.cpp, os/image_source.cpp, os/make_count.cpp, os/summer.cpp, os/view_count.cpp, port_power/ex0100_receiver.cpp, port_power/ex0101_sender.cpp, port_power/ex0200_polling.cpp, port_power/ex0301_buffered_callback.cpp, port_power/ex0302_buffered_ext_callback.cpp, port_power/ex0403_bufferedport_callback_reply.cpp, and portaudio/sound_receiver.cpp.

Definition at line 20 of file BufferedPort.h.

Public Types

typedef T ContentType
 The type of content stored by this BufferedPort. More...
 

Public Member Functions

 BufferedPort ()
 Constructor. More...
 
 BufferedPort (Port &port)
 Wrap an existing unbuffered port. More...
 
virtual ~BufferedPort ()
 Destructor. More...
 
virtual bool open (const std::string &name) override
 Start port operation, with a specific name, with automatically-chosen network parameters. More...
 
virtual bool open (const Contact &contact, bool registerName=true) override
 Start port operation with user-chosen network parameters. More...
 
virtual bool addOutput (const std::string &name) override
 Add an output connection to the specified port. More...
 
virtual bool addOutput (const std::string &name, const std::string &carrier) override
 Add an output connection to the specified port, using a specified carrier. More...
 
virtual bool addOutput (const Contact &contact) override
 Add an output connection to the specified port, using specified network parameters. More...
 
virtual void close () override
 Stop port activity. More...
 
virtual void interrupt () override
 Interrupt any current reads or writes attached to the port. More...
 
virtual void resume () override
 Put the port back in an operative state after interrupt() has been called. More...
 
virtual int getPendingReads () override
 Get the number of objects ready to be read. More...
 
virtual Contact where () const override
 Returns information about how this port can be reached. More...
 
virtual std::string getName () const override
 Get name of port. More...
 
T & prepare ()
 Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write. More...
 
bool unprepare ()
 Give the last prepared object back to YARP without writing it. More...
 
void write (bool forceStrict=false)
 Write the current object being returned by BufferedPort::prepare. More...
 
void writeStrict ()
 Write the current object being returned by BufferedPort::prepare, waiting until any previous sends are complete. More...
 
void waitForWrite ()
 Wait for any pending writes to complete. More...
 
virtual void setStrict (bool strict=true) override
 Call this to strictly keep all messages, or allow old ones to be quietly dropped. More...
 
virtual T * read (bool shouldWait=true) override
 Read an available object from the port. More...
 
virtual T * lastRead () override
 Get the last data returned by read() More...
 
virtual bool isClosed () override
 Returns whether the port associated with this reader has been closed. More...
 
void setReplier (PortReader &reader) override
 If a message is received that requires a reply, use this handler. More...
 
void setReader (PortReader &reader) override
 Set an external reader for port data. More...
 
void setAdminReader (PortReader &reader) override
 Set an external reader for unrecognized administrative port messages. More...
 
virtual void onRead (T &datum) override
 Callback method. More...
 
virtual void useCallback (TypedReaderCallback< T > &callback) override
 Set an object whose onRead method will be called when data is available. More...
 
void useCallback ()
 Use own onRead() method as callback. More...
 
virtual void disableCallback () override
 Remove a callback set up with useCallback() More...
 
virtual bool setEnvelope (PortWriter &envelope) override
 Set an envelope (e.g., a timestamp) to the next message which will be sent. More...
 
virtual bool getEnvelope (PortReader &envelope) override
 Get the envelope information (e.g., a timestamp) from the last message received on the port. More...
 
virtual int getInputCount () override
 Determine how many connections are arriving into this port. More...
 
virtual int getOutputCount () override
 Determine how many output connections this port has. More...
 
bool isWriting () override
 Report whether the port is currently writing data. More...
 
virtual void getReport (PortReport &reporter) override
 Get information on the state of the port - connections etc. More...
 
virtual void setReporter (PortReport &reporter) override
 Set a callback to be called upon any future connections and disconnections to/from the port. More...
 
virtual void resetReporter () override
 Remove the callback which is called upon any future connections and disconnections to/from the port. More...
 
virtual void * acquire () override
 Take control of the last object read. More...
 
virtual void release (void *handle) override
 Return control to YARP of an object previously taken control of with the acquire() method. More...
 
virtual void setTargetPeriod (double period) override
 Try to provide data periodically. More...
 
virtual Type getType () override
 Get the type of data the port has committed to send/receive. More...
 
virtual void promiseType (const Type &typ) override
 Commit the port to a particular type of data. More...
 
virtual void setInputMode (bool expectInput) override
 Configure the port to allow or forbid inputs. More...
 
virtual void setOutputMode (bool expectOutput) override
 Configure the port to allow or forbid outputs. More...
 
virtual void setRpcMode (bool expectRpc) override
 Configure the port to be RPC only. More...
 
virtual PropertyacquireProperties (bool readOnly) override
 Access unstructured port properties. More...
 
virtual void releaseProperties (Property *prop) override
 End access unstructured port properties. More...
 
virtual void includeNodeInName (bool flag) override
 Choose whether to prepend a node name (if one is available) to the port's name. More...
 
virtual bool setCallbackLock (yarp::os::Mutex *mutex) override
 Add a lock to use when invoking callbacks. More...
 
virtual bool removeCallbackLock () override
 Remove a lock on callbacks added with setCallbackLock() More...
 
virtual bool lockCallback () override
 Lock callbacks until unlockCallback() is called. More...
 
virtual bool tryLockCallback () override
 Try to lock callbacks until unlockCallback() is called. More...
 
virtual void unlockCallback () override
 Unlock callbacks. More...
 
- Public Member Functions inherited from yarp::os::Contactable
virtual ~Contactable ()
 Destructor. More...
 
void setReadOnly ()
 Shorthand for setInputMode(true), setOutputMode(false), setRpcMode(false) More...
 
void setWriteOnly ()
 Shorthand for setInputMode(false), setOutputMode(true), setRpcMode(false) More...
 
void setRpcServer ()
 Shorthand for setInputMode(true), setOutputMode(false), setRpcMode(true) More...
 
void setRpcClient ()
 Shorthand for setInputMode(false), setOutputMode(true), setRpcMode(true) More...
 
- Public Member Functions inherited from yarp::os::TypedReader< T >
virtual ~TypedReader ()
 Destructor. More...
 
- Public Member Functions inherited from yarp::os::TypedReaderCallback< T >
virtual ~TypedReaderCallback ()
 Destructor. More...
 
virtual void onRead (T &datum, const yarp::os::TypedReader< T > &reader)
 Callback method. More...
 

Private Member Functions

 BufferedPort (const BufferedPort &alt)=delete
 
const BufferedPortoperator= (const BufferedPort &alt)=delete
 
void attachIfNeeded ()
 
bool sharedOpen (Port &port)
 

Private Attributes

PortWriterBuffer< T > writer
 
Port port
 
PortReaderBuffer< T > reader
 
bool interrupted
 
bool attached
 

Member Typedef Documentation

◆ ContentType

template<typename T>
typedef T yarp::os::BufferedPort< T >::ContentType

The type of content stored by this BufferedPort.

Definition at line 77 of file BufferedPort.h.

Constructor & Destructor Documentation

◆ BufferedPort() [1/3]

template<typename T >
yarp::os::BufferedPort< T >::BufferedPort ( )

Constructor.

Definition at line 17 of file BufferedPort-inl.h.

◆ BufferedPort() [2/3]

template<typename T >
yarp::os::BufferedPort< T >::BufferedPort ( Port port)

Wrap an existing unbuffered port.

Definition at line 27 of file BufferedPort-inl.h.

◆ ~BufferedPort()

template<typename T >
yarp::os::BufferedPort< T >::~BufferedPort ( )
virtual

Destructor.

Definition at line 35 of file BufferedPort-inl.h.

◆ BufferedPort() [3/3]

template<typename T>
yarp::os::BufferedPort< T >::BufferedPort ( const BufferedPort< T > &  alt)
privatedelete

Member Function Documentation

◆ acquire()

template<typename T >
void * yarp::os::BufferedPort< T >::acquire ( )
overridevirtual

Take control of the last object read.

YARP will not reuse that object until it is explicitly released by the user. Be careful - if you acquire objects without releasing, YARP will keep making new ones to store incoming messages. So you need to release all objects you acquire eventually to avoid running out of memory.

Returns
the handle to call release() with in order to give YARP back control of the last object read.

Implements yarp::os::TypedReader< T >.

Definition at line 281 of file BufferedPort-inl.h.

◆ acquireProperties()

template<typename T >
yarp::os::Property * yarp::os::BufferedPort< T >::acquireProperties ( bool  readOnly)
overridevirtual

Access unstructured port properties.

Parameters
readOnlyset this if you won't be modifying the properties.
Returns
the port properties (or nullptr if readOnly and none have been set)

Implements yarp::os::Contactable.

Definition at line 331 of file BufferedPort-inl.h.

◆ addOutput() [1/3]

template<typename T >
bool yarp::os::BufferedPort< T >::addOutput ( const std::string &  name)
overridevirtual

Add an output connection to the specified port.

Parameters
namethe name of the target port
Returns
true iff the connection is successfully created

Implements yarp::os::Contactable.

Definition at line 55 of file BufferedPort-inl.h.

◆ addOutput() [2/3]

template<typename T >
bool yarp::os::BufferedPort< T >::addOutput ( const std::string &  name,
const std::string &  carrier 
)
overridevirtual

Add an output connection to the specified port, using a specified carrier.

Parameters
namethe name of the target port
carrierthe carrier (network protocol) to use, e.g. "tcp", "udp", "mcast", "text", ...
Returns
true iff the connection is successfully created

Implements yarp::os::Contactable.

Definition at line 61 of file BufferedPort-inl.h.

◆ addOutput() [3/3]

template<typename T >
bool yarp::os::BufferedPort< T >::addOutput ( const Contact contact)
overridevirtual

Add an output connection to the specified port, using specified network parameters.

Parameters
contactinformation on how to reach the target
Returns
true iff the connection is successfully created

Implements yarp::os::Contactable.

Definition at line 67 of file BufferedPort-inl.h.

◆ attachIfNeeded()

template<typename T >
void yarp::os::BufferedPort< T >::attachIfNeeded ( )
private

Definition at line 379 of file BufferedPort-inl.h.

◆ close()

template<typename T >
void yarp::os::BufferedPort< T >::close ( )
overridevirtual

Stop port activity.

Implements yarp::os::Contactable.

Definition at line 73 of file BufferedPort-inl.h.

◆ disableCallback()

template<typename T >
void yarp::os::BufferedPort< T >::disableCallback ( )
overridevirtual

Remove a callback set up with useCallback()

Implements yarp::os::TypedReader< T >.

Definition at line 225 of file BufferedPort-inl.h.

◆ getEnvelope()

template<typename T >
bool yarp::os::BufferedPort< T >::getEnvelope ( PortReader envelope)
overridevirtual

Get the envelope information (e.g., a timestamp) from the last message received on the port.

You must be sure to match the type of your envelope for getEnvelope with whatever is being sent using setEnvelope. The Stamp class is a typical choice for timestamps. The Bottle class also works as an envelope, but it is not specialized to be efficient.

Parameters
enveloperecipient for envelope information for last message received by port.
Returns
true iff reading the envelope was successful

Implements yarp::os::Contactable.

Definition at line 239 of file BufferedPort-inl.h.

◆ getInputCount()

template<typename T >
int yarp::os::BufferedPort< T >::getInputCount ( )
overridevirtual

Determine how many connections are arriving into this port.

In other words, how many other ports have this port listed as an output?

Returns
number of input connections

Implements yarp::os::Contactable.

Definition at line 245 of file BufferedPort-inl.h.

◆ getName()

template<typename T >
std::string yarp::os::BufferedPort< T >::getName ( ) const
overridevirtual

Get name of port.

Returns
name of port

Reimplemented from yarp::os::Contactable.

Definition at line 108 of file BufferedPort-inl.h.

◆ getOutputCount()

template<typename T >
int yarp::os::BufferedPort< T >::getOutputCount ( )
overridevirtual

Determine how many output connections this port has.

Returns
number of output connections

Implements yarp::os::Contactable.

Definition at line 251 of file BufferedPort-inl.h.

◆ getPendingReads()

template<typename T >
int yarp::os::BufferedPort< T >::getPendingReads ( )
overridevirtual

Get the number of objects ready to be read.

Implements yarp::os::TypedReader< T >.

Definition at line 96 of file BufferedPort-inl.h.

◆ getReport()

template<typename T >
void yarp::os::BufferedPort< T >::getReport ( PortReport reporter)
overridevirtual

Get information on the state of the port - connections etc.

PortReport::report will be called once for each connection to the port that exists right now. To request callbacks for any future connections/disconnections, use the setReporter method instead.

Parameters
reportercallback for port event/state information

Implements yarp::os::Contactable.

Definition at line 263 of file BufferedPort-inl.h.

◆ getType()

template<typename T >
yarp::os::Type yarp::os::BufferedPort< T >::getType ( )
overridevirtual

Get the type of data the port has committed to send/receive.

Not all ports commit to a particular type of data.

Returns
type of data to expect/provide

Implements yarp::os::Contactable.

Definition at line 301 of file BufferedPort-inl.h.

◆ includeNodeInName()

template<typename T >
void yarp::os::BufferedPort< T >::includeNodeInName ( bool  flag)
overridevirtual

Choose whether to prepend a node name (if one is available) to the port's name.

Node names are set using yarp::os::Node.

Parameters
flagtrue if the node name should be added to port names

Implements yarp::os::Contactable.

Definition at line 343 of file BufferedPort-inl.h.

◆ interrupt()

template<typename T >
void yarp::os::BufferedPort< T >::interrupt ( )
overridevirtual

Interrupt any current reads or writes attached to the port.

This is useful prior to calling close(), if there are multiple threads operating on the port. Any reads or writes after the call to interrupt() will fail - unless resume() is called.

Implements yarp::os::Contactable.

Definition at line 82 of file BufferedPort-inl.h.

◆ isClosed()

template<typename T >
bool yarp::os::BufferedPort< T >::isClosed ( )
overridevirtual

Returns whether the port associated with this reader has been closed.

Returns
true if Port associated with this reader has been closed

Implements yarp::os::TypedReader< T >.

Definition at line 177 of file BufferedPort-inl.h.

◆ isWriting()

template<typename T >
bool yarp::os::BufferedPort< T >::isWriting ( )
overridevirtual

Report whether the port is currently writing data.

Returns
true iff the port is writing in the background.

Implements yarp::os::Contactable.

Definition at line 257 of file BufferedPort-inl.h.

◆ lastRead()

template<typename T >
T * yarp::os::BufferedPort< T >::lastRead ( )
overridevirtual

Get the last data returned by read()

Returns
pointer to last data returned by read(), or nullptr on failure.

Implements yarp::os::TypedReader< T >.

Definition at line 171 of file BufferedPort-inl.h.

◆ lockCallback()

template<typename T >
bool yarp::os::BufferedPort< T >::lockCallback ( )
overridevirtual

Lock callbacks until unlockCallback() is called.

Has no effect if no lock has been set via a call to setCallbackLock(). Will block if callbacks are already locked.

Returns
true if callbacks were locked

Implements yarp::os::Contactable.

Definition at line 361 of file BufferedPort-inl.h.

◆ onRead()

template<typename T>
void yarp::os::BufferedPort< T >::onRead ( T &  datum)
overridevirtual

Callback method.

this method will be called with new data, as long as you've requested this be done by calling useCallback()

Parameters
datumdata read from a port

Reimplemented from yarp::os::TypedReaderCallback< T >.

Reimplemented in yarp::dev::JoypadControl::JoyPort< T >, yarp::dev::JoypadControl::JoyPort< yarp::sig::Vector >, yarp::dev::JoypadControl::JoyPort< VectorOf< unsigned char > >, StateExtendedInputPort, yarp::dev::SensorStreamingDataInputPort, and InputCallback.

Definition at line 204 of file BufferedPort-inl.h.

◆ open() [1/2]

template<typename T >
bool yarp::os::BufferedPort< T >::open ( const std::string &  name)
overridevirtual

Start port operation, with a specific name, with automatically-chosen network parameters.

The port is registered with the given name, and allocated network resources, by communicating with the YARP name server.

Returns
true iff the port started operation successfully and is now visible on the YARP network

Implements yarp::os::Contactable.

Definition at line 41 of file BufferedPort-inl.h.

◆ open() [2/2]

template<typename T >
bool yarp::os::BufferedPort< T >::open ( const Contact contact,
bool  registerName = true 
)
overridevirtual

Start port operation with user-chosen network parameters.

Contact information is supplied by the user rather than the name server. If the Contact information is incomplete, the name server is used to complete it (set registerName to false if you don't want name server help).

Returns
true iff the port started operation successfully and is now visible on the YARP network

Implements yarp::os::Contactable.

Definition at line 48 of file BufferedPort-inl.h.

◆ operator=()

template<typename T>
const BufferedPort& yarp::os::BufferedPort< T >::operator= ( const BufferedPort< T > &  alt)
privatedelete

◆ prepare()

template<typename T >
T & yarp::os::BufferedPort< T >::prepare ( )

Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.

The object can safely be modified by the user of this class, to prepare it. Extra objects will be created or reused as necessary depending on the state of communication with the output(s) of the port.

Warning
If prepare() gives you a reused object, it is up to the user to clear the object if that is appropriate. If you are sending yarp::os::Bottle objects, you may want to call yarp::os::Bottle::clear(), for example. YARP doesn't clear objects for you, since there are many cases in which overwriting old data is suffient and reallocation of memory would be unnecessary and inefficient.
Returns
the next object that will be written

Definition at line 114 of file BufferedPort-inl.h.

◆ promiseType()

template<typename T >
void yarp::os::BufferedPort< T >::promiseType ( const Type typ)
overridevirtual

Commit the port to a particular type of data.

Parameters
typthe type of data the port will send/receive

Implements yarp::os::Contactable.

Definition at line 307 of file BufferedPort-inl.h.

◆ read()

template<typename T >
T * yarp::os::BufferedPort< T >::read ( bool  shouldWait = true)
overridevirtual

Read an available object from the port.

Parameters
shouldWaittrue if the method should wait until an object is available, false if the call should return immediately if no message is available
Returns
A pointer to an object read from the port, or nullptr if none is available and waiting was not requested. This object is owned by the communication system and should not be deleted by the user. The object is available to the user until the next call to one of the read methods, after which it should not be accessed again.

Implements yarp::os::TypedReader< T >.

Definition at line 154 of file BufferedPort-inl.h.

◆ release()

template<typename T >
void yarp::os::BufferedPort< T >::release ( void *  handle)
overridevirtual

Return control to YARP of an object previously taken control of with the acquire() method.

Parameters
handlethe pointer returned by acquire() when control of the object was taken by the user.

Implements yarp::os::TypedReader< T >.

Definition at line 287 of file BufferedPort-inl.h.

◆ releaseProperties()

template<typename T >
void yarp::os::BufferedPort< T >::releaseProperties ( Property prop)
overridevirtual

End access unstructured port properties.

Parameters
propthe port property object provided by acquireProperties()

Implements yarp::os::Contactable.

Definition at line 337 of file BufferedPort-inl.h.

◆ removeCallbackLock()

template<typename T >
bool yarp::os::BufferedPort< T >::removeCallbackLock ( )
overridevirtual

Remove a lock on callbacks added with setCallbackLock()

Implements yarp::os::Contactable.

Definition at line 355 of file BufferedPort-inl.h.

◆ resetReporter()

template<typename T >
void yarp::os::BufferedPort< T >::resetReporter ( )
overridevirtual

Remove the callback which is called upon any future connections and disconnections to/from the port.

Implements yarp::os::Contactable.

Definition at line 275 of file BufferedPort-inl.h.

◆ resume()

template<typename T >
void yarp::os::BufferedPort< T >::resume ( )
overridevirtual

Put the port back in an operative state after interrupt() has been called.

Implements yarp::os::Contactable.

Definition at line 89 of file BufferedPort-inl.h.

◆ setAdminReader()

template<typename T >
void yarp::os::BufferedPort< T >::setAdminReader ( PortReader reader)
overridevirtual

Set an external reader for unrecognized administrative port messages.

Parameters
readerthe external reader to use

Implements yarp::os::Contactable.

Definition at line 197 of file BufferedPort-inl.h.

◆ setCallbackLock()

template<typename T >
bool yarp::os::BufferedPort< T >::setCallbackLock ( yarp::os::Mutex mutex)
overridevirtual

Add a lock to use when invoking callbacks.

mutex.lock() will be called before and mutex.unlock() will be called after the callback. This applies at least to callbacks set by setReader and setAdminReader, and in future may apply to other callbacks.

Parameters
mutexthe lock to use. If nullptr, a mutex will be allocated internally by the port, and destroyed with the port.

Implements yarp::os::Contactable.

Definition at line 349 of file BufferedPort-inl.h.

◆ setEnvelope()

template<typename T >
bool yarp::os::BufferedPort< T >::setEnvelope ( PortWriter envelope)
overridevirtual

Set an envelope (e.g., a timestamp) to the next message which will be sent.

You must be sure to match the type of your envelope for setEnvelope with whatever will be read using getEnvelope. The Stamp class is a typical choice for timestamps. The Bottle class also works as an envelope, but it is not specialized to be efficient.

Currently, for proper operation, the envelope must serialize correctly in text-mode (even if you do not explicitly use text-mode connections). Bottle or Stamp are good choices.

Parameters
envelopeinformation to add to the next message which will be sent
Returns
true iff setting the envelope was successful

Implements yarp::os::Contactable.

Definition at line 232 of file BufferedPort-inl.h.

◆ setInputMode()

template<typename T >
void yarp::os::BufferedPort< T >::setInputMode ( bool  expectInput)
overridevirtual

Configure the port to allow or forbid inputs.

By default, ports allow anything.

Parameters
expectInputset to true if this port will be used for input

Implements yarp::os::Contactable.

Definition at line 313 of file BufferedPort-inl.h.

◆ setOutputMode()

template<typename T >
void yarp::os::BufferedPort< T >::setOutputMode ( bool  expectOutput)
overridevirtual

Configure the port to allow or forbid outputs.

By default, ports allow anything.

Parameters
expectOutputset to true if this port will be used for output

Implements yarp::os::Contactable.

Definition at line 319 of file BufferedPort-inl.h.

◆ setReader()

template<typename T >
void yarp::os::BufferedPort< T >::setReader ( PortReader reader)
overridevirtual

Set an external reader for port data.

Parameters
readerthe external reader to use

Implements yarp::os::Contactable.

Definition at line 190 of file BufferedPort-inl.h.

◆ setReplier()

template<typename T >
void yarp::os::BufferedPort< T >::setReplier ( PortReader reader)
overridevirtual

If a message is received that requires a reply, use this handler.

No buffering happens.

Parameters
readerthe handler to use

Implements yarp::os::TypedReader< T >.

Definition at line 183 of file BufferedPort-inl.h.

◆ setReporter()

template<typename T >
void yarp::os::BufferedPort< T >::setReporter ( PortReport reporter)
overridevirtual

Set a callback to be called upon any future connections and disconnections to/from the port.

To get information on the current connections that exist, use the getReport method instead.

Parameters
reportercallback for port event/state information

Implements yarp::os::Contactable.

Definition at line 269 of file BufferedPort-inl.h.

◆ setRpcMode()

template<typename T >
void yarp::os::BufferedPort< T >::setRpcMode ( bool  expectRpc)
overridevirtual

Configure the port to be RPC only.

By default all ports can be used for RPC or streaming communication.

Parameters
expectRpcset to true if this port will be used for RPC only

Implements yarp::os::Contactable.

Definition at line 325 of file BufferedPort-inl.h.

◆ setStrict()

template<typename T >
void yarp::os::BufferedPort< T >::setStrict ( bool  strict = true)
overridevirtual

Call this to strictly keep all messages, or allow old ones to be quietly dropped.

If you don't call this, old messages will be quietly dropped.

Parameters
strictTrue to keep all messages until they are read, false to drop old messages when a new one comes in.
Warning
If you can't read them as fast as the come in, watch out.

Implements yarp::os::TypedReader< T >.

Definition at line 147 of file BufferedPort-inl.h.

◆ setTargetPeriod()

template<typename T >
void yarp::os::BufferedPort< T >::setTargetPeriod ( double  period)
overridevirtual

Try to provide data periodically.

If no new data arrives in a given period, repeat the last data received (if any). Similarly, the port should not pass on data more frequently than the given period.

Parameters
periodtarget period in (fractional) seconds.

Implements yarp::os::TypedReader< T >.

Definition at line 294 of file BufferedPort-inl.h.

◆ sharedOpen()

template<typename T >
bool yarp::os::BufferedPort< T >::sharedOpen ( Port port)
private

Definition at line 389 of file BufferedPort-inl.h.

◆ tryLockCallback()

template<typename T >
bool yarp::os::BufferedPort< T >::tryLockCallback ( )
overridevirtual

Try to lock callbacks until unlockCallback() is called.

Has no effect if no lock has been set via a call to setCallbackLock(). Returns immediately.

Returns
true if callbacks were locked by this call, false if they were already locked.

Implements yarp::os::Contactable.

Definition at line 367 of file BufferedPort-inl.h.

◆ unlockCallback()

template<typename T >
void yarp::os::BufferedPort< T >::unlockCallback ( )
overridevirtual

Unlock callbacks.

Implements yarp::os::Contactable.

Definition at line 373 of file BufferedPort-inl.h.

◆ unprepare()

template<typename T >
bool yarp::os::BufferedPort< T >::unprepare ( )

Give the last prepared object back to YARP without writing it.

Returns
true if there was a prepared object to return.

Definition at line 120 of file BufferedPort-inl.h.

◆ useCallback() [1/2]

template<typename T>
void yarp::os::BufferedPort< T >::useCallback ( TypedReaderCallback< T > &  callback)
overridevirtual

Set an object whose onRead method will be called when data is available.

Parameters
callbackthe object whose onRead method will be called with data

Implements yarp::os::TypedReader< T >.

Definition at line 211 of file BufferedPort-inl.h.

◆ useCallback() [2/2]

template<typename T>
void yarp::os::BufferedPort< T >::useCallback ( )

Use own onRead() method as callback.

User can override that method to be informed about data as it arrives.

Definition at line 218 of file BufferedPort-inl.h.

◆ waitForWrite()

template<typename T >
void yarp::os::BufferedPort< T >::waitForWrite ( )

Wait for any pending writes to complete.

Definition at line 141 of file BufferedPort-inl.h.

◆ where()

template<typename T >
yarp::os::Contact yarp::os::BufferedPort< T >::where ( ) const
overridevirtual

Returns information about how this port can be reached.

Returns
network parameters for this port

Implements yarp::os::Contactable.

Definition at line 102 of file BufferedPort-inl.h.

◆ write()

template<typename T >
void yarp::os::BufferedPort< T >::write ( bool  forceStrict = false)

Write the current object being returned by BufferedPort::prepare.

Warning
That object should no longer be touched by the user of this class, it is now owned by the communications system. The BufferedPort::prepare method should be called again to get a fresh (or reused) object guaranteed to be not in use by the communications system.
Parameters
forceStrictIf this is true, wait until any previous sends are complete. If false, the current object will not be sent on connections that are currently busy.

Definition at line 126 of file BufferedPort-inl.h.

◆ writeStrict()

template<typename T >
void yarp::os::BufferedPort< T >::writeStrict ( )

Write the current object being returned by BufferedPort::prepare, waiting until any previous sends are complete.

Warning
That object should no longer be touched by the user of this class it is now owned by the communications system. The BufferedPort::prepare method should be called again to get a fresh (or reused) object guaranteed to be not in use by the communications system.

Definition at line 135 of file BufferedPort-inl.h.

Member Data Documentation

◆ attached

template<typename T>
bool yarp::os::BufferedPort< T >::attached
private

Definition at line 311 of file BufferedPort.h.

◆ interrupted

template<typename T>
bool yarp::os::BufferedPort< T >::interrupted
private

Definition at line 310 of file BufferedPort.h.

◆ port

template<typename T>
Port yarp::os::BufferedPort< T >::port
private

Definition at line 308 of file BufferedPort.h.

◆ reader

template<typename T>
PortReaderBuffer<T> yarp::os::BufferedPort< T >::reader
private

Definition at line 309 of file BufferedPort.h.

◆ writer

template<typename T>
PortWriterBuffer<T> yarp::os::BufferedPort< T >::writer
private

Definition at line 307 of file BufferedPort.h.


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