|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
39 convertTextModePending(false),
44 target_used(&lst_used),
59 this->textMode = textMode;
63 convertTextModePending =
false;
72 convertTextModePending =
false;
74 target_used = &lst_used;
81 target_used = &lst_used;
84 for (i = 0; i < lst.size(); i++) {
88 for (i = 0; i < header.size(); i++) {
99 if (pool !=
nullptr) {
100 if (
data.length() + poolIndex > pool->
length()) {
104 if (pool ==
nullptr &&
data.length() < poolLength) {
106 if (*target_used < target->size()) {
108 if (bytes->
length() < poolLength) {
113 if (pool ==
nullptr) {
118 if (pool ==
nullptr) {
126 if (poolLength < 65536) {
131 target->push_back(pool);
134 if (pool !=
nullptr) {
135 memcpy(pool->
get() + poolIndex,
data.get(),
data.length());
136 poolIndex +=
data.length();
148 poolLength = initialPoolSize;
161 if (*target_used < target->size()) {
175 if (buf ==
nullptr) {
180 target->push_back(buf);
207 convertTextModePending =
true;
221 this->reader = &reader;
225 template <
typename T,
typename NetT>
228 if (std::is_same<T, NetT>::value) {
241 appendType<std::int8_t, NetInt8>(
this,
data);
246 appendType<std::int16_t, NetInt16>(
this,
data);
251 appendType<std::int32_t, NetInt32>(
this,
data);
256 appendType<std::int64_t, NetInt64>(
this,
data);
261 appendType<yarp::conf::float32_t, NetFloat32>(
this,
data);
266 appendType<yarp::conf::float64_t, NetFloat64>(
this,
data);
276 if (terminate ==
'\n') {
278 }
else if (terminate == 0) {
308 const char* eol =
"\r\n";
316 return header_used + lst_used;
326 if (index < header_used) {
336 if (index < header_used) {
348 for (i = 0; i < header_used; i++) {
352 for (i = 0; i < lst_used; i++) {
362 for (
size_t i = 0; i < header_used; i++) {
366 for (
size_t i = 0; i < lst_used; i++) {
388 for (i = 0; i < header_used; i++) {
392 for (i = 0; i < lst_used; i++) {
401 return header.size() + lst.size();
415 target_used = &header_used;
460 applyConvertTextMode();
471 initialPoolSize = size;
479 std::string output(total_size, 0);
480 char* dest =
const_cast<char*
>(output.c_str());
481 for (
size_t i = 0; i < header_used; i++) {
482 const char*
data = header[i]->get();
483 size_t len = header[i]->used();
484 memmove(dest,
data, len);
487 for (
size_t i = 0; i < lst_used; i++) {
488 const char*
data = lst[i]->get();
489 size_t len = lst[i]->used();
490 memmove(dest,
data, len);
496 bool BufferedConnectionWriter::applyConvertTextMode()
const
501 bool BufferedConnectionWriter::applyConvertTextMode()
503 if (convertTextModePending) {
504 convertTextModePending =
false;
508 for (
size_t i = 0; i < lst_used; i++) {
512 const std::string& str = sos.
str();
513 b.
fromBinary(str.c_str(),
static_cast<int>(str.length()));
514 std::string replacement = b.
toString() +
"\n";
515 for (
auto& i : lst) {
522 Bytes data(
const_cast<char*
>(replacement.c_str()), replacement.length());
A dummy connection to test yarp::os::Portable implementations.
virtual void appendLine(const std::string &data)
Send a string along with a carriage-return-line-feed sequence.
yarp::os::Portable * getReference() override
A simple collection of objects that can be described and transmitted in a portable way.
void copy()
Makes sure data block is owned, making a copy if necessary.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
void appendFloat32(yarp::conf::float32_t data) override
Send a representation of a 32-bit floating point number to the network connection.
void fromBinary(const char *buf, size_t len)
Initializes bottle from a binary representation.
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
void write(const Bytes &b) override
Write a block of bytes to the stream.
bool write(ConnectionWriter &connection) const override
Write this object to a network connection.
void appendInt8(std::int8_t data) override
Send a representation of a 8-bit integer to the network connection.
constexpr size_t BUFFERED_CONNECTION_INITIAL_POOL_SIZE
void restart()
Tell the writer that we will be serializing a new object, but to keep any cached buffers that already...
const char * data(size_t index) const override
virtual void write(char ch)
Write a single byte to the stream.
void appendFloat64(yarp::conf::float64_t data) override
Send a representation of a 64-bit floating point number to the network connection.
size_t setUsed(size_t used)
explicitly declare how many of the bytes are in use.
Simple specification of the minimum functions needed from output streams.
virtual void appendBlockCopy(const Bytes &data)
Add a buffer by copying its contents.
void addToHeader()
Switch to storing a header.
void reset(bool textMode)
Completely clear the writer and start afresh.
A helper for creating cached object descriptions.
size_t bufferCount() const
void requestDrop() override
Tag the connection to be dropped after the current message.
ConnectionReader & getReader(ConnectionWriter *replyWriter=nullptr)
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
void clear() override
Clear all cached data.
void appendExternalBlock(const char *data, size_t len) override
Send a block of data to the network connection, without making a copy.
An OutputStream that produces a string.
void setReference(yarp::os::Portable *obj) override
Stores a direct pointer to the object being sent.
PortReader * getReplyHandler() override
bool addPool(const yarp::os::Bytes &data)
Add the specified bytes to the current pool buffer.
void stopPool()
Stop adding to the current pool buffer.
~BufferedConnectionWriter() override
Destructor.
virtual bool isError() const =0
void appendInt64(std::int64_t data) override
Send a representation of a 64-bit integer to the network connection.
bool isTextMode() const override
Check if the connection is text mode.
bool convertTextMode() override
Converts a standard description in binary into a textual description, if the connection is in text-mo...
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
An interface for writing to a network connection.
bool isError() const override
void appendInt16(std::int16_t data) override
Send a representation of a 16-bit integer to the network connection.
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
virtual size_t dataSize() const
bool isActive() const override
bool isBareMode() const override
Check if the connection is bare mode.
std::string toString() const
virtual void flush()
Make sure all pending write operations are finished.
void setReplyHandler(PortReader &reader) override
This sets a handler to deal with replies to the message.
A simple abstraction for a block of bytes.
bool isValid() const override
void stopWrite() const override
Call when all writing is finished.
BufferedConnectionWriter(bool textMode=false, bool bareMode=false)
Constructor.
SizedWriter * getBuffer() const override
size_t length() const override
void declareSizes(int argc, int *argv) override
If you can easily determine how many blocks there are in a message, call this first,...
bool dropRequested() override
void setTextMode(bool textmode)
Set the textMode of the dummy connection.
An interface to the operating system, including Port based communication.
size_t headerLength() const override
const std::string & str() const
void push(const Bytes &data, bool copy)
Add the specified buffer to the list of buffers to be written.
void appendInt32(std::int32_t data) override
Send a representation of a 32-bit integer to the network connection.
void appendText(const std::string &str, const char terminate='\n') override
Send a terminated string to the network connection.
void startWrite() const override
Call when writing is about to begin.
The components from which ports and connections are built.
Minimal requirements for an efficient Writer.
void setInitialPoolSize(size_t size)
Set a custom initial pool size, which affects the size of buffers created for temporary data storage.
void appendBlock(const char *data, size_t len) override
Send a block of data to the network connection.