YARP
Yet Another Robot Platform
DummyConnector.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * Copyright (C) 2007 Freyr Magnusson
5  * All rights reserved.
6  *
7  * This software may be modified and distributed under the terms of the
8  * BSD-3-Clause license. See the accompanying LICENSE file for details.
9  */
10 
11 #include <yarp/os/DummyConnector.h>
15 
16 
17 using namespace yarp::os::impl;
18 using namespace yarp::os;
19 
20 #ifndef DOXYGEN_SHOULD_SKIP_THIS
21 class DummyConnectorReader :
23 {
24 public:
25  ConnectionWriter* altWriter;
26  BufferedConnectionWriter* bufWriter;
27  bool tmode;
28 
29  ConnectionWriter* getWriter() override
30  {
31  if (bufWriter) {
32  bufWriter->reset(tmode);
33  }
34  return altWriter;
35  }
36 };
37 
38 class DummyConnector::Private
39 {
40 private:
41  BufferedConnectionWriter writer{false};
42  DummyConnectorReader reader;
44  bool textMode{false};
45 
46 public:
47  Private()
48  {
49  reader.altWriter = &writer;
50  reader.bufWriter = dynamic_cast<BufferedConnectionWriter*>(reader.altWriter);
51  reader.tmode = textMode;
52  }
53 
54  void setTextMode(bool textmode)
55  {
56  textMode = textmode;
57  writer.reset(textMode);
58  reader.tmode = textMode;
59  }
60 
61  ConnectionWriter& getCleanWriter()
62  {
63  writer.reset(textMode);
64  return writer;
65  }
66 
67  ConnectionWriter& getWriter()
68  {
69  return writer;
70  }
71 
72  ConnectionReader& getReader(ConnectionWriter* replyWriter)
73  {
74  writer.stopWrite();
75  std::string s = writer.toString();
76  sis.reset();
77  sis.add(s);
78  Route r;
79  reader.reset(sis, nullptr, r, s.length(), textMode);
80  reader.altWriter = ((replyWriter != nullptr) ? replyWriter : &writer);
81  reader.bufWriter = dynamic_cast<BufferedConnectionWriter*>(reader.altWriter);
82  return reader;
83  }
84 
85  void reset()
86  {
87  writer.reset(textMode);
88  }
89 };
90 #endif // DOXYGEN_SHOULD_SKIP_THIS
91 
93  mPriv(new Private())
94 {
95 }
96 
98 {
99  delete mPriv;
100 }
101 
102 void DummyConnector::setTextMode(bool textmode)
103 {
104  mPriv->setTextMode(textmode);
105 }
106 
108 {
109  return mPriv->getCleanWriter();
110 }
111 
113 {
114  return mPriv->getWriter();
115 }
116 
118 {
119  return mPriv->getReader(replywriter);
120 }
121 
123 {
124  mPriv->reset();
125 }
yarp::os::StringInputStream::reset
void reset()
Definition: StringInputStream.h:35
yarp::os::impl::BufferedConnectionWriter::reset
void reset(bool textMode)
Completely clear the writer and start afresh.
Definition: BufferedConnectionWriter.cpp:57
yarp::os::StringInputStream::add
void add(const std::string &txt)
Definition: StringInputStream.h:47
yarp::os::impl::BufferedConnectionWriter
A helper for creating cached object descriptions.
Definition: BufferedConnectionWriter.h:50
yarp::os::DummyConnector::reset
void reset()
Reset and clear the current ConnectionWriter.
Definition: DummyConnector.cpp:122
StreamConnectionReader.h
yarp::os::impl::StreamConnectionReader
Lets Readable objects read from the underlying InputStream associated with the connection between two...
Definition: StreamConnectionReader.h:42
yarp::os::Route
Information about a connection between two ports.
Definition: Route.h:32
yarp::os::DummyConnector::getReader
ConnectionReader & getReader(ConnectionWriter *replyWriter=nullptr)
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
Definition: DummyConnector.cpp:117
StringInputStream.h
yarp::os::DummyConnector::DummyConnector
DummyConnector()
Default constructor.
Definition: DummyConnector.cpp:92
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
DummyConnector.h
BufferedConnectionWriter.h
yarp::os::DummyConnector::getWriter
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
Definition: DummyConnector.cpp:112
yarp::os::DummyConnector::getCleanWriter
ConnectionWriter & getCleanWriter()
Get a clean/empty dummy ConnectionWriter.
Definition: DummyConnector.cpp:107
yarp::os::StringInputStream
An InputStream that reads from a string.
Definition: StringInputStream.h:25
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::DummyConnector::setTextMode
void setTextMode(bool textmode)
Set the textMode of the dummy connection.
Definition: DummyConnector.cpp:102
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::os::DummyConnector::~DummyConnector
virtual ~DummyConnector()
Destructor.
Definition: DummyConnector.cpp:97
yarp::os::impl
The components from which ports and connections are built.