YARP
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::conf::ssize_t read (Bytes &b, size_t offset, yarp::conf::ssize_t len)
 Read a block of data from the stream. More...
 
virtual yarp::conf::ssize_t read (yarp::os::Bytes &b)=0
 Read a block of data from the stream. More...
 
virtual yarp::conf::ssize_t partialRead (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 () const =0
 Check if the stream is ok or in an error state. More...
 
virtual bool setReadTimeout (double timeout)
 Set activity timeout. More...
 
std::string readLine (const char terminal='\n', bool *success=nullptr)
 Read a block of text terminated with a specific marker (or EOF). More...
 
yarp::conf::ssize_t readFull (Bytes &b)
 Keep reading until buffer is full. More...
 
yarp::conf::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 28 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 128 of file InputStream.h.

Constructor & Destructor Documentation

◆ InputStream()

InputStream::InputStream ( )
default

Constructor.

◆ ~InputStream()

InputStream::~InputStream ( )
virtualdefault

Destructor.

Member Function Documentation

◆ check()

void InputStream::check ( )
virtual

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 19 of file InputStream.cpp.

◆ close()

◆ interrupt()

void InputStream::interrupt ( )
virtual

Interrupt the stream.

If the stream is currently in a blocked state, it must be unblocked.

Reimplemented in yarp::os::impl::SocketTwoWayStream, yarp::os::impl::LocalCarrierStream, yarp::os::impl::DgramTwoWayStream, XmlRpcStream, UnixSockTwoWayStream, TcpRosStream, ShmemHybridStream, MpiStream, MjpegStream, and HumanStream.

Definition at line 45 of file InputStream.cpp.

◆ isOk()

◆ partialRead()

yarp::conf::ssize_t InputStream::partialRead ( yarp::os::Bytes b)
virtual

Like read, but solicit partial responses.

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

Definition at line 40 of file InputStream.cpp.

◆ read() [1/3]

int InputStream::read ( )
virtual

Read and return a single byte.

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

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

Reimplemented in yarp::os::StringInputStream, MpiP2PStream, MpiBcastStream, yarp::os::StringInputStream, and yarp::os::StringInputStream.

Definition at line 23 of file InputStream.cpp.

◆ read() [2/3]

yarp::conf::ssize_t InputStream::read ( Bytes b,
size_t  offset,
yarp::conf::ssize_t  len 
)
virtual

Read a block of data from the stream.

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

Parameters
[out]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 34 of file InputStream.cpp.

◆ read() [3/3]

virtual yarp::conf::ssize_t yarp::os::InputStream::read ( yarp::os::Bytes b)
pure virtual

◆ readDiscard()

yarp::conf::ssize_t InputStream::readDiscard ( size_t  len)

Read and discard a fixed number of bytes.

Definition at line 115 of file InputStream.cpp.

◆ readFull()

yarp::conf::ssize_t InputStream::readFull ( Bytes b)

Keep reading until buffer is full.

Definition at line 99 of file InputStream.cpp.

◆ readLine()

std::string InputStream::readLine ( const char  terminal = '\n',
bool *  success = nullptr 
)

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

Definition at line 57 of file InputStream.cpp.

◆ setReadEnvelopeCallback()

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

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 MjpegStream.

Definition at line 126 of file InputStream.cpp.

◆ setReadTimeout()

bool InputStream::setReadTimeout ( double  timeout)
virtual

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 49 of file InputStream.cpp.


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