YARP
Yet Another Robot Platform
RpcServer.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/RpcServer.h>
8 
10 
11 using namespace yarp::os;
12 using namespace yarp::os::impl;
13 
14 namespace {
15 YARP_OS_LOG_COMPONENT(RPCSERVER, "yarp.os.RpcServer")
16 } // namespace
17 
19 {
20  port.setInputMode(true);
21  port.setOutputMode(false);
22  port.setRpcMode(true);
23 }
24 
26 {
27  port.close();
28 }
29 
30 bool RpcServer::write(const PortWriter& writer, const PortWriter* callback) const
31 {
32  YARP_UNUSED(writer);
33  YARP_UNUSED(callback);
34  yCError(RPCSERVER, "%s cannot write, please use a regular Port or RpcClient for that", port.getName().c_str());
35  return false;
36 }
37 
38 bool RpcServer::write(const PortWriter& writer,
39  PortReader& reader,
40  const PortWriter* callback) const
41 {
42  YARP_UNUSED(writer);
43  YARP_UNUSED(reader);
44  YARP_UNUSED(callback);
45  yCError(RPCSERVER, "%s cannot write, please use a regular Port or RpcClient for that", port.getName().c_str());
46  return false;
47 }
48 
49 bool RpcServer::read(PortReader& reader, bool willReply)
50 {
51  if (!willReply) {
52  yCError(RPCSERVER, "%s must reply, please use a regular Port if you do not want to", port.getName().c_str());
53  // this is an error for RpcServer
54  return false;
55  }
56  return port.read(reader, true);
57 }
58 
59 void RpcServer::setInputMode(bool expectInput)
60 {
61  yCAssert(RPCSERVER, expectInput);
62 }
63 
64 
65 void RpcServer::setOutputMode(bool expectOutput)
66 {
67  yCAssert(RPCSERVER, !expectOutput);
68 }
69 
70 
71 void RpcServer::setRpcMode(bool expectRpc)
72 {
73  yCAssert(RPCSERVER, expectRpc);
74 }
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
~RpcServer() override
Destructor.
Definition: RpcServer.cpp:25
bool read(PortReader &reader, bool willReply=true) override
Read an object from the port.
Definition: RpcServer.cpp:49
void setInputMode(bool expectInput) override
Configure the port to allow or forbid inputs.
Definition: RpcServer.cpp:59
virtual bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write cannot be called by RPCServer.
Definition: RpcServer.cpp:30
RpcServer()
Constructor.
Definition: RpcServer.cpp:18
void setOutputMode(bool expectOutput) override
Configure the port to allow or forbid outputs.
Definition: RpcServer.cpp:65
void setRpcMode(bool expectRpc) override
Configure the port to be RPC only.
Definition: RpcServer.cpp:71
#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