YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
PortCoreClient.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
8#include <yarp/os/Bottle.h>
11#include <yarp/os/Network.h>
13
14using namespace yarp::os;
15using namespace yarp::os::impl;
16
17namespace {
18YARP_OS_LOG_COMPONENT(PORTCORECLIENT, "yarp.os.impl.PortCoreClient")
19
20ContactStyle quietStyle(const Contact& contact, double timeout)
21{
22 ContactStyle style;
23 style.quiet = true;
24 style.timeout = timeout;
25 style.carrier = contact.getCarrier();
26 return style;
27}
28} // namespace
29
30PortCoreClient::PortCoreClient(const std::string& remoteportName, double timeout) :
32 quietStyle(Contact::fromString(remoteportName), timeout))
33{
34}
35
36PortCoreClient::PortCoreClient(const Contact& remotePort, const ContactStyle& style) :
37 m_link(remotePort, style)
38{
39 yarp().attachAsClient(m_link);
40}
41
47
48PortCoreClient::AdminPortLink::AdminPortLink(const Contact& remotePort, const ContactStyle& style) :
49 m_contact(remotePort),
50 m_style(style)
51{
52 m_style.admin = true;
53}
54
55bool PortCoreClient::AdminPortLink::read(ConnectionReader& connection)
56{
57 Bottle cmd;
58 Bottle reply;
59 cmd.read(connection);
60 //yCDebug(PORTCORECLIENT, "asking %s: %s", m_contact.toString().c_str(), cmd.toString().c_str());
61 if (!NetworkBase::write(m_contact, cmd, reply, m_style)) {
62 if (!m_style.quiet) {
63 yCError(PORTCORECLIENT, "Cannot write to %s", m_contact.getName().c_str());
64 }
65 return false;
66 }
67 ConnectionWriter* writer = connection.getWriter();
68 if (writer != nullptr) {
69 reply.write(*writer);
70 }
71 return true;
72}
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:241
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition Bottle.cpp:231
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
Preferences for how to communicate with a contact.
double timeout
Set a timeout for communication (in units of seconds, fractional seconds allowed).
bool quiet
Suppress all outputs and warnings.
std::string carrier
Request that communication be made using a particular carrier.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
static bool write(const Contact &contact, PortWriter &cmd, PortReader &reply, bool admin=false, bool quiet=false, double timeout=-1)
Send a single command to a port and await a single response.
Definition Network.cpp:1322
An abstract unbuffered port.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
Client side of the administrative commands defined in PortCoreMsgs.thrift and handled by PortCore::ad...
PortCoreClient(const std::string &remoteportName, double timeout=2.0)
#define yCError(component,...)
#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.