YARP  2.3.70.1
Yet Another Robot Platform
yarp::os::InputStream Class Referenceabstract

Simple specification of the minimum functions needed from input streams. More...

#include <yarp/os/InputStream.h>

+ Inheritance diagram for yarp::os::InputStream:

Public Types

typedef void(* readEnvelopeCallbackType) (void *, const yarp::os::Bytes &envelope)
 Callback type for setting the envelope from a message in carriers that cannot be escaped. More...
 

Public Member Functions

 InputStream ()
 Constructor. More...
 
virtual ~InputStream ()
 Destructor. More...
 
virtual void check ()
 Perform maintenance actions, if needed. More...
 
virtual int read ()
 Read and return a single byte. More...
 
virtual YARP_SSIZE_T read (const Bytes &b, size_t offset, YARP_SSIZE_T len)
 Read a block of data from the stream. More...
 
virtual YARP_SSIZE_T read (const yarp::os::Bytes &b)=0
 Read a block of data from the stream. More...
 
virtual YARP_SSIZE_T partialRead (const yarp::os::Bytes &b)
 Like read, but solicit partial responses. More...
 
virtual void close ()=0
 Terminate the stream. More...
 
virtual void interrupt ()
 Interrupt the stream. More...
 
virtual bool isOk ()=0
 Check if the stream is ok or in an error state. More...
 
virtual bool setReadTimeout (double timeout)
 Set activity timeout. More...
 
ConstString readLine (int terminal='\n', bool *success=YARP_NULLPTR)
 Read a block of text terminated with a specific marker (or EOF). More...
 
YARP_SSIZE_T readFull (const Bytes &b)
 Keep reading until buffer is full. More...
 
YARP_SSIZE_T readDiscard (size_t len)
 Read and discard a fixed number of bytes. More...
 
virtual bool setReadEnvelopeCallback (readEnvelopeCallbackType callback, void *data)
 Install a callback that the InputStream will have to call when the envelope is read from a message in carriers that cannot be escaped. More...
 

Detailed Description

Simple specification of the minimum functions needed from input streams.

The streams could be TCP, UDP, MCAST, ...

Definition at line 24 of file InputStream.h.

Member Typedef Documentation

◆ readEnvelopeCallbackType

typedef void(* yarp::os::InputStream::readEnvelopeCallbackType) (void *, const yarp::os::Bytes &envelope)

Callback type for setting the envelope from a message in carriers that cannot be escaped.

Definition at line 165 of file InputStream.h.

Constructor & Destructor Documentation

◆ InputStream()

yarp::os::InputStream::InputStream ( )
inline

Constructor.

Definition at line 31 of file InputStream.h.

◆ ~InputStream()

virtual yarp::os::InputStream::~InputStream ( )
inlinevirtual

Destructor.

Definition at line 39 of file InputStream.h.

Member Function Documentation

◆ check()

virtual void yarp::os::InputStream::check ( )
inlinevirtual

Perform maintenance actions, if needed.

This method is called frequently by YARP when a stream is being accessed. By default, it does nothing.

Definition at line 48 of file InputStream.h.

◆ close()

◆ interrupt()

virtual void yarp::os::InputStream::interrupt ( )
inlinevirtual

◆ isOk()

◆ partialRead()

virtual YARP_SSIZE_T yarp::os::InputStream::partialRead ( const yarp::os::Bytes b)
inlinevirtual

Like read, but solicit partial responses.

Reimplemented in yarp::os::impl::SocketTwoWayStream.

Definition at line 102 of file InputStream.h.

◆ read() [1/3]

virtual int yarp::os::InputStream::read ( )
inlinevirtual

Read and return a single byte.

Should block and wait for data. By default, this calls read(const Bytes& b) to do its work.

Returns
a byte from the stream (0-255), or -1 on failure.

Definition at line 58 of file InputStream.h.

◆ read() [2/3]

virtual YARP_SSIZE_T yarp::os::InputStream::read ( const Bytes b,
size_t  offset,
YARP_SSIZE_T  len 
)
inlinevirtual

Read a block of data from the stream.

Should block and wait for data. By default, this calls read(const Bytes& b) to do its work.

Parameters
bthe block of data to read to
offsetan offset within the block to start at
lenthe number of bytes to read
Returns
the number of bytes read, or -1 upon error

Definition at line 80 of file InputStream.h.

◆ read() [3/3]

virtual YARP_SSIZE_T yarp::os::InputStream::read ( const yarp::os::Bytes b)
pure virtual

◆ readDiscard()

YARP_SSIZE_T InputStream::readDiscard ( size_t  len)

Read and discard a fixed number of bytes.

Definition at line 70 of file InputStream.cpp.

◆ readFull()

YARP_SSIZE_T InputStream::readFull ( const Bytes b)

Keep reading until buffer is full.

Definition at line 55 of file InputStream.cpp.

◆ readLine()

ConstString InputStream::readLine ( int  terminal = '\n',
bool *  success = YARP_NULLPTR 
)

Read a block of text terminated with a specific marker (or EOF).

Definition at line 14 of file InputStream.cpp.

◆ setReadEnvelopeCallback()

virtual bool yarp::os::InputStream::setReadEnvelopeCallback ( readEnvelopeCallbackType  callback,
void *  data 
)
inlinevirtual

Install a callback that the InputStream will have to call when the envelope is read from a message in carriers that cannot be escaped.

Parameters
callbackthe callback to execute
dataa pointer that should be passed as first parameter to the callback function
Returns
true iff the callback was installed.

Reimplemented in yarp::os::MjpegStream.

Definition at line 178 of file InputStream.h.

◆ setReadTimeout()

virtual bool yarp::os::InputStream::setReadTimeout ( double  timeout)
inlinevirtual

Set activity timeout.

Support for this is optional. 0 = wait forever.

Returns
true iff timeout is supported.

Reimplemented in yarp::os::impl::SocketTwoWayStream.

Definition at line 136 of file InputStream.h.


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