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  BufferedConnectionWriter* altWriter;
26  bool tmode;
27 
28  BufferedConnectionWriter* getWriter() override
29  {
30  altWriter->reset(tmode);
31  return altWriter;
32  }
33 };
34 
35 class DummyConnector::Private
36 {
37 private:
38  BufferedConnectionWriter writer{false};
39  DummyConnectorReader reader;
41  bool textMode{false};
42 
43 public:
44  Private()
45  {
46  reader.altWriter = &writer;
47  reader.tmode = textMode;
48  }
49 
50  void setTextMode(bool textmode)
51  {
52  textMode = textmode;
53  writer.reset(textMode);
54  reader.tmode = textMode;
55  }
56 
57  ConnectionWriter& getCleanWriter()
58  {
59  writer.reset(textMode);
60  return writer;
61  }
62 
63  ConnectionWriter& getWriter()
64  {
65  return writer;
66  }
67 
68  ConnectionReader& getReader()
69  {
70  writer.stopWrite();
71  std::string s = writer.toString();
72  sis.reset();
73  sis.add(s);
74  Route r;
75  reader.reset(sis, nullptr, r, s.length(), textMode);
76  return reader;
77  }
78 
79  void reset()
80  {
81  writer.reset(textMode);
82  }
83 };
84 #endif // DOXYGEN_SHOULD_SKIP_THIS
85 
87  mPriv(new Private())
88 {
89 }
90 
92 {
93  delete mPriv;
94 }
95 
96 void DummyConnector::setTextMode(bool textmode)
97 {
98  mPriv->setTextMode(textmode);
99 }
100 
102 {
103  return mPriv->getCleanWriter();
104 }
105 
107 {
108  return mPriv->getWriter();
109 }
110 
112 {
113  return mPriv->getReader();
114 }
115 
117 {
118  mPriv->reset();
119 }
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...
DummyConnector()
Default constructor.
void setTextMode(bool textmode)
Set the textMode of the dummy connection.
ConnectionWriter & getCleanWriter()
Get a clean/empty dummy ConnectionWriter.
ConnectionReader & getReader()
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
void reset()
Reset and clear the current ConnectionWriter.
Information about a connection between two ports.
Definition: Route.h:32
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...
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.