YARP
Yet Another Robot Platform
RpcClient.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-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <yarp/os/RpcClient.h>
8 
10 
11 using namespace yarp::os;
12 using namespace yarp::os::impl;
13 
14 namespace {
15 YARP_OS_LOG_COMPONENT(RPCCLIENT, "yarp.os.RpcClient")
16 } // namespace
17 
19 {
20 public:
21  // an RpcClient may be implemented with a regular port
23 };
24 
25 
27  mPriv(new Private)
28 {
29  mPriv->port.setInputMode(false);
30  mPriv->port.setOutputMode(true);
31  mPriv->port.setRpcMode(true);
32 }
33 
35 {
36  mPriv->port.close();
37  delete mPriv;
38 }
39 
40 bool RpcClient::read(PortReader& reader, bool willReply)
41 {
42  YARP_UNUSED(reader);
43  YARP_UNUSED(willReply);
44  yCError(RPCCLIENT,
45  "cannot read from RpcClient %s, please use a regular Port for that",
46  mPriv->port.getName().c_str());
47  return false;
48 }
49 
51 {
52  YARP_UNUSED(writer);
53  return false;
54 }
55 
57 {
58  YARP_UNUSED(writer);
59  return false;
60 }
61 
62 void RpcClient::setInputMode(bool expectInput)
63 {
64  yCAssert(RPCCLIENT, !expectInput);
65 }
66 
67 void RpcClient::setOutputMode(bool expectOutput)
68 {
69  yCAssert(RPCCLIENT, expectOutput);
70 }
71 
72 void RpcClient::setRpcMode(bool expectRpc)
73 {
74  yCAssert(RPCCLIENT, expectRpc);
75 }
76 
78 {
79  return mPriv->port;
80 }
81 
82 const Port& RpcClient::asPort() const
83 {
84  return mPriv->port;
85 }
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
A mini-server for network communication.
Definition: Port.h:47
RpcClient()
Constructor.
Definition: RpcClient.cpp:26
void setInputMode(bool expectInput) override
Configure the port to allow or forbid inputs.
Definition: RpcClient.cpp:62
void setOutputMode(bool expectOutput) override
Configure the port to allow or forbid outputs.
Definition: RpcClient.cpp:67
bool reply(PortWriter &writer) override
Send an object as a reply to an object read from the port.
Definition: RpcClient.cpp:50
bool replyAndDrop(PortWriter &writer) override
Same as reply(), but closes connection after reply.
Definition: RpcClient.cpp:56
~RpcClient() override
Destructor.
Definition: RpcClient.cpp:34
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
Definition: RpcClient.cpp:40
Port & asPort() override
Get the concrete Port being used for communication.
Definition: RpcClient.cpp:77
void setRpcMode(bool expectRpc) override
Configure the port to be RPC only.
Definition: RpcClient.cpp:72
#define yCError(component,...)
Definition: LogComponent.h:154
#define yCAssert(component, x)
Definition: LogComponent.h:169
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:34
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
#define YARP_UNUSED(var)
Definition: api.h:162