YARP
Yet Another Robot Platform
ConnectionRecorder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_IMPL_CONNECTIONRECORDER_H
11 #define YARP_OS_IMPL_CONNECTIONRECORDER_H
12 
13 #include <yarp/os/Bottle.h>
16 #include <yarp/os/PortWriter.h>
18 
19 namespace yarp {
20 namespace os {
21 namespace impl {
22 
23 
31 {
32 private:
37  bool writing;
38  bool wrote;
39  bool skipNextInt;
40  yarp::os::Bottle blank;
41 
42 public:
44 
48  void init(yarp::os::ConnectionReader* wrappedReader);
49 
53  void fini();
54 
57  bool hasReply() const;
58 
59  bool expectBlock(char* data, size_t len) override;
60  std::string expectText(const char terminatingChar) override;
61  std::int8_t expectInt8() override;
62  std::int16_t expectInt16() override;
63  std::int32_t expectInt32() override;
64  std::int64_t expectInt64() override;
67  bool pushInt(int x) override;
68  bool isTextMode() const override;
69  bool isBareMode() const override;
70  bool convertTextMode() override;
71  size_t getSize() const override;
73  yarp::os::Portable* getReference() const override;
74  yarp::os::Contact getRemoteContact() const override;
75  yarp::os::Contact getLocalContact() const override;
76  bool isValid() const override;
77  bool isActive() const override;
78  bool isError() const override;
79  void appendBlock(const char* data, size_t len) override;
80  void appendInt8(std::int8_t data) override;
81  void appendInt16(std::int16_t data) override;
82  void appendInt32(std::int32_t data) override;
83  void appendInt64(std::int64_t data) override;
84  void appendFloat32(yarp::conf::float32_t data) override;
85  void appendFloat64(yarp::conf::float64_t data) override;
86  void appendText(const std::string& str, const char terminate) override;
87  void appendExternalBlock(const char* data, size_t len) override;
88  void declareSizes(int argc, int* argv) override;
89  void setReplyHandler(yarp::os::PortReader& reader) override;
90  void setReference(yarp::os::Portable* obj) override;
91  bool write(yarp::os::ConnectionWriter& connection) const override;
92  void requestDrop() override;
93  const yarp::os::Searchable& getConnectionModifiers() const override;
94  yarp::os::SizedWriter* getBuffer() const override;
95  bool setSize(size_t len) override;
96 };
97 
98 } // namespace impl
99 } // namespace os
100 } // namespace yarp
101 
102 #endif // YARP_OS_IMPL_CONNECTIONRECORDER_H
yarp::os::impl::ConnectionRecorder::getSize
size_t getSize() const override
Checks how much data is available.
Definition: ConnectionRecorder.cpp:141
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::os::impl::ConnectionRecorder::setReplyHandler
void setReplyHandler(yarp::os::PortReader &reader) override
This sets a handler to deal with replies to the message.
Definition: ConnectionRecorder.cpp:255
yarp::os::impl::ConnectionRecorder::expectInt16
std::int16_t expectInt16() override
Read a 16-bit integer from the network connection.
Definition: ConnectionRecorder.cpp:80
yarp::os::impl::ConnectionRecorder::isActive
bool isActive() const override
Definition: ConnectionRecorder.cpp:178
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
yarp::os::impl::ConnectionRecorder::init
void init(yarp::os::ConnectionReader *wrappedReader)
Call this to wrap a specific ConnectionReader.
Definition: ConnectionRecorder.cpp:23
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::os::impl::ConnectionRecorder::getConnectionModifiers
const yarp::os::Searchable & getConnectionModifiers() const override
Access modifiers associated with the connection, if any.
Definition: ConnectionRecorder.cpp:285
yarp::os::impl::ConnectionRecorder::getBuffer
yarp::os::SizedWriter * getBuffer() const override
Definition: ConnectionRecorder.cpp:291
yarp::os::impl::ConnectionRecorder::isTextMode
bool isTextMode() const override
Check if the connection is text mode.
Definition: ConnectionRecorder.cpp:126
ConnectionWriter.h
yarp::os::impl::ConnectionRecorder::appendText
void appendText(const std::string &str, const char terminate) override
Send a terminated string to the network connection.
Definition: ConnectionRecorder.cpp:238
yarp::os::impl::ConnectionRecorder::declareSizes
void declareSizes(int argc, int *argv) override
If you can easily determine how many blocks there are in a message, call this first,...
Definition: ConnectionRecorder.cpp:250
yarp::os::impl::ConnectionRecorder::expectFloat32
yarp::conf::float32_t expectFloat32() override
Read a 32-bit floating point number from the network connection.
Definition: ConnectionRecorder.cpp:105
yarp::os::impl::ConnectionRecorder::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: ConnectionRecorder.cpp:265
yarp::os::impl::BufferedConnectionWriter
A helper for creating cached object descriptions.
Definition: BufferedConnectionWriter.h:50
yarp::os::impl::ConnectionRecorder::isBareMode
bool isBareMode() const override
Check if the connection is bare mode.
Definition: ConnectionRecorder.cpp:131
yarp::os::impl::ConnectionRecorder::getWriter
yarp::os::ConnectionWriter * getWriter() override
Gets a way to reply to the message, if possible.
Definition: ConnectionRecorder.cpp:146
yarp::os::impl::ConnectionRecorder::expectInt8
std::int8_t expectInt8() override
Read a 8-bit integer from the network connection.
Definition: ConnectionRecorder.cpp:73
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
PortWriter.h
yarp::os::impl::ConnectionRecorder::setReference
void setReference(yarp::os::Portable *obj) override
Stores a direct pointer to the object being sent.
Definition: ConnectionRecorder.cpp:260
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
yarp::os::impl::ConnectionRecorder::hasReply
bool hasReply() const
Definition: ConnectionRecorder.cpp:52
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::impl::ConnectionRecorder::appendInt16
void appendInt16(std::int16_t data) override
Send a representation of a 16-bit integer to the network connection.
Definition: ConnectionRecorder.cpp:208
yarp::os::impl::ConnectionRecorder::getReply
const yarp::os::impl::BufferedConnectionWriter & getReply() const
Definition: ConnectionRecorder.cpp:47
yarp::os::impl::ConnectionRecorder::expectText
std::string expectText(const char terminatingChar) override
Read some text from the network connection.
Definition: ConnectionRecorder.cpp:66
yarp::os::impl::ConnectionRecorder::fini
void fini()
Call this when all reading/writing has been done.
Definition: ConnectionRecorder.cpp:32
BufferedConnectionWriter.h
yarp::os::impl::ConnectionRecorder::expectInt32
std::int32_t expectInt32() override
Read a 32-bit integer from the network connection.
Definition: ConnectionRecorder.cpp:87
yarp::os::impl::ConnectionRecorder::ConnectionRecorder
ConnectionRecorder()
Definition: ConnectionRecorder.cpp:14
yarp::os::impl::ConnectionRecorder::isError
bool isError() const override
Definition: ConnectionRecorder.cpp:187
yarp::os::impl::ConnectionRecorder::appendBlock
void appendBlock(const char *data, size_t len) override
Send a block of data to the network connection.
Definition: ConnectionRecorder.cpp:196
yarp::os::impl::ConnectionRecorder::getMessage
const yarp::os::impl::BufferedConnectionWriter & getMessage() const
Definition: ConnectionRecorder.cpp:42
yarp::os::impl::ConnectionRecorder::appendExternalBlock
void appendExternalBlock(const char *data, size_t len) override
Send a block of data to the network connection, without making a copy.
Definition: ConnectionRecorder.cpp:244
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::impl::ConnectionRecorder::appendFloat32
void appendFloat32(yarp::conf::float32_t data) override
Send a representation of a 32-bit floating point number to the network connection.
Definition: ConnectionRecorder.cpp:226
yarp::os::impl::ConnectionRecorder::expectInt64
std::int64_t expectInt64() override
Read a 64-bit integer from the network connection.
Definition: ConnectionRecorder.cpp:98
yarp::os::impl::ConnectionRecorder::getLocalContact
yarp::os::Contact getLocalContact() const override
Gets information about who is receiving the data, if that information is available.
Definition: ConnectionRecorder.cpp:164
yarp::os::impl::ConnectionRecorder::pushInt
bool pushInt(int x) override
Store an integer to return on the next call to expectInt()
Definition: ConnectionRecorder.cpp:119
yarp::os::impl::ConnectionRecorder::requestDrop
void requestDrop() override
Tag the connection to be dropped after the current message.
Definition: ConnectionRecorder.cpp:281
yarp::os::impl::ConnectionRecorder::appendFloat64
void appendFloat64(yarp::conf::float64_t data) override
Send a representation of a 64-bit floating point number to the network connection.
Definition: ConnectionRecorder.cpp:232
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::impl::ConnectionRecorder::expectBlock
bool expectBlock(char *data, size_t len) override
Read a block of data from the network connection.
Definition: ConnectionRecorder.cpp:57
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::os::impl::ConnectionRecorder::convertTextMode
bool convertTextMode() override
Reads in a standard description in text mode, and converts it to a standard description in binary.
Definition: ConnectionRecorder.cpp:136
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
yarp::os::impl::ConnectionRecorder::getRemoteContact
yarp::os::Contact getRemoteContact() const override
Gets information about who is supplying the data being read, if that information is available.
Definition: ConnectionRecorder.cpp:159
yarp::os::impl::ConnectionRecorder::appendInt32
void appendInt32(std::int32_t data) override
Send a representation of a 32-bit integer to the network connection.
Definition: ConnectionRecorder.cpp:214
yarp::os::impl::ConnectionRecorder
A helper for recording entire message/reply transactions.
Definition: ConnectionRecorder.h:31
yarp::os::impl::ConnectionRecorder::setSize
bool setSize(size_t len) override
Definition: ConnectionRecorder.cpp:296
yarp::os::impl::ConnectionRecorder::expectFloat64
yarp::conf::float64_t expectFloat64() override
Read a 64-bit floating point number from the network connection.
Definition: ConnectionRecorder.cpp:112
yarp::os::impl::ConnectionRecorder::isValid
bool isValid() const override
Definition: ConnectionRecorder.cpp:169
yarp::os::impl::ConnectionRecorder::getReference
yarp::os::Portable * getReference() const override
Get a direct pointer to the object being sent, if possible.
Definition: ConnectionRecorder.cpp:154
Bottle.h
yarp::os::impl::ConnectionRecorder::appendInt8
void appendInt8(std::int8_t data) override
Send a representation of a 8-bit integer to the network connection.
Definition: ConnectionRecorder.cpp:202
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36
ConnectionReader.h
yarp::os::impl::ConnectionRecorder::appendInt64
void appendInt64(std::int64_t data) override
Send a representation of a 64-bit integer to the network connection.
Definition: ConnectionRecorder.cpp:220