YARP
Yet Another Robot Platform
XmlRpcStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_XMLRPC_CARRIER_XMLRPCSTREAM_H
10 #define YARP_XMLRPC_CARRIER_XMLRPCSTREAM_H
11 
12 #include <yarp/os/InputStream.h>
13 #include <yarp/os/OutputStream.h>
14 #include <yarp/os/TwoWayStream.h>
17 
18 #include "XmlRpcClient.h"
19 #include "XmlRpcServerConnection.h"
20 
21 class XmlRpcStream :
23  public yarp::os::InputStream,
25 {
26 private:
27  TwoWayStream *delegate;
28  YarpXmlRpc::XmlRpcClient client;
29  YarpXmlRpc::XmlRpcServerConnection server;
32  bool sender;
33  bool firstRound;
34  bool interpretRos;
35 public:
36  XmlRpcStream(TwoWayStream *delegate, bool sender, bool interpretRos) :
37  client("notset", 0),
38  server(0, nullptr),
39  sender(sender),
40  interpretRos(interpretRos)
41  {
42  this->delegate = delegate;
43  client.reset();
44  server.reset();
45  firstRound = true;
46  }
47 
48  virtual ~XmlRpcStream()
49  {
50  if (delegate != nullptr) {
51  delete delegate;
52  delegate = nullptr;
53  }
54  }
55 
57  {
58  return *this;
59  }
60 
62  {
63  return *this;
64  }
65 
66 
67  const yarp::os::Contact& getLocalAddress() const override
68  {
69  return delegate->getLocalAddress();
70  }
71 
72  const yarp::os::Contact& getRemoteAddress() const override
73  {
74  return delegate->getRemoteAddress();
75  }
76 
77  bool isOk() const override
78  {
79  return delegate->isOk();
80  }
81 
82  void reset() override
83  {
84  delegate->reset();
85  }
86 
87  void close() override
88  {
89  delegate->close();
90  }
91 
92  void beginPacket() override
93  {
94  delegate->beginPacket();
95  }
96 
97  void endPacket() override
98  {
99  delegate->endPacket();
100  }
101 
103  void write(const yarp::os::Bytes& b) override;
104 
107 
108  void interrupt() override
109  {
110  delegate->getInputStream().interrupt();
111  }
112 
113 };
114 
115 #endif // YARP_XMLRPC_CARRIER_XMLRPCSTREAM_H
void beginPacket() override
Mark the beginning of a logical packet.
Definition: XmlRpcStream.h:92
virtual ~XmlRpcStream()
Definition: XmlRpcStream.h:48
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: XmlRpcStream.h:97
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: XmlRpcStream.h:77
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:108
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: XmlRpcStream.h:67
XmlRpcStream(TwoWayStream *delegate, bool sender, bool interpretRos)
Definition: XmlRpcStream.h:36
yarp::os::InputStream & getInputStream() override
Get an InputStream to read from.
Definition: XmlRpcStream.h:56
void reset() override
Reset the stream.
Definition: XmlRpcStream.h:82
yarp::os::OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: XmlRpcStream.h:61
void close() override
Terminate the stream.
Definition: XmlRpcStream.h:87
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: XmlRpcStream.h:72
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
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:29
::ssize_t ssize_t
Definition: numeric.h:60