YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ShiftStream.cpp
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
8
14
16{
17public:
19 ~Private();
20 void close();
21
24};
25
27
32
34{
35 if (stream != nullptr) {
36 stream->close();
37 delete stream;
38 stream = nullptr;
39 }
40}
41
42
44 mPriv(new Private())
45{
46}
47
49{
50 delete mPriv;
51}
52
54{
55}
56
58{
59 check();
60 if (mPriv->stream == nullptr) {
61 return mPriv->nullStream;
62 }
63 return mPriv->stream->getInputStream();
64}
65
67{
68 check();
69 if (mPriv->stream == nullptr) {
70 return mPriv->nullStream;
71 }
72 return mPriv->stream->getOutputStream();
73}
74
76{
77 check();
78 return (mPriv->stream == nullptr) ? mPriv->nullStream.getLocalAddress()
79 : (mPriv->stream->getLocalAddress());
80}
81
83{
84 check();
85 return (mPriv->stream == nullptr) ? mPriv->nullStream.getRemoteAddress()
86 : (mPriv->stream->getRemoteAddress());
87}
88
90{
91 mPriv->close();
92}
93
95{
96 close();
97 mPriv->stream = stream;
98}
99
101{
102 TwoWayStream* result = mPriv->stream;
103 mPriv->stream = nullptr;
104 return result;
105}
106
108{
109 return mPriv->stream;
110}
111
113{
114 return mPriv->stream == nullptr;
115}
116
118{
119 if (mPriv->stream != nullptr) {
120 return mPriv->stream->isOk();
121 }
122 return false;
123}
124
126{
127 if (mPriv->stream != nullptr) {
128 mPriv->stream->reset();
129 }
130}
131
133{
134 if (mPriv->stream != nullptr) {
135 mPriv->stream->beginPacket();
136 }
137}
138
140{
141 if (mPriv->stream != nullptr) {
142 mPriv->stream->endPacket();
143 }
144}
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
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
A "null" stream, always invalid.
Simple specification of the minimum functions needed from output streams.
A container for a stream, allowing the stream implementation to be replaced when needed.
Definition ShiftStream.h:22
void endPacket() override
Mark the end of a logical packet (see beginPacket).
virtual void takeStream(TwoWayStream *stream)
Wrap the supplied stream.
virtual ~ShiftStream()
Destructor.
bool isOk() const override
Check if the stream is ok or in an error state.
virtual TwoWayStream * giveStream()
Removes the wrapped stream and returns it.
InputStream & getInputStream() override
Get an InputStream to read from.
virtual void check() const
Perform maintenance actions, if needed.
virtual TwoWayStream * getStream() const
void reset() override
Reset the stream.
void beginPacket() override
Mark the beginning of a logical packet.
const Contact & getLocalAddress() const override
Get the address of the local side of the stream.
virtual bool isEmpty() const
ShiftStream()
Constructor.
const Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
void close() override
Terminate the stream.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
A stream which can be asked to perform bidirectional communication.