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

Buffer incoming data to a port. More...

#include <yarp/os/PortReaderBuffer.h>

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

Public Member Functions

 PortReaderBuffer (unsigned int maxBuffer=0)
 Constructor. More...
 
virtual ~PortReaderBuffer ()
 Destructor. More...
 
void detach ()
 
virtual void setStrict (bool strict=true) YARP_OVERRIDE
 Call this to strictly keep all messages, or allow old ones to be quietly dropped. More...
 
bool check ()
 Check if data is available. More...
 
virtual int getPendingReads () YARP_OVERRIDE
 Check how many messages are waiting to be read. More...
 
T * read (bool shouldWait=true) YARP_OVERRIDE
 Read an available object from the port. More...
 
void interrupt () YARP_OVERRIDE
 Abort any read operation currently in progress. More...
 
T * lastRead () YARP_OVERRIDE
 Get the last data returned by read() More...
 
void attach (Port &port)
 Attach this buffer to a particular port. More...
 
void useCallback (TypedReaderCallback< T > &callback) YARP_OVERRIDE
 Set an object whose onRead method will be called when data is available. More...
 
void disableCallback () YARP_OVERRIDE
 Remove a callback set up with useCallback() More...
 
virtual PortReadercreate () YARP_OVERRIDE
 Factory method. More...
 
void setReplier (PortReader &reader) YARP_OVERRIDE
 If a message is received that requires a reply, use this handler. More...
 
virtual bool getEnvelope (PortReader &envelope)
 
bool isClosed () YARP_OVERRIDE
 
virtual ConstString getName () const YARP_OVERRIDE
 Get name of port being read from. More...
 
virtual bool acceptObject (T *obj, PortWriter *wrapper) YARP_OVERRIDE
 Send object obj; expect callback to wrapper when obj is no longer in use. More...
 
virtual bool forgetObject (T *obj, yarp::os::PortWriter *wrapper) YARP_OVERRIDE
 Sender is no longer interested in getting callbacks. More...
 
virtual void * acquire () YARP_OVERRIDE
 Take control of the last object read. More...
 
virtual void release (void *handle) YARP_OVERRIDE
 Return control to YARP of an object previously taken control of with the acquire() method. More...
 
virtual void setTargetPeriod (double period) YARP_OVERRIDE
 Try to provide data periodically. More...
 
- Public Member Functions inherited from yarp::os::TypedReader< T >
virtual ~TypedReader ()
 Destructor. More...
 
- Public Member Functions inherited from yarp::os::LocalReader< T >
virtual ~LocalReader ()
 

Private Attributes

yarp::os::impl::PortReaderBufferBase implementation
 
bool autoDiscard
 
T * last
 
T * default_value
 
TypedReaderThread< T > * reader
 

Detailed Description

template<class T>
class yarp::os::PortReaderBuffer< T >

Buffer incoming data to a port.

An instance of this class can be associated with a Port by calling attach(). From then on data that arrives to the Port will be passed to this buffer, to be picked up at the user's leisure by calling check() and read(). "T" should be a PortReader class, such as Bottle.

Definition at line 21 of file PortReaderBuffer.h.

Constructor & Destructor Documentation

◆ PortReaderBuffer()

template<class T>
yarp::os::PortReaderBuffer< T >::PortReaderBuffer ( unsigned int  maxBuffer = 0)
inline

Constructor.

Parameters
maxBufferMaximum number of buffers permitted (0 = no limit)

Definition at line 348 of file PortReaderBuffer.h.

◆ ~PortReaderBuffer()

template<class T>
virtual yarp::os::PortReaderBuffer< T >::~PortReaderBuffer ( )
inlinevirtual

Destructor.

Definition at line 360 of file PortReaderBuffer.h.

Member Function Documentation

◆ acceptObject()

template<class T>
virtual bool yarp::os::PortReaderBuffer< T >::acceptObject ( T *  obj,
PortWriter wrapper 
)
inlinevirtual

Send object obj; expect callback to wrapper when obj is no longer in use.

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

Definition at line 517 of file PortReaderBuffer.h.

◆ acquire()

template<class T>
virtual void* yarp::os::PortReaderBuffer< T >::acquire ( )
inlinevirtual

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 528 of file PortReaderBuffer.h.

◆ attach()

template<class T>
void yarp::os::PortReaderBuffer< T >::attach ( Port port)
inline

Attach this buffer to a particular port.

Data arriving to that port will from now on be placed in this buffer.

Parameters
portthe port to attach to

Definition at line 450 of file PortReaderBuffer.h.

◆ check()

template<class T>
bool yarp::os::PortReaderBuffer< T >::check ( )
inline

Check if data is available.

Returns
true iff data is available (i.e. a call to read() will return immediately and successfully)

Definition at line 392 of file PortReaderBuffer.h.

