Buffer incoming data to a port. More...
#include <yarp/os/PortReaderBuffer.h>
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. | |
PortReader * | create () 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. | |
void * | acquire () 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 () |
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.
yarp::os::PortReaderBuffer< T >::PortReaderBuffer | ( | unsigned int | maxBuffer = 0 | ) |
Constructor.
maxBuffer | Maximum number of buffers permitted (0 = no limit) |
Definition at line 12 of file PortReaderBuffer-inl.h.
|
virtual |
Destructor.
Definition at line 24 of file PortReaderBuffer-inl.h.
|
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.
|
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.
Implements yarp::os::TypedReader< T >.
Definition at line 192 of file PortReaderBuffer-inl.h.
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.
port | the port to attach to |
Definition at line 116 of file PortReaderBuffer-inl.h.
bool yarp::os::PortReaderBuffer< T >::check | ( | ) |
Check if data is available.
Definition at line 56 of file PortReaderBuffer-inl.h.
|
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).
Implements yarp::os::PortReaderBufferBaseCreator.
Definition at line 150 of file PortReaderBuffer-inl.h.
void yarp::os::PortReaderBuffer< T >::detach | ( | ) |
Definition at line 30 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Remove a callback set up with useCallback()
Implements yarp::os::TypedReader< T >.
Definition at line 134 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Sender is no longer interested in getting callbacks.
Implements yarp::os::LocalReader< T >.
Definition at line 186 of file PortReaderBuffer-inl.h.
|
virtual |
Definition at line 162 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Get name of port being read from.
Implements yarp::os::TypedReader< T >.
Definition at line 174 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Check how many messages are waiting to be read.
Implements yarp::os::TypedReader< T >.
Definition at line 62 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Abort any read operation currently in progress.
Implements yarp::os::TypedReader< T >.
Definition at line 104 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Returns whether the port associated with this reader has been closed.
Implements yarp::os::TypedReader< T >.
Definition at line 168 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Get the last data returned by read()
Implements yarp::os::TypedReader< T >.
Definition at line 110 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Read an available object from the port.
shouldWait | true if the method should wait until an object is available, false if the call should return immediately if no message is available |
Implements yarp::os::TypedReader< T >.
Definition at line 69 of file PortReaderBuffer-inl.h.
|
virtual |
Reads objects from a network connection.
This method is called by a port when data is received.
connection | an interface to the network connection for reading |
Definition at line 144 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Return control to YARP of an object previously taken control of with the acquire() method.
handle | the 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.
|
overridevirtual |
If a message is received that requires a reply, use this handler.
No buffering happens.
reader | the handler to use |
Implements yarp::os::TypedReader< T >.
Definition at line 156 of file PortReaderBuffer-inl.h.
|
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.
strict | True 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 48 of file PortReaderBuffer-inl.h.
|
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.
period | target period in (fractional) seconds. |
Implements yarp::os::TypedReader< T >.
Definition at line 204 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Set an object whose onRead method will be called when data is available.
callback | the object whose onRead method will be called with data |
Implements yarp::os::TypedReader< T >.
Definition at line 123 of file PortReaderBuffer-inl.h.