YARP
Yet Another Robot Platform
yarp::os::impl::ConnectionRecorder Class Reference

A helper for recording entire message/reply transactions. More...

#include <yarp/os/impl/ConnectionRecorder.h>

+ Inheritance diagram for yarp::os::impl::ConnectionRecorder:

Public Member Functions

 ConnectionRecorder ()
 
void init (yarp::os::ConnectionReader *wrappedReader)
 Call this to wrap a specific ConnectionReader. More...
 
void fini ()
 Call this when all reading/writing has been done. More...
 
const yarp::os::impl::BufferedConnectionWritergetMessage () const
 
const yarp::os::impl::BufferedConnectionWritergetReply () const
 
bool hasReply () const
 
bool expectBlock (char *data, size_t len) override
 Read a block of data from the network connection. More...
 
std::string expectText (const char terminatingChar) override
 Read some text from the network connection. More...
 
std::int8_t expectInt8 () override
 Read a 8-bit integer from the network connection. More...
 
std::int16_t expectInt16 () override
 Read a 16-bit integer from the network connection. More...
 
std::int32_t expectInt32 () override
 Read a 32-bit integer from the network connection. More...
 
std::int64_t expectInt64 () override
 Read a 64-bit integer from the network connection. More...
 
yarp::conf::float32_t expectFloat32 () override
 Read a 32-bit floating point number from the network connection. More...
 
yarp::conf::float64_t expectFloat64 () override
 Read a 64-bit floating point number from the network connection. More...
 
bool pushInt (int x) override
 Store an integer to return on the next call to expectInt() More...
 
bool isTextMode () const override
 Check if the connection is text mode. More...
 
bool isBareMode () const override
 Check if the connection is bare mode. More...
 
bool convertTextMode () override
 Reads in a standard description in text mode, and converts it to a standard description in binary. More...
 
size_t getSize () const override
 Checks how much data is available. More...
 
yarp::os::ConnectionWritergetWriter () override
 Gets a way to reply to the message, if possible. More...
 
yarp::os::PortablegetReference () const override
 Get a direct pointer to the object being sent, if possible. More...
 
yarp::os::Contact getRemoteContact () const override
 Gets information about who is supplying the data being read, if that information is available. More...
 
yarp::os::Contact getLocalContact () const override
 Gets information about who is receiving the data, if that information is available. More...
 
bool isValid () const override
 
bool isActive () const override
 
bool isError () const override
 
void appendBlock (const char *data, size_t len) override
 Send a block of data to the network connection. More...
 
void appendInt8 (std::int8_t data) override
 Send a representation of a 8-bit integer to the network connection. More...
 
void appendInt16 (std::int16_t data) override
 Send a representation of a 16-bit integer to the network connection. More...
 
void appendInt32 (std::int32_t data) override
 Send a representation of a 32-bit integer to the network connection. More...
 
void appendInt64 (std::int64_t data) override
 Send a representation of a 64-bit integer to the network connection. More...
 
void appendFloat32 (yarp::conf::float32_t data) override
 Send a representation of a 32-bit floating point number to the network connection. More...
 
void appendFloat64 (yarp::conf::float64_t data) override
 Send a representation of a 64-bit floating point number to the network connection. More...
 
void appendText (const std::string &str, const char terminate) override
 Send a terminated string to the network connection. More...
 
void appendExternalBlock (const char *data, size_t len) override
 Send a block of data to the network connection, without making a copy. More...
 
void declareSizes (int argc, int *argv) override
 If you can easily determine how many blocks there are in a message, call this first, before anything else. More...
 
void setReplyHandler (yarp::os::PortReader &reader) override
 This sets a handler to deal with replies to the message. More...
 
void setReference (yarp::os::Portable *obj) override
 Stores a direct pointer to the object being sent. More...
 
bool write (yarp::os::ConnectionWriter &connection) const override
 Write this object to a network connection. More...
 
void requestDrop () override
 Tag the connection to be dropped after the current message. More...
 
const yarp::os::SearchablegetConnectionModifiers () const override
 Access modifiers associated with the connection, if any. More...
 
