|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
55 incomingURIs.insert(std::make_pair(info.
portName, c.
toURI()));
58 outgoingURIs.insert(std::make_pair(info.
portName, c.
toURI()));
64 static std::string
toRosName(
const std::string& str)
83 if (contactable ==
nullptr) {
96 return (
cat.empty() ||
cat ==
"-");
102 return (
cat.empty() ||
cat ==
"+");
108 return (
cat.empty() ||
cat ==
"+" ||
cat ==
"-");
114 return (
cat.empty() ||
cat ==
"-1");
120 return (
cat.empty() ||
cat ==
"+1");
126 return (
cat.empty() ||
cat ==
"+1" ||
cat ==
"-1");
194 bool has_prev_name{
false};
210 if (!mutex.try_lock()) {
213 while (name_cache.begin() != name_cache.end()) {
225 if (!name_cache.empty() && name_cache.begin()->first == c) {
226 name_cache.erase(name_cache.begin());
237 std::vector<Contact> query(
const std::string& name,
const std::string& category = std::string());
239 void prepare(
const std::string& name);
256 unsigned int opaque_id = 1;
262 for (
auto& it : by_part_name) {
272 for (std::multimap<std::string, std::string>::const_iterator it = report.
outgoingURIs.begin(); it != report.
outgoingURIs.end(); ++it) {
283 for (std::multimap<std::string, std::string>::const_iterator it = report.
incomingURIs.begin(); it != report.
incomingURIs.end(); ++it) {
294 if (connections->
size() == 0) {
324 for (
auto& it : by_part_name) {
344 for (
auto& it : by_part_name) {
367 std::vector<Contact> contacts = query(topic,
"-");
368 if (contacts.empty()) {
369 na.
fail(
"Cannot find topic");
373 for (
auto& c : contacts) {
394 std::vector<Contact> contacts = query(topic,
"+");
395 if (contacts.empty()) {
396 na.
fail(
"Cannot find topic");
399 for (
auto& c : contacts) {
412 na.
fail(
"Cannot find topic");
422 if (prop !=
nullptr) {
423 prop->
put(
"node_like", 1);
440 yCError(NODE,
"Node name mismatch, expected [%s] but got [%s]\n", name.c_str(), item.
nc.
getNodeName().c_str());
447 name_cache[&contactable] = item;
448 by_part_name.insert(std::pair<std::string, NodeItem>(item.
nc.
getNestedName(), item));
449 by_category.insert(std::pair<std::string, NodeItem>(item.
nc.
getCategory(), item));
456 NodeItem item = name_cache[&contactable];
463 NodeItem item = name_cache[&contactable];
464 name_cache.erase(&contactable);
466 for (
auto it = by_part_name.begin(); it != by_part_name.end(); ++it) {
467 if (it->first == nestedName && it->second.contactable->where().toString() == contactable.
where().
toString()) {
468 by_part_name.erase(it);
473 for (
auto it = by_category.begin(); it != by_category.end(); ++it) {
474 if (it->first == category && it->second.contactable->where().toString() == contactable.
where().
toString()) {
475 by_category.erase(it);
484 std::vector<Contact> contacts;
486 for (std::multimap<std::string, NodeItem>::const_iterator it = by_part_name.begin(); it != by_part_name.end(); ++it) {
487 if (it->first == name && (category.empty() || category == it->second.nc.getCategory())) {
488 contacts.emplace_back(it->second.contactable->where());
506 if (key ==
"getBusStats") {
508 }
else if (key ==
"getBusInfo") {
510 }
else if (key ==
"getMasterUri") {
512 }
else if (key ==
"shutdown") {
514 }
else if (key ==
"getPid") {
516 }
else if (key ==
"getSubscriptions") {
517 getSubscriptions(na);
518 }
else if (key ==
"getPublications") {
520 }
else if (key ==
"paramUpdate") {
522 }
else if (key ==
"publisherUpdate") {
524 }
else if (key ==
"requestTopic") {
527 na.
error(
"I have no idea what you are talking about");
537 yCDebug(NODE,
"NODE %s <<< %s\n", name.c_str(), full.
toString().c_str());
556 Nodes& nodes = NameClient::getNameClient().getNodes();
569 Nodes& nodes = NameClient::getNameClient().getNodes();
578 mPriv->
add(contactable);
583 mPriv->
update(contactable);
588 mPriv->
remove(contactable);
593 std::vector<Contact> contacts = mPriv->
query(name, category);
594 if (!contacts.empty()) {
595 return contacts.at(0);
void close() override
Stop port activity.
A simple collection of objects that can be described and transmitted in a portable way.
void prepare(const std::string &name)
prepare if it is not already been done, opens the port of the Node.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void includeNodeInName(bool flag) override
Choose whether to prepend a node name (if one is available) to the port's name.
void prepare(const std::string &name)
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
@ PORTINFO_CONNECTION
Information about an incoming or outgoing connection.
size_type size() const
Gets the number of elements in the bottle.
void add(Contactable &contactable)
void releaseProperties(Property *prop) override
End access unstructured port properties.
static NameClient & getNameClient()
Get an instance of the name client.
void getPid(NodeArgs &na)
Contact queryName(const std::string &name)
Look up the address of a named port.
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
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.
void add(Contactable &contactable) override
add a contactable to this node.
void getBusInfo(NodeArgs &na)
std::string getName() const
virtual bool isValid() const =0
int getpid()
Portable wrapper for the getppid() function.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A base class for objects that want information about port status changes.
virtual Contact query(const std::string &name, const std::string &category="") override
query the Node to obtain Contact information about a nested port associated with this Node.
Information about a port connection or event.
std::multimap< std::string, std::string > incomingURIs
A mini-server for network communication.
void getMasterUri(NodeArgs &na)
void update(Contactable &contactable)
std::string targetName
Name of connection target, if any.
static std::string toRosName(const std::string &name)
Possible ROS names are a subset of YARP names.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
int tag
Type of information.
void addExternalNode(const std::string &name, Node &node)
addExternalNode adds a Node to this container.
void report(const PortInfo &info) override
Callback for port event/state information.
virtual std::string asString() const
Get string value.
Contactable * contactable
static Contact rosify(const Contact &contact)
bool incoming
True if a connection is incoming, false if outgoing.
bool read(ConnectionReader &reader) override
Read this object from a network connection.
std::string portName
Name of port.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
void shutdown(NodeArgs &na)
void setReader(PortReader &reader) override
Set an external reader for port data.
Contact where()
where getter fot information about the port of the Node.
#define yCAssert(component, x)
An interface for reading from a network connection.
Bottle tail() const
Get all but the first element of a bottle.
std::vector< Contact > query(const std::string &name, const std::string &category=std::string())
void fail(const char *txt)
#define yCError(component,...)
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Client for YARP name server.
void getPublications(NodeArgs &na)
void setActiveName(const std::string &name)
setActiveName setter for the currently active node
void requestTopic(NodeArgs &na)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
std::multimap< std::string, std::string > outgoingURIs
void update(Contactable &contactable)
update should update the contactable with new information.
std::map< Contactable *, NodeItem > name_cache
Property * acquireProperties(bool readOnly) override
Access unstructured port properties.
void getSubscriptions(NodeArgs &na)
void publisherUpdate(NodeArgs &na)
void fromExternal(const Bottle &alt)
void cat(Vector &a, const Vector &b)
void paramUpdate(NodeArgs &na)
void error(const char *txt)
Contact where() const override
Returns information about how this port can be reached.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void remove(Contactable &contactable)
virtual Bottle * asList() const
Get list value.
void interrupt()
interrupt delegates the call to the Node port interrupt.
void remove(Contactable &contactable) override
remove specified contactable from the list of contactables associated with this Node.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
std::string getActiveName()
getActiveName getter for the currently active node's name
void getBusStats(NodeArgs &na)
A single value (typically within a Bottle).
static std::string toRosName(const std::string &str)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::multimap< std::string, NodeItem > by_part_name
The components from which ports and connections are built.
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
static std::string fromRosName(const std::string &name)
std::multimap< std::string, NodeItem > by_category
A class for storing options and configuration information.
void removeExternalNode(const std::string &name)
removeExternalNode erase the node from the container.
static std::string fromRosName(const std::string &str)
std::string sourceName
Name of connection source, if any.