YARP
Yet Another Robot Platform
carrier/carrier_stub.cpp

Example showing how to add a new carrier to YARP.

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#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:73
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:207
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
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:306
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:685
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:786
Communicating between two ports via a plain-text protocol.
Definition: TextCarrier.h:23
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: TextCarrier.cpp:29
Carrier * create() const override
Factory method.
Definition: TextCarrier.cpp:69
virtual std::string getSpecifierName() const
Definition: TextCarrier.cpp:37
The main, catch-all namespace for YARP.
Definition: environment.h:18
int main(int argc, char *argv[])
Definition: yarpros.cpp:261