yarp::os::SizedWritergetBuffer () const override
 
bool setSize (size_t len) override
 
- Public Member Functions inherited from yarp::os::ConnectionReader
virtual ~ConnectionReader ()
 Destructor. More...
 
virtual std::string expectString ()
 Read a string from the network connection. More...
 
virtual int expectInt () final
 Read an integer from the network connection. More...
 
virtual double expectDouble ()
 Read a floating point number from the network connection. More...
 
virtual Bytes readEnvelope ()
 Read a message envelope, if available. More...
 
virtual void setParentConnectionReader (ConnectionReader *parentConnectionReader)
 Set ConnectionReader to be used for reading the envelope. More...
 
- Public Member Functions inherited from yarp::os::ConnectionWriter
virtual ~ConnectionWriter ()
 Destructor. More...
 
virtual void appendInt (int data) final
 Send a representation of an integer to the network connection. More...
 
virtual void appendDouble (double data)
 Send a representation of a floating point number to the network connection. More...
 
virtual void appendString (const char *str, const char terminate='\n') final
 Send a character sequence to the network connection. More...
 
virtual void appendRawString (const std::string &str) final
 
void appendString (const std::string &str)
 Send a string to the network connection. More...
 
virtual bool isNull () const
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion () const
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement () const
 This is called when the port is about to begin writing operations. More...
 
virtual yarp::os::Type getWriteType () const
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::ConnectionReader
static ConnectionReadercreateConnectionReader (InputStream &is)
 Create an instance of YARP's standard connection reader implementation. More...
 
static bool readFromStream (PortReader &portable, InputStream &is)
 
- Static Public Member Functions inherited from yarp::os::ConnectionWriter
static ConnectionWritercreateBufferedConnectionWriter ()
 Create a connection writer implementation that stores to a buffer which can be read later using getBuffer() More...
 
static bool writeToStream (PortWriter &portable, OutputStream &os)
 

Detailed Description

A helper for recording entire message/reply transactions.

Definition at line 24 of file ConnectionRecorder.h.

Constructor & Destructor Documentation

◆ ConnectionRecorder()

yarp::os::impl::ConnectionRecorder::ConnectionRecorder ( )

Definition at line 11 of file ConnectionRecorder.cpp.

Member Function Documentation

◆ appendBlock()

void yarp::os::impl::ConnectionRecorder::appendBlock ( const char *  data,
size_t  len 
)
overridevirtual

Send a block of data to the network connection.

Since communication may not happen immediately, or may happen multiple times, a copy of this data is made. If you know the block of data will remain valid, and it is a large block of data, please call ConnectionWriter::appendExternalBlock instead.

Parameters
datathe start of the data block
lenthe length of the data block

Implements yarp::os::ConnectionWriter.

Definition at line 193 of file ConnectionRecorder.cpp.

◆ appendExternalBlock()

void yarp::os::impl::ConnectionRecorder::appendExternalBlock ( const char *  data,
size_t  len 
)
overridevirtual

Send a block of data to the network connection, without making a copy.

If you are not confident that the block of data will remain valid throughout transmission, call ConnectionWriter::appendBlock instead.

Parameters
datathe start of the data block
lenthe length of the data block

Implements yarp::os::ConnectionWriter.

Definition at line 241 of file ConnectionRecorder.cpp.

◆ appendFloat32()

void yarp::os::impl::ConnectionRecorder::appendFloat32 ( yarp::conf::float32_t  data)
overridevirtual

Send a representation of a 32-bit floating point number to the network connection.

Parameters
datathe floating point number to send

Implements yarp::os::ConnectionWriter.

Definition at line 223 of file ConnectionRecorder.cpp.

◆ appendFloat64()

void yarp::os::impl::ConnectionRecorder::appendFloat64 ( yarp::conf::float64_t  data)
overridevirtual

Send a representation of a 64-bit floating point number to the network connection.

Parameters
datathe floating point number to send

Implements yarp::os::ConnectionWriter.

Definition at line 229 of file ConnectionRecorder.cpp.

◆ appendInt16()

