YARP
Yet Another Robot Platform
XmlRpcStream.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 YARP_XMLRPC_CARRIER_XMLRPCSTREAM_H
7 #define YARP_XMLRPC_CARRIER_XMLRPCSTREAM_H
8 
9 #include <yarp/os/InputStream.h>
10 #include <yarp/os/OutputStream.h>
11 #include <yarp/os/TwoWayStream.h>
14 
15 #include "XmlRpcClient.h"
16 #include "XmlRpcServerConnection.h"
17 
18 class XmlRpcStream :
20  public yarp::os::InputStream,
22 {
23 private:
24  TwoWayStream *delegate;
25  YarpXmlRpc::XmlRpcClient client;
26  YarpXmlRpc::XmlRpcServerConnection server;
29  bool sender;
30  bool firstRound;
31  bool interpretRos;
32 public:
33  XmlRpcStream(TwoWayStream *delegate, bool sender, bool interpretRos) :
34  client("notset", 0),
35  server(0, nullptr),
36  sender(sender),
37  interpretRos(interpretRos)
38  {
39  this->delegate = delegate;
40  client.reset();
41  server.reset();
42  firstRound = true;
43  }
44 
45  virtual ~XmlRpcStream()
46  {
47  if (delegate != nullptr) {
48  delete delegate;
49  delegate = nullptr;
50  }
51  }
52 
54  {
55  return *this;
56  }
57 
59  {
60  return *this;
61  }
62 
63 
64  const yarp::os::Contact& getLocalAddress() const override
65  {
66  return delegate->getLocalAddress();
67  }
68 
69  const yarp::os::Contact& getRemoteAddress() const override
70  {
71  return delegate->getRemoteAddress();
72  }
73 
74  bool isOk() const override
75  {
76  return delegate->isOk();
77  }
78 
79  void reset() override
80  {
81  delegate->reset();
82  }
83 
84  void close() override
85  {
86  delegate->close();
87  }
88 
89  void beginPacket() override
90  {
91  delegate->beginPacket();
92  }
93 
94  void endPacket() override
95  {
96  delegate->endPacket();
97  }
98 
100  void write(const yarp::os::Bytes& b) override;
101 
104 
105  void interrupt() override
106  {
107  delegate->getInputStream().interrupt();
108  }
109 
110 };
111 
112 #endif // YARP_XMLRPC_CARRIER_XMLRPCSTREAM_H
void beginPacket() override
Mark the beginning of a logical packet.
Definition: XmlRpcStream.h:89
virtual ~XmlRpcStream()
Definition: XmlRpcStream.h:45
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: XmlRpcStream.h:94
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: XmlRpcStream.h:74
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
void interrupt() override
Interrupt the stream.
Definition: XmlRpcStream.h:105
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: XmlRpcStream.h:64
XmlRpcStream(TwoWayStream *delegate, bool sender, bool interpretRos)
Definition: XmlRpcStream.h:33
yarp::os::InputStream & getInputStream() override
Get an InputStream to read from.
Definition: XmlRpcStream.h:53
void reset() override
Reset the stream.
Definition: XmlRpcStream.h:79
yarp::os::OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: XmlRpcStream.h:58
void close() override
Terminate the stream.
Definition: XmlRpcStream.h:84
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: XmlRpcStream.h:69
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:26
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:20
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
virtual void write(char ch)
Write a single byte to the stream.
An InputStream that reads from a string.
An OutputStream that produces a string.
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:26
::ssize_t ssize_t
Definition: numeric.h:86