YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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.
 

Public Member Functions

 InputStream ()
 Constructor.
 
virtual ~InputStream ()
 Destructor.
 
virtual void check ()
 Perform maintenance actions, if needed.
 
virtual int read ()
 Read and return a single byte.
 
virtual yarp::conf::ssize_t read (Bytes &b, size_t offset, yarp::conf::ssize_t len)
 Read a block of data from the stream.
 
virtual yarp::conf::ssize_t read (yarp::os::Bytes &b)=0
 Read a block of data from the stream.
 
virtual yarp::conf::ssize_t partialRead (yarp::os::Bytes &b)
 Like read, but solicit partial responses.
 
virtual void close ()=0
 Terminate the stream.
 
virtual void interrupt ()
 Interrupt the stream.
 
virtual bool isOk () const =0
 Check if the stream is ok or in an error state.
 
virtual bool setReadTimeout (double timeout)
 Set activity timeout.
 
std::string readLine (const char terminal='\n', bool *success=nullptr)
 Read a block of text terminated with a specific marker (or EOF).
 
yarp::conf::ssize_t readFull (Bytes &b)
 Keep reading until buffer is full.
 
yarp::conf::ssize_t readDiscard (size_t len)
 Read and discard a fixed number of bytes.
 
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.
 

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 124 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 16 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 GstreamerStream, HumanStream, MjpegStream, MpiStream, ShmemHybridStream, UnixSockTwoWayStream, WebSocketStream, yarp::os::impl::DgramTwoWayStream, yarp::os::impl::LocalCarrierStream, and yarp::os::impl::SocketTwoWayStream.

Definition at line 42 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 37 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.

Definition at line 20 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

Reimplemented in yarp::os::StringInputStream.

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

◆ readFull()

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

Keep reading until buffer is full.

Definition at line 96 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 54 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 123 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 46 of file InputStream.cpp.


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