void yarp::os::impl::ConnectionRecorder::appendInt16 ( std::int16_t  data)
overridevirtual

Send a representation of a 16-bit integer to the network connection.

Parameters
datathe integer to send

Implements yarp::os::ConnectionWriter.

Definition at line 205 of file ConnectionRecorder.cpp.

◆ appendInt32()

void yarp::os::impl::ConnectionRecorder::appendInt32 ( std::int32_t  data)
overridevirtual

Send a representation of a 32-bit integer to the network connection.

Parameters
datathe integer to send

Implements yarp::os::ConnectionWriter.

Definition at line 211 of file ConnectionRecorder.cpp.

◆ appendInt64()

void yarp::os::impl::ConnectionRecorder::appendInt64 ( std::int64_t  data)
overridevirtual

Send a representation of a 64-bit integer to the network connection.

Parameters
datathe integer to send

Implements yarp::os::ConnectionWriter.

Definition at line 217 of file ConnectionRecorder.cpp.

◆ appendInt8()

void yarp::os::impl::ConnectionRecorder::appendInt8 ( std::int8_t  data)
overridevirtual

Send a representation of a 8-bit integer to the network connection.

Parameters
datathe integer to send

Implements yarp::os::ConnectionWriter.

Definition at line 199 of file ConnectionRecorder.cpp.

◆ appendText()

void yarp::os::impl::ConnectionRecorder::appendText ( const std::string &  str,
const char  terminate 
)
overridevirtual

Send a terminated string to the network connection.

The lenght of string is not specified in advance, therefore the reader should read until the terminating character is found.

Parameters
strthe string to send
terminatethe terminating character to use

Implements yarp::os::ConnectionWriter.

Definition at line 235 of file ConnectionRecorder.cpp.

◆ convertTextMode()

bool yarp::os::impl::ConnectionRecorder::convertTextMode ( )
overridevirtual

Reads in a standard description in text mode, and converts it to a standard description in binary.

Useful if you only operate on the binary description usually, and just want to permit text mode for command-line interaction. If isTextMode would return false, no conversion is done.

Returns
true if the conversion was possible

Implements yarp::os::ConnectionReader.

Definition at line 133 of file ConnectionRecorder.cpp.

◆ declareSizes()

void yarp::os::impl::ConnectionRecorder::declareSizes ( int  argc,
int *  argv 
)
overridevirtual

If you can easily determine how many blocks there are in a message, call this first, before anything else.

This may improve efficiency in some situations.

Parameters
argcNumber of blocks
argvAn array of integers, giving the length of each block

Implements yarp::os::ConnectionWriter.

Definition at line 247 of file ConnectionRecorder.cpp.

◆ expectBlock()

bool yarp::os::impl::ConnectionRecorder::expectBlock ( char *  data,
size_t  len 
)
overridevirtual

Read a block of data from the network connection.

Parameters
dataStart of the block of data
lenLength of the block of data
Returns
true on success

Implements yarp::os::ConnectionReader.

Definition at line 54 of file ConnectionRecorder.cpp.

◆ expectFloat32()

yarp::conf::float32_t yarp::os::impl::ConnectionRecorder::expectFloat32 ( )
overridevirtual

Read a 32-bit floating point number from the network connection.

Returns
the floating point number read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 102 of file ConnectionRecorder.cpp.

◆ expectFloat64()

yarp::conf::float64_t yarp::os::impl::ConnectionRecorder::expectFloat64 ( )
overridevirtual

Read a 64-bit floating point number from the network connection.

Returns
the floating point number read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 109 of file ConnectionRecorder.cpp.

◆ expectInt16()

std::int16_t yarp::os::impl::ConnectionRecorder::expectInt16 ( )
overridevirtual

Read a 16-bit integer from the network connection.

Returns
the integer read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 77 of file ConnectionRecorder.cpp.

◆ expectInt32()

std::int32_t yarp::os::impl::ConnectionRecorder::expectInt32 ( )
overridevirtual

Read a 32-bit integer from the network connection.

Returns
the integer read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 84 of file ConnectionRecorder.cpp.

◆ expectInt64()

