Buffer incoming data to a port. More...
#include <yarp/os/PortReaderBuffer.h>
Public Member Functions | |
PortReaderBuffer (unsigned int maxBuffer=0) | |
Constructor. More... | |
virtual | ~PortReaderBuffer () |
Destructor. More... | |
void | detach () |
void | setStrict (bool strict=true) 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... | |
int | getPendingReads () override |
Check how many messages are waiting to be read. More... | |
T * | read (bool shouldWait=true) override |
Read an available object from the port. More... | |
void | interrupt () override |
Abort any read operation currently in progress. More... | |
T * | lastRead () 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) override |
Set an object whose onRead method will be called when data is available. More... | |
void | disableCallback () override |
Remove a callback set up with useCallback() More... | |
virtual bool | read (ConnectionReader &connection) |
Reads objects from a network connection. More... | |
PortReader * | create () const override |
Factory method. More... | |
void | setReplier (PortReader &reader) override |
If a message is received that requires a reply, use this handler. More... | |
virtual bool | getEnvelope (PortReader &envelope) |
bool | isClosed () override |
Returns whether the port associated with this reader has been closed. More... | |
std::string | getName () const override |
Get name of port being read from. More... | |
bool | acceptObject (T *obj, PortWriter *wrapper) override |
Send object obj; expect callback to wrapper when obj is no longer in use. More... | |
bool | forgetObject (T *obj, yarp::os::PortWriter *wrapper) override |
Sender is no longer interested in getting callbacks. More... | |
void * | acquire () override |
Take control of the last object read. More... | |
void | release (void *handle) override |
Return control to YARP of an object previously taken control of with the acquire() method. More... | |
void | setTargetPeriod (double period) override |
Try to provide data periodically. More... | |
Public Member Functions inherited from yarp::os::TypedReader< T > | |
virtual | ~TypedReader ()=default |
Destructor. More... | |
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 39 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 15 of file PortReaderBuffer-inl.h.
|
virtual |
Destructor.
Definition at line 27 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 183 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 195 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 119 of file PortReaderBuffer-inl.h.
bool yarp::os::PortReaderBuffer< T >::check |
Check if data is available.
Definition at line 59 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 153 of file PortReaderBuffer-inl.h.
void yarp::os::PortReaderBuffer< T >::detach |
Definition at line 33 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Remove a callback set up with useCallback()
Implements yarp::os::TypedReader< T >.
Definition at line 137 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Sender is no longer interested in getting callbacks.
Implements yarp::os::LocalReader< T >.
Definition at line 189 of file PortReaderBuffer-inl.h.
|
virtual |
Definition at line 165 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Get name of port being read from.
Implements yarp::os::TypedReader< T >.
Definition at line 177 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Check how many messages are waiting to be read.
Implements yarp::os::TypedReader< T >.
Definition at line 65 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Abort any read operation currently in progress.
Implements yarp::os::TypedReader< T >.
Definition at line 107 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 171 of file PortReaderBuffer-inl.h.
|
overridevirtual |
Get the last data returned by read()
Implements yarp::os::TypedReader< T >.
Definition at line 113 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 72 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 147 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 201 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 159 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 51 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 207 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 126 of file PortReaderBuffer-inl.h.