◆ create()

template<class T>
virtual PortReader* yarp::os::PortReaderBuffer< T >::create ( )
inlinevirtual

Factory method.

New instances are created as needed to store incoming data. By default, this just uses the default contructor - override this if you need to do something fancier (such as allocating a shared memory space).

Returns
new instance of the templated type.

Definition at line 496 of file PortReaderBuffer.h.

◆ detach()

template<class T>
void yarp::os::PortReaderBuffer< T >::detach ( )
inline

Definition at line 364 of file PortReaderBuffer.h.

◆ disableCallback()

template<class T>
void yarp::os::PortReaderBuffer< T >::disableCallback ( )
inlinevirtual

Remove a callback set up with useCallback()

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

Definition at line 464 of file PortReaderBuffer.h.

◆ forgetObject()

template<class T>
virtual bool yarp::os::PortReaderBuffer< T >::forgetObject ( T *  obj,
yarp::os::PortWriter wrapper 
)
inlinevirtual

Sender is no longer interested in getting callbacks.

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

Definition at line 522 of file PortReaderBuffer.h.

◆ getEnvelope()

template<class T>
virtual bool yarp::os::PortReaderBuffer< T >::getEnvelope ( PortReader envelope)
inlinevirtual

Definition at line 504 of file PortReaderBuffer.h.

◆ getName()

template<class T>
virtual ConstString yarp::os::PortReaderBuffer< T >::getName ( ) const
inlinevirtual

Get name of port being read from.

Returns
name of port

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

Definition at line 512 of file PortReaderBuffer.h.

◆ getPendingReads()

template<class T>
virtual int yarp::os::PortReaderBuffer< T >::getPendingReads ( )
inlinevirtual

Check how many messages are waiting to be read.

Returns
number of pending messages

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

Definition at line 396 of file PortReaderBuffer.h.

◆ interrupt()

template<class T>
void yarp::os::PortReaderBuffer< T >::interrupt ( )
inlinevirtual

Abort any read operation currently in progress.

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

Definition at line 436 of file PortReaderBuffer.h.

◆ isClosed()

template<class T>
bool yarp::os::PortReaderBuffer< T >::isClosed ( )
inlinevirtual
Returns
true if Port associated with this reader has been closed

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

Definition at line 508 of file PortReaderBuffer.h.

◆ lastRead()

template<class T>
T* yarp::os::PortReaderBuffer< T >::lastRead ( )
inlinevirtual

Get the last data returned by read()

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

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

Definition at line 441 of file PortReaderBuffer.h.

◆ read()

template<class T>
T* yarp::os::PortReaderBuffer< T >::read ( bool  shouldWait = true)
inlinevirtual

Read an available object from the port.

Parameters
shouldWaittrue if the method should wait until an object is available
Returns
A pointer to an object read from the port, or YARP_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 402 of file PortReaderBuffer.h.

◆ release()

template<class T>
virtual void yarp::os::PortReaderBuffer< T >::release ( void *  handle)
inlinevirtual

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 532 of file PortReaderBuffer.h.

◆ setReplier()

template<class T>
void yarp::os::PortReaderBuffer< T >::setReplier ( PortReader reader)
inlinevirtual

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 500 of file PortReaderBuffer.h.

◆ setStrict()

template<class T>
virtual void yarp::os::PortReaderBuffer< T >::setStrict ( bool  strict = true)
inlinevirtual

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.

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

Definition at line 381 of file PortReaderBuffer.h.

◆ setTargetPeriod()

template<class T>
virtual void yarp::os::PortReaderBuffer< T >::setTargetPeriod ( double  period)
inlinevirtual

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 536 of file PortReaderBuffer.h.

◆ useCallback()

template<class T>
void yarp::os::PortReaderBuffer< T >::useCallback ( TypedReaderCallback< T > &  callback)
inlinevirtual

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 455 of file PortReaderBuffer.h.

Member Data Documentation

◆ autoDiscard

template<class T>
bool yarp::os::PortReaderBuffer< T >::autoDiscard
private

Definition at line 542 of file PortReaderBuffer.h.

◆ default_value

template<class T>
T* yarp::os::PortReaderBuffer< T >::default_value
private

Definition at line 544 of file PortReaderBuffer.h.

◆ implementation

template<class T>
yarp::os::impl::PortReaderBufferBase yarp::os::PortReaderBuffer< T >::implementation
private

Definition at line 541 of file PortReaderBuffer.h.

◆ last

template<class T>
T* yarp::os::PortReaderBuffer< T >::last
private

Definition at line 543 of file PortReaderBuffer.h.

◆ reader

template<class T>
TypedReaderThread<T>* yarp::os::PortReaderBuffer< T >::reader
private

Definition at line 545 of file PortReaderBuffer.h.


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