YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
11using namespace yarp::os;
12using namespace yarp::os::impl;
13
14namespace {
15YARP_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
30bool 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
38bool 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
49bool 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
63
64
69
70
A mini-server for performing network communication in the background.
virtual std::string getName() const
Get name of port.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition PortWriter.h:23
void setRpcMode(bool expectRpc) override
Configure the port to be RPC only.
Definition Port.cpp:626
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
Definition Port.cpp:481
void setInputMode(bool expectInput) override
Configure the port to allow or forbid inputs.
Definition Port.cpp:610
void close() override
Stop port activity.
Definition Port.cpp:363
void setOutputMode(bool expectOutput) override
Configure the port to allow or forbid outputs.
Definition Port.cpp:618
~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,...)
#define yCAssert(component, x)
#define YARP_OS_LOG_COMPONENT(name, name_string)
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