YARP
Yet Another Robot Platform
TcpRosStream.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef TCPROSSTREAM_INC
7#define TCPROSSTREAM_INC
8
13
16
17#include <string>
18#include <map>
19
24{
25private:
26 yarp::os::TwoWayStream *delegate;
27 int raw;
30 char *cursor;
31 int remaining;
32 int phase;
33 bool expectTwiddle;
35 std::string kind;
37 bool initiative;
38 bool setInitiative;
39public:
40 TcpRosStream(TwoWayStream *delegate,
41 bool sender,
42 bool reply,
43 bool service,
44 int raw,
45 const char *kind) :
46 delegate(delegate),
47 raw(raw),
48 header(yarp::wire_rep_utils::BlobNetworkHeader{0,0,0}),
49 cursor(nullptr),
50 remaining(0),
51 phase(0),
52 expectTwiddle(service && sender),
53 kind(kind),
54 twiddlerReader(delegate->getInputStream(), twiddler),
55 initiative(false),
56 setInitiative(false)
57 {
58 updateKind(kind,sender,reply);
59 }
60
61 virtual ~TcpRosStream() {
62 if (delegate!=NULL) {
63 delete delegate;
64 delegate = NULL;
65 }
66 }
67
68 yarp::os::InputStream& getInputStream() override { return *this; }
69 yarp::os::OutputStream& getOutputStream() override { return *this; }
70
71
72 const yarp::os::Contact& getLocalAddress() const override {
73 return delegate->getLocalAddress();
74 }
75
76 const yarp::os::Contact& getRemoteAddress() const override {
77 return delegate->getRemoteAddress();
78 }
79
80 bool isOk() const override {
81 return delegate->isOk();
82 }
83
84 void reset() override {
85 delegate->reset();
86 }
87
88 void close() override {
89 delegate->close();
90 }
91
92 void beginPacket() override {
93 twiddlerReader.reset();
94 delegate->beginPacket();
95 }
96
97 void endPacket() override {
98 delegate->endPacket();
99 }
100
102 void write(const yarp::os::Bytes& b) override;
103
106
107 void interrupt() override {
108 delegate->getInputStream().interrupt();
109 }
110
111 void updateKind(const char *kind, bool sender, bool reply);
112
113 static std::map<std::string, std::string> rosToKind();
114 static std::string rosToKind(const char *rosname);
115 static bool configureTwiddler(yarp::wire_rep_utils::WireTwiddler& twiddler, const char *txt, const char *prompt, bool sender, bool reply);
116};
117
118#endif
yarp::os::OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: TcpRosStream.h:69
void beginPacket() override
Mark the beginning of a logical packet.
Definition: TcpRosStream.h:92
virtual ~TcpRosStream()
Definition: TcpRosStream.h:61
void reset() override
Reset the stream.
Definition: TcpRosStream.h:84
void interrupt() override
Interrupt the stream.
Definition: TcpRosStream.h:107
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: TcpRosStream.h:72
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: TcpRosStream.h:80
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: TcpRosStream.h:76
yarp::os::InputStream & getInputStream() override
Get an InputStream to read from.
Definition: TcpRosStream.h:68
TcpRosStream(TwoWayStream *delegate, bool sender, bool reply, bool service, int raw, const char *kind)
Definition: TcpRosStream.h:40
void close() override
Terminate the stream.
Definition: TcpRosStream.h:88
static std::map< std::string, std::string > rosToKind()
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
static bool configureTwiddler(yarp::wire_rep_utils::WireTwiddler &twiddler, const char *txt, const char *prompt, bool sender, bool reply)
void updateKind(const char *kind, bool sender, bool reply)
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: TcpRosStream.h:97
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:25
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:20
virtual void interrupt()
Interrupt the stream.
Definition: InputStream.cpp:42
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Definition: ManagedBytes.h:21
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:21
virtual void write(char ch)
Write a single byte to the stream.
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:25
virtual InputStream & getInputStream()=0
Get an InputStream to read from.
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
virtual void endPacket()=0
Mark the end of a logical packet (see beginPacket).
virtual void close()=0
Terminate the stream.
virtual void reset()=0
Reset the stream.
virtual void beginPacket()=0
Mark the beginning of a logical packet.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
::ssize_t ssize_t
Definition: numeric.h:86
The main, catch-all namespace for YARP.
Definition: dirs.h:16