YARP
Yet Another Robot Platform
RpcServer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #include <yarp/os/RpcServer.h>
11 
13 
14 using namespace yarp::os;
15 using namespace yarp::os::impl;
16 
17 namespace {
18 YARP_OS_LOG_COMPONENT(RPCSERVER, "yarp.os.RpcServer")
19 } // namespace
20 
22 {
23  port.setInputMode(true);
24  port.setOutputMode(false);
25  port.setRpcMode(true);
26 }
27 
29 {
30  port.close();
31 }
32 
33 bool RpcServer::write(const PortWriter& writer, const PortWriter* callback) const
34 {
35  YARP_UNUSED(writer);
36  YARP_UNUSED(callback);
37  yCError(RPCSERVER, "%s cannot write, please use a regular Port or RpcClient for that", port.getName().c_str());
38  return false;
39 }
40 
41 bool RpcServer::write(const PortWriter& writer,
42  PortReader& reader,
43  const PortWriter* callback) const
44 {
45  YARP_UNUSED(writer);
46  YARP_UNUSED(reader);
47  YARP_UNUSED(callback);
48  yCError(RPCSERVER, "%s cannot write, please use a regular Port or RpcClient for that", port.getName().c_str());
49  return false;
50 }
51 
52 bool RpcServer::read(PortReader& reader, bool willReply)
53 {
54  if (!willReply) {
55  yCError(RPCSERVER, "%s must reply, please use a regular Port if you do not want to", port.getName().c_str());
56  // this is an error for RpcServer
57  return false;
58  }
59  return port.read(reader, true);
60 }
61 
62 void RpcServer::setInputMode(bool expectInput)
63 {
64  yCAssert(RPCSERVER, expectInput);
65 }
66 
67 
68 void RpcServer::setOutputMode(bool expectOutput)
69 {
70  yCAssert(RPCSERVER, !expectOutput);
71 }
72 
73 
74 void RpcServer::setRpcMode(bool expectRpc)
75 {
76  yCAssert(RPCSERVER, expectRpc);
77 }
yarp::os::RpcServer::setOutputMode
void setOutputMode(bool expectOutput) override
Configure the port to allow or forbid outputs.
Definition: RpcServer.cpp:68
yarp::os::RpcServer::setInputMode
void setInputMode(bool expectInput) override
Configure the port to allow or forbid inputs.
Definition: RpcServer.cpp:62
yarp::os::RpcServer::~RpcServer
~RpcServer() override
Destructor.
Definition: RpcServer.cpp:28
YARP_UNUSED
#define YARP_UNUSED(var)
Definition: api.h:159
yarp::os::RpcServer::setRpcMode
void setRpcMode(bool expectRpc) override
Configure the port to be RPC only.
Definition: RpcServer.cpp:74
LogComponent.h
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
RpcServer.h
yarp::os::RpcServer::RpcServer
RpcServer()
Constructor.
Definition: RpcServer.cpp:21
yCAssert
#define yCAssert(component, x)
Definition: LogComponent.h:172
yarp::os::RpcServer::write
virtual bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write cannot be called by RPCServer.
Definition: RpcServer.cpp:33
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::os::RpcServer::read
bool read(PortReader &reader, bool willReply=true) override
Read an object from the port.
Definition: RpcServer.cpp:52
YARP_OS_LOG_COMPONENT
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:37
yarp::os::impl
The components from which ports and connections are built.