std::int64_t yarp::os::impl::ConnectionRecorder::expectInt64 ( )
overridevirtual

Read a 64-bit integer from the network connection.

Returns
the integer read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 95 of file ConnectionRecorder.cpp.

◆ expectInt8()

std::int8_t yarp::os::impl::ConnectionRecorder::expectInt8 ( )
overridevirtual

Read a 8-bit integer from the network connection.

Returns
the integer read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 70 of file ConnectionRecorder.cpp.

◆ expectText()

std::string yarp::os::impl::ConnectionRecorder::expectText ( const char  terminatingChar)
overridevirtual

Read some text from the network connection.

Parameters
terminatingCharThe marker for the end of the text
Returns
the text read from the connection

Implements yarp::os::ConnectionReader.

Definition at line 63 of file ConnectionRecorder.cpp.

◆ fini()

void yarp::os::impl::ConnectionRecorder::fini ( )

Call this when all reading/writing has been done.

Definition at line 29 of file ConnectionRecorder.cpp.

◆ getBuffer()

yarp::os::SizedWriter * yarp::os::impl::ConnectionRecorder::getBuffer ( ) const
overridevirtual
Returns
a buffer if one is present.

Implements yarp::os::ConnectionWriter.

Definition at line 288 of file ConnectionRecorder.cpp.

◆ getConnectionModifiers()

const yarp::os::Searchable & yarp::os::impl::ConnectionRecorder::getConnectionModifiers ( ) const
overridevirtual

Access modifiers associated with the connection, if any.

Returns
connection configuration object

Implements yarp::os::ConnectionReader.

Definition at line 282 of file ConnectionRecorder.cpp.

◆ getLocalContact()

yarp::os::Contact yarp::os::impl::ConnectionRecorder::getLocalContact ( ) const
overridevirtual

Gets information about who is receiving the data, if that information is available.

Returns
contact information about sender (Contact::invalid if not available)

Implements yarp::os::ConnectionReader.

Definition at line 161 of file ConnectionRecorder.cpp.

◆ getMessage()

const yarp::os::impl::BufferedConnectionWriter & yarp::os::impl::ConnectionRecorder::getMessage ( ) const

Definition at line 39 of file ConnectionRecorder.cpp.

◆ getReference()

yarp::os::Portable * yarp::os::impl::ConnectionRecorder::getReference ( ) const
overridevirtual

Get a direct pointer to the object being sent, if possible.

This only makes sense in local operation, when sender and receiver are in the same process; in all other situations this returns nullptr.

Returns
The message object, or nullptr if not available

Implements yarp::os::ConnectionReader.

Definition at line 151 of file ConnectionRecorder.cpp.

◆ getRemoteContact()

yarp::os::Contact yarp::os::impl::ConnectionRecorder::getRemoteContact ( ) const
overridevirtual

Gets information about who is supplying the data being read, if that information is available.

Returns
contact information about sender (Contact::invalid if not available)

Implements yarp::os::ConnectionReader.

Definition at line 156 of file ConnectionRecorder.cpp.

◆ getReply()

const yarp::os::impl::BufferedConnectionWriter & yarp::os::impl::ConnectionRecorder::getReply ( ) const

Definition at line 44 of file ConnectionRecorder.cpp.

◆ getSize()

size_t yarp::os::impl::ConnectionRecorder::getSize ( ) const
overridevirtual

Checks how much data is available.

Returns
the number of bytes left on the connection.

Implements yarp::os::ConnectionReader.

Definition at line 138 of file ConnectionRecorder.cpp.

◆ getWriter()

yarp::os::ConnectionWriter * yarp::os::impl::ConnectionRecorder::getWriter ( )
overridevirtual

Gets a way to reply to the message, if possible.

Returns
An object that permits replies, or nullptr if this cannot be done.

Implements yarp::os::ConnectionReader.

Definition at line 143 of file ConnectionRecorder.cpp.

◆ hasReply()

bool yarp::os::impl::ConnectionRecorder::hasReply ( ) const

Definition at line 49 of file ConnectionRecorder.cpp.

◆ init()

void yarp::os::impl::ConnectionRecorder::init ( yarp::os::ConnectionReader wrappedReader)

Call this to wrap a specific ConnectionReader.

Definition at line 20 of file ConnectionRecorder.cpp.

◆ isActive()

bool yarp::os::impl::ConnectionRecorder::isActive ( ) const
overridevirtual
Returns
true if the reader is active. Readers become inactive if the connection they are associated with breaks.

Implements yarp::os::ConnectionReader.

Definition at line 175 of file ConnectionRecorder.cpp.

◆ isBareMode()

bool yarp::os::impl::ConnectionRecorder::isBareMode ( ) const
overridevirtual

Check if the connection is bare mode.

If it is, you are encouraged to omit type information from your serialization.

Returns
true if the connection is bare

Implements yarp::os::ConnectionReader.

Definition at line 128 of file ConnectionRecorder.cpp.

◆ isError()

bool yarp::os::impl::ConnectionRecorder::isError ( ) const
overridevirtual
Returns
true if the reader encountered an error. Readers can encounter an error if there is some data loss. For unreliable protocols like UDP/Multicast, where losses are not unexpected, this error flag will be reset for the next incoming message.

Implements yarp::os::ConnectionReader.

Definition at line 184 of file ConnectionRecorder.cpp.

◆ isTextMode()

bool yarp::os::impl::ConnectionRecorder::isTextMode ( ) const
overridevirtual

Check if the connection is text mode.

If it is, you are encouraged (but by no means required) to use a human-readable representation of your data structure.

Returns
true if the connection is text mode (as opposed to binary)

Implements yarp::os::ConnectionReader.

Definition at line 123 of file ConnectionRecorder.cpp.

◆ isValid()

bool yarp::os::impl::ConnectionRecorder::isValid ( ) const
overridevirtual
Returns
true if the reader is valid. Invalid readers may signal a shutdown.

Implements yarp::os::ConnectionReader.

Definition at line 166 of file ConnectionRecorder.cpp.

◆ pushInt()

bool yarp::os::impl::ConnectionRecorder::pushInt ( int  x)
overridevirtual

Store an integer to return on the next call to expectInt()

Parameters
xthe integer to store
Returns
true on success

Implements yarp::os::ConnectionReader.

Definition at line 116 of file ConnectionRecorder.cpp.

◆ requestDrop()

void yarp::os::impl::ConnectionRecorder::requestDrop ( )
overridevirtual

Tag the connection to be dropped after the current message.

Implements yarp::os::ConnectionReader.

Definition at line 278 of file ConnectionRecorder.cpp.

◆ setReference()

void yarp::os::impl::ConnectionRecorder::setReference ( yarp::os::Portable obj)
overridevirtual

Stores a direct pointer to the object being sent.

This is useful for local communication, to bypass serialization.

Implements yarp::os::ConnectionWriter.

Definition at line 257 of file ConnectionRecorder.cpp.

◆ setReplyHandler()

void yarp::os::impl::ConnectionRecorder::setReplyHandler ( yarp::os::PortReader reader)
overridevirtual

This sets a handler to deal with replies to the message.

The handler will be called once per connection. There will be problems for connections using carriers that don't support replies.

Parameters
readerthe object that handles replies.

Implements yarp::os::ConnectionWriter.

Definition at line 252 of file ConnectionRecorder.cpp.

◆ setSize()

bool yarp::os::impl::ConnectionRecorder::setSize ( size_t  len)
overridevirtual

Implements yarp::os::ConnectionReader.

Definition at line 293 of file ConnectionRecorder.cpp.

◆ write()

bool yarp::os::impl::ConnectionRecorder::write ( yarp::os::ConnectionWriter writer) const
overridevirtual

Write this object to a network connection.

Override this for your particular class. Be aware that depending on the nature of the connections a port has, and what protocol they use, and how efficient the YARP implementation is, this method may be called once, twice, or many times, as the result of a single call to Port::write

Parameters
writeran interface to the network connection for writing
Returns
true iff the object is successfully written

Implements yarp::os::PortWriter.

Definition at line 262 of file ConnectionRecorder.cpp.


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