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;
}
yarp::os::Carriers::addCarrierPrototype
static bool addCarrierPrototype(Carrier *carrier)
Add a new connection type.
Definition: Carriers.cpp:306
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
all.h
yarp::os::BufferedPort::read
T * read(bool shouldWait=true) override
Read an available object from the port.
Definition: BufferedPort-inl.h:154
main
int main(int argc, char *argv[])
Definition: yarpros.cpp:261
yarp::os::Bottle::fromString
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:207
Carriers.h
TextCarrier.h
yarp::os::BufferedPort::prepare
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
Definition: BufferedPort-inl.h:114
yarp::os::BufferedPort< yarp::os::Bottle >
yarp::os::NetworkBase::connect
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
yarp::os::BufferedPort::open
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: BufferedPort-inl.h:41
yarp::os::impl::TextCarrier::getSpecifierName
virtual std::string getSpecifierName() const
Definition: TextCarrier.cpp:37
yarp::os::impl::TextCarrier
Communicating between two ports via a plain-text protocol.
Definition: TextCarrier.h:23
yarp::os::BufferedPort::write
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
Definition: BufferedPort-inl.h:126
Carrier.h
yarp::os::Network
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:786
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::BufferedPort::close
void close() override
Stop port activity.
Definition: BufferedPort-inl.h:73
yarp::os::impl::TextCarrier::getName
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: TextCarrier.cpp:29
yarp::os::impl::TextCarrier::create
Carrier * create() const override
Factory method.
Definition: TextCarrier.cpp:69