YARP
Yet Another Robot Platform
DummyConnector.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-FileCopyrightText: 2007 Freyr Magnusson
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
12
13
14using namespace yarp::os::impl;
15using namespace yarp::os;
16
17#ifndef DOXYGEN_SHOULD_SKIP_THIS
18class DummyConnectorReader :
20{
21public:
22 ConnectionWriter* altWriter;
23 BufferedConnectionWriter* bufWriter;
24 bool tmode;
25
26 ConnectionWriter* getWriter() override
27 {
28 if (bufWriter) {
29 bufWriter->reset(tmode);
30 }
31 return altWriter;
32 }
33};
34
35class DummyConnector::Private
36{
37private:
38 BufferedConnectionWriter writer{false};
39 DummyConnectorReader reader;
41 bool textMode{false};
42
43public:
44 Private()
45 {
46 reader.altWriter = &writer;
47 reader.bufWriter = dynamic_cast<BufferedConnectionWriter*>(reader.altWriter);
48 reader.tmode = textMode;
49 }
50
51 void setTextMode(bool textmode)
52 {
53 textMode = textmode;
54 writer.reset(textMode);
55 reader.tmode = textMode;
56 }
57
58 ConnectionWriter& getCleanWriter()
59 {
60 writer.reset(textMode);
61 return writer;
62 }
63
64 ConnectionWriter& getWriter()
65 {
66 return writer;
67 }
68
69 ConnectionReader& getReader(ConnectionWriter* replyWriter)
70 {
71 writer.stopWrite();
72 std::string s = writer.toString();
73 sis.reset();
74 sis.add(s);
75 Route r;
76 reader.reset(sis, nullptr, r, s.length(), textMode);
77 reader.altWriter = ((replyWriter != nullptr) ? replyWriter : &writer);
78 reader.bufWriter = dynamic_cast<BufferedConnectionWriter*>(reader.altWriter);
79 return reader;
80 }
81
82 void reset()
83 {
84 writer.reset(textMode);
85 }
86};
87#endif // DOXYGEN_SHOULD_SKIP_THIS
88
89DummyConnector::DummyConnector() :
90 mPriv(new Private())
91{
92}
93
95{
96 delete mPriv;
97}
98
99void DummyConnector::setTextMode(bool textmode)
100{
101 mPriv->setTextMode(textmode);
102}
103
105{
106 return mPriv->getCleanWriter();
107}
108
110{
111 return mPriv->getWriter();
112}
113
115{
116 return mPriv->getReader(replywriter);
117}
118
120{
121 mPriv->reset();
122}
An interface for reading from a network connection.
An interface for writing to a network connection.
virtual ~DummyConnector()
Destructor.
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
void setTextMode(bool textmode)
Set the textMode of the dummy connection.
ConnectionReader & getReader(ConnectionWriter *replyWriter=nullptr)
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
ConnectionWriter & getCleanWriter()
Get a clean/empty dummy ConnectionWriter.
void reset()
Reset and clear the current ConnectionWriter.
Information about a connection between two ports.
Definition: Route.h:28
An InputStream that reads from a string.
void add(const std::string &txt)
A helper for creating cached object descriptions.
void reset(bool textMode)
Completely clear the writer and start afresh.
Lets Readable objects read from the underlying InputStream associated with the connection between two...
yarp::os::ConnectionWriter * getWriter() override
Gets a way to reply to the message, if possible.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.