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