|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
36 std::string bytes_to_string(
const Bytes& header)
39 for (
size_t i = 0; i < header.
length(); i++) {
44 for (
size_t i = 0; i < header.
length(); i++) {
45 char ch = header.
get()[i];
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62 static std::mutex mutex;
64 std::vector<Carrier*> delegates;
66 Carrier* chooseCarrier(
const std::string& name,
67 bool load_if_needed =
true,
68 bool return_template =
false);
70 bool load_if_needed =
true);
72 static bool matchCarrier(
const Bytes& header,
Bottle& code);
74 static bool scanForCarrier(
const Bytes& header);
79 std::mutex Carriers::Private::mutex{};
81 Carrier* Carriers::Private::chooseCarrier(
const std::string& name,
85 auto pos = name.find(
'+');
86 if (pos != std::string::npos) {
87 return chooseCarrier(name.substr(0, pos), load_if_needed, return_template);
90 for (
auto& delegate : delegates) {
93 if (!return_template) {
100 if (load_if_needed) {
105 return Carriers::Private::chooseCarrier(name,
false);
110 "Could not find carrier \"%s\"",
111 (!name.empty()) ? name.c_str() :
"[bytes]");
116 Carrier* Carriers::Private::chooseCarrier(
const Bytes& header,
119 for (
auto& delegate : delegates) {
126 if (load_if_needed) {
127 if (scanForCarrier(header)) {
129 return Carriers::Private::chooseCarrier(header,
true);
134 "Could not find carrier for a connection starting with: %s",
135 bytes_to_string(header).c_str());
141 bool Carriers::Private::matchCarrier(
const Bytes& header,
Bottle& code)
146 for (
size_t i = 0; i < code.
size() && !done; i++) {
151 if (header.
length() <= at) {
156 if (j != header.
get()[at]) {
170 bool Carriers::Private::checkForCarrier(
const Bytes& header,
Searchable& group)
173 if (code.
size() == 0) {
176 if (matchCarrier(header, code)) {
185 bool Carriers::Private::scanForCarrier(
const Bytes& header)
187 yCDebug(CARRIERS,
"Scanning for a carrier by header.");
191 for (
size_t i = 0; i < lst.
size(); i++) {
192 if (checkForCarrier(header, lst.
get(i))) {
199 bool Carriers::Private::select(
Searchable& options)
201 return options.
check(
"type",
Value(
"none")).asString() ==
"carrier";
204 #endif // DOXYGEN_SHOULD_SKIP_THIS
207 Carriers::Carriers() :
213 mPriv->delegates.emplace_back(
new TcpCarrier());
214 mPriv->delegates.emplace_back(
new TcpCarrier(
false));
216 mPriv->delegates.emplace_back(
new UdpCarrier());
218 mPriv->delegates.emplace_back(
new TextCarrier(
true));
229 for (
auto& delegate : mPriv->delegates) {
233 mPriv->delegates.clear();
255 Face* face =
nullptr;
276 bool ok = face->
open(address);
308 getInstance().mPriv->delegates.emplace_back(carrier);
329 std::lock_guard<std::mutex> guard(Private::mutex);
334 std::vector<Carrier*>& delegates = instance.mPriv->delegates;
335 for (
auto& delegate : delegates) {
341 instance.mPriv->scan();
342 Bottle plugins = instance.mPriv->getSelectedPlugins();
343 for (
size_t i = 0; i < plugins.
size(); i++) {
345 std::string name = options.
check(
"name",
Value(
"untitled")).asString();
346 if (done.
check(name)) {
A dummy Face for testing purposes.
static bool addCarrierPrototype(Carrier *carrier)
Add a new connection type.
A simple collection of objects that can be described and transmitted in a portable way.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
size_type size() const
Gets the number of elements in the bottle.
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
The output side of an active connection between two ports.
static Face * listen(const Contact &address)
Create a "proto-carrier" interface object that waits for incoming connections prior to a carrier bein...
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
virtual Carrier * create() const =0
Factory method.
bool readFromSearchable(Searchable &options, const std::string &name)
Configure settings from a configuration file or other searchable object.
static Carrier * chooseCarrier(const std::string &name)
Select a carrier by name.
static Carrier * getCarrierTemplate(const std::string &name)
Get template for carrier.
virtual std::string getName() const =0
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Pick out a set of relevant plugins.
virtual void write(OutputStream &os)
Communicating with a port via TCP.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool setSelector(YarpPluginSelector &selector)
Use a selector to find a plugin or plugins.
virtual OutputProtocol * write(const Contact &address)=0
Try to reach out and talk to someone.
std::string getName() const
Get the name associated with this factory.
Bottle getSelectedPlugins() const
A carrier for communicating locally within a process.
virtual bool isString() const
Checks if value is a string.
OutputStream & os()
Shorthand for getOutputStream()
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
virtual std::string asString() const
Get string value.
bool open(SharedLibraryFactory &factory)
Initialize a factory object based on the hints available.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual bool checkHeader(const Bytes &header)=0
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
static Carriers & getInstance()
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
Communicating between two ports via TCP.
static Bottle listCarriers()
static OutputProtocol * connect(const Contact &address)
Initiate a connection to an address.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Communicating between two ports via UDP.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A simple abstraction for a block of bytes.
void scan()
Find plugin configuration files, and run [plugin] sections through the select method.
static bool registerCarrier(const char *name, const char *dll)
Register a carrier to make available at runtime.
Collect hints for finding a particular plugin.
virtual ~Carriers()
Destructor.
virtual yarp::os::Face * createFace() const
Create new Face object that the carrier needs.
Bottle tail() const
Get all but the first element of a bottle.
A wrapper for a named factory method in a named shared library.
static std::string toString(int x)
The basic state of a connection - route, streams in use, etc.
#define yCError(component,...)
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
Communicating between two ports via a plain-text protocol.
Collection of carriers, a singleton.
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
void clear()
Remove all carriers.
Communicating between two ports via MCAST.
Communicating between two ports via a variant plain-text protocol originally designed for the yarp na...
virtual bool open(const Contact &address)=0
Start listening to the given address.
A single value (typically within a Bottle).
virtual bool reply(ConnectionState &proto, SizedWriter &writer)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
The initial point-of-contact with a port.
Minimal requirements for an efficient Writer.
A class for storing options and configuration information.