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:

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.

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 (int 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...
 

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 18 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::TcpRosStream, yarp::os::XmlRpcStream, yarp::os::impl::DgramTwoWayStream, yarp::os::MjpegStream, yarp::os::impl::SocketTwoWayStream, yarp::os::impl::LocalCarrierStream, yarp::os::MpiStream, HumanStream, and ShmemHybridStream.

Definition at line 44 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 39 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.

Definition at line 22 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 33 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 114 of file InputStream.cpp.

◆ readFull()

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

Keep reading until buffer is full.

Definition at line 98 of file InputStream.cpp.

◆ readLine()

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

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

Definition at line 56 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 yarp::os::MjpegStream, and yarp::os::H264Stream.

Definition at line 125 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 48 of file InputStream.cpp.


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