YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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.
 
virtual ~PortReaderBuffer ()
 Destructor.
 
void detach ()
 
void setStrict (bool strict=true) override
 Call this to strictly keep all messages, or allow old ones to be quietly dropped.
 
bool check ()
 Check if data is available.
 
int getPendingReads () override
 Check how many messages are waiting to be read.
 
T * read (bool shouldWait=true) override
 Read an available object from the port.
 
void interrupt () override
 Abort any read operation currently in progress.
 
T * lastRead () override
 Get the last data returned by read()
 
void attach (Port &port)
 Attach this buffer to a particular port.
 
void useCallback (TypedReaderCallback< T > &callback) override
 Set an object whose onRead method will be called when data is available.
 
void disableCallback () override
 Remove a callback set up with useCallback()
 
virtual bool read (ConnectionReader &connection)
 Reads objects from a network connection.
 
PortReadercreate () const override
 Factory method.
 
void setReplier (PortReader &reader) override
 If a message is received that requires a reply, use this handler.
 
virtual bool getEnvelope (PortReader &envelope)
 
bool isClosed () override
 Returns whether the port associated with this reader has been closed.
 
std::string getName () const override
 Get name of port being read from.
 
bool acceptObject (T *obj, PortWriter *wrapper) override
 Send object obj; expect callback to wrapper when obj is no longer in use.
 
bool forgetObject (T *obj, yarp::os::PortWriter *wrapper) override
 Sender is no longer interested in getting callbacks.
 
voidacquire () override
 Take control of the last object read.
 
void release (void *handle) override
 Return control to YARP of an object previously taken control of with the acquire() method.
 
void setTargetPeriod (double period) override
 Try to provide data periodically.
 
- Public Member Functions inherited from yarp::os::TypedReader< T >
virtual ~TypedReader ()=default
 Destructor.
 
- Public Member Functions inherited from yarp::os::LocalReader< T >
virtual ~LocalReader ()=default
 
- Public Member Functions inherited from yarp::os::PortReaderBufferBaseCreator
virtual ~PortReaderBufferBaseCreator ()
 

Detailed Description

template<typename 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 35 of file PortReaderBuffer.h.

Constructor & Destructor Documentation

◆ PortReaderBuffer()

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

Constructor.

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

Definition at line 12 of file PortReaderBuffer-inl.h.

◆ ~PortReaderBuffer()

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

Destructor.

Definition at line 24 of file PortReaderBuffer-inl.h.

Member Function Documentation

◆ acceptObject()

template<typename T >
bool yarp::os::PortReaderBuffer< T >::acceptObject ( T *  obj,
PortWriter wrapper 
)
overridevirtual

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

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

Definition at line 180 of file PortReaderBuffer-inl.h.

◆ acquire()

template<typename T >
void * yarp::os::PortReaderBuffer< 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 192 of file PortReaderBuffer-inl.h.

◆ attach()

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

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

◆ check()

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

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

◆ create()

template<typename T >
yarp::os::PortReader * yarp::os::PortReaderBuffer< T >::create ( ) const
overridevirtual

Factory method.

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

Returns
new instance of the templated type.

Implements yarp::os::PortReaderBufferBaseCreator.

Definition at line 150 of file PortReaderBuffer-inl.h.

◆ detach()

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

Definition at line 30 of file PortReaderBuffer-inl.h.

◆ disableCallback()

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

Remove a callback set up with useCallback()

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

Definition at line 134 of file PortReaderBuffer-inl.h.

◆ forgetObject()

template<typename T >
bool yarp::os::PortReaderBuffer< T >::forgetObject ( T *  obj,
yarp::os::PortWriter wrapper 
)
overridevirtual

Sender is no longer interested in getting callbacks.

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

Definition at line 186 of file PortReaderBuffer-inl.h.

◆ getEnvelope()

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

Definition at line 162 of file PortReaderBuffer-inl.h.

◆ getName()

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

Get name of port being read from.

Returns
name of port

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

Definition at line 174 of file PortReaderBuffer-inl.h.

◆ getPendingReads()

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

Check how many messages are waiting to be read.

Returns
number of pending messages

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

Definition at line 62 of file PortReaderBuffer-inl.h.

◆ interrupt()

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

Abort any read operation currently in progress.

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

Definition at line 104 of file PortReaderBuffer-inl.h.

◆ isClosed()

template<typename T >
bool yarp::os::PortReaderBuffer< 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 168 of file PortReaderBuffer-inl.h.

◆ lastRead()

template<typename T >
T * yarp::os::PortReaderBuffer< 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 110 of file PortReaderBuffer-inl.h.

◆ read() [1/2]

template<typename T >
T * yarp::os::PortReaderBuffer< 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 69 of file PortReaderBuffer-inl.h.

◆ read() [2/2]

template<typename T >
bool yarp::os::PortReaderBuffer< T >::read ( ConnectionReader connection)
virtual

Reads objects from a network connection.

This method is called by a port when data is received.

Parameters
connectionan interface to the network connection for reading
Returns
true iff the object is successfully read

Definition at line 144 of file PortReaderBuffer-inl.h.

◆ release()

template<typename T >
void yarp::os::PortReaderBuffer< 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 198 of file PortReaderBuffer-inl.h.

◆ setReplier()

template<typename T >
void yarp::os::PortReaderBuffer< 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 156 of file PortReaderBuffer-inl.h.

◆ setStrict()

template<typename T >
void yarp::os::PortReaderBuffer< 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 48 of file PortReaderBuffer-inl.h.

◆ setTargetPeriod()

template<typename T >
void yarp::os::PortReaderBuffer< 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 204 of file PortReaderBuffer-inl.h.

◆ useCallback()

template<typename T >
void yarp::os::PortReaderBuffer< 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 123 of file PortReaderBuffer-inl.h.


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