YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
BufferedConnectionWriter.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_OS_IMPL_BUFFEREDCONNECTIONWRITER_H
8#define YARP_OS_IMPL_BUFFEREDCONNECTIONWRITER_H
9
11#include <yarp/os/SizedWriter.h>
12
13#include <string>
14#include <vector>
15
16
17namespace yarp::os {
18
19class Bytes;
20class ManagedBytes;
21
22} // namespace yarp::os
23
24namespace yarp::os::impl {
25
26/*
27 * When allocating space to store serialized data, we start off with
28 * a block of this size. It will be resized as necessary.
29 * Data can optionally have a header, serialized separately.
30 */
32
48{
49public:
62 BufferedConnectionWriter(bool textMode = false,
63 bool bareMode = false);
64
69
75 void reset(bool textMode);
76
84 void restart();
85
89 void clear() override;
90
101 bool addPool(const yarp::os::Bytes& data);
102
108 void stopPool();
109
120 void push(const Bytes& data, bool copy);
121
122 // defined by yarp::os::ConnectionWriter
123 bool isTextMode() const override;
124 bool isBareMode() const override;
125 bool convertTextMode() override;
126 void declareSizes(int argc, int* argv) override; // FIXME Remove?
127 void setReplyHandler(PortReader& reader) override;
128 void appendInt8(std::int8_t data) override;
129 void appendInt16(std::int16_t data) override;
130 void appendInt32(std::int32_t data) override;
131 void appendInt64(std::int64_t data) override;
132 void appendFloat32(yarp::conf::float32_t data) override;
133 void appendFloat64(yarp::conf::float64_t data) override;
134 void appendBlock(const char* data, size_t len) override;
135 void appendText(const std::string& str, const char terminate = '\n') override;
136 void appendExternalBlock(const char* data, size_t len) override;
137
145 virtual void appendBlock(const yarp::os::Bytes& data);
146
152 virtual void appendBlockCopy(const Bytes& data);
153
161 virtual void appendLine(const std::string& data);
162
163
164 // defined by yarp::os::SizedWriter
165 size_t length() const override;
166 size_t headerLength() const override;
167 size_t length(size_t index) const override;
168 const char* data(size_t index) const override;
169 bool write(ConnectionWriter& connection) const override;
170 void write(OutputStream& os) override;
171
178 bool write(PortReader& obj);
179
184 virtual size_t dataSize() const;
185
186 size_t bufferCount() const;
187
188
189 // defined by yarp::os::SizedWriter
190 PortReader* getReplyHandler() override;
191
196 void addToHeader();
197
198
199 // defined by yarp::os::SizedWriter
200 yarp::os::Portable* getReference() override;
201
202
203 // defined by yarp::os::ConnectionWriter
204 void setReference(yarp::os::Portable* obj) override;
205 bool isValid() const override;
206 bool isActive() const override;
207 bool isError() const override;
208 void requestDrop() override;
209
210 // defined by yarp::os::SizedWriter
211 bool dropRequested() override;
212 void startWrite() const override;
213 void stopWrite() const override;
214
215 // defined by yarp::os::ConnectionWriter
216 SizedWriter* getBuffer() override;
217 const SizedWriter* getBuffer() const override;
218
225 void setInitialPoolSize(size_t size);
226
227
231 std::string toString() const;
232
233
234private:
248 bool applyConvertTextMode();
249 bool applyConvertTextMode() const;
250
251
252 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<yarp::os::ManagedBytes*>) lst;
253 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<yarp::os::ManagedBytes*>) header;
254 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<yarp::os::ManagedBytes*>*) target;
256 size_t poolIndex;
257 size_t poolCount;
258 size_t poolLength;
259 yarp::os::PortReader* reader;
260 bool textMode;
261 bool bareMode;
262 bool convertTextModePending;
263 yarp::os::Portable* ref;
264 bool shouldDrop;
265 size_t lst_used;
266 size_t header_used;
267 size_t* target_used;
268 size_t initialPoolSize;
269};
270
271
272} // namespace yarp::os::impl
273
274#endif // YARP_OS_IMPL_BUFFEREDCONNECTIONWRITER_H
std::string toString(const T &value)
convert an arbitrary type to string.
A mini-server for performing network communication in the background.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
An interface for writing to a network connection.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Simple specification of the minimum functions needed from output streams.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
A helper for creating cached object descriptions.
The components from which ports and connections are built.
constexpr size_t BUFFERED_CONNECTION_INITIAL_POOL_SIZE
An interface to the operating system, including Port based communication.
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition system.h:338
#define YARP_os_impl_API
Definition api.h:46