YARP
Yet Another Robot Platform
carrier/carrier_stub.cpp

Example showing how to add a new carrier to YARP.

/*
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
* SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <yarp/os/all.h>
class TestCarrier : public yarp::os::impl::TextCarrier
{
public:
virtual std::string getName() const override
{
return "test";
}
virtual std::string getSpecifierName() const override
{
return "TESTTEST";
}
virtual Carrier *create() const override
{
return new TestCarrier();
}
};
int main(int argc, char *argv[])
{
out.open("/test/out");
in.open("/test/in");
yarp::os::Network::connect("/test/out","/test/in","test");
out.prepare().fromString("1 2 3");
out.write();
yarp::os::Bottle * bot = in.read();
if (bot!=NULL) {
printf("Got message %s\n", bot->toString().c_str());
}
out.close();
in.close();
return 0;
}
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:204
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
static bool addCarrierPrototype(Carrier *carrier)
Add a new connection type.
Definition: Carriers.cpp:303
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition: Network.cpp:682
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:783
Communicating between two ports via a plain-text protocol.
Definition: TextCarrier.h:20
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: TextCarrier.cpp:26
Carrier * create() const override
Factory method.
Definition: TextCarrier.cpp:66
virtual std::string getSpecifierName() const
Definition: TextCarrier.cpp:34
The main, catch-all namespace for YARP.
Definition: dirs.h:16
int main(int argc, char *argv[])
Definition: yarpros.cpp:263