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 cat(Vector &a, const Vector &b)
static std::string fromRosName(const std::string &str)
static std::string toRosName(const std::string &str)
void fail(const char *txt)
void error(const char *txt)
void fromExternal(const Bottle &alt)
Contactable * contactable
std::multimap< std::string, std::string > outgoingURIs
std::multimap< std::string, std::string > incomingURIs
void report(const PortInfo &info) override
Callback for port event/state information.
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Bottle tail() const
Get all but the first element of a bottle.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
An interface for reading from a network connection.
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
virtual bool isValid() const =0
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
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 update(Contactable &contactable)
std::vector< Contact > query(const std::string &name, const std::string &category=std::string())
void getPid(NodeArgs &na)
std::multimap< std::string, NodeItem > by_part_name
void shutdown(NodeArgs &na)
void prepare(const std::string &name)
void publisherUpdate(NodeArgs &na)
void getBusInfo(NodeArgs &na)
std::map< Contactable *, NodeItem > name_cache
void paramUpdate(NodeArgs &na)
void getSubscriptions(NodeArgs &na)
void add(Contactable &contactable)
std::multimap< std::string, NodeItem > by_category
bool read(ConnectionReader &reader) override
Read this object from a network connection.
void requestTopic(NodeArgs &na)
void getBusStats(NodeArgs &na)
void remove(Contactable &contactable)
void getPublications(NodeArgs &na)
void getMasterUri(NodeArgs &na)
void prepare(const std::string &name)
prepare if it is not already been done, opens the port of the Node.
void update(Contactable &contactable)
update should update the contactable with new information.
void remove(Contactable &contactable) override
remove specified contactable from the list of contactables associated with this Node.
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.
void add(Contactable &contactable) override
add a contactable to this node.
Contact where()
where getter fot information about the port of the Node.
void interrupt()
interrupt delegates the call to the Node port interrupt.
void removeExternalNode(const std::string &name)
removeExternalNode erase the node from the container.
void addExternalNode(const std::string &name, Node &node)
addExternalNode adds a Node to this container.
std::string getActiveName()
getActiveName getter for the currently active node's name
void setActiveName(const std::string &name)
setActiveName setter for the currently active node
Information about a port connection or event.
std::string targetName
Name of connection target, if any.
bool incoming
True if a connection is incoming, false if outgoing.
std::string portName
Name of port.
int tag
Type of information.
std::string sourceName
Name of connection source, if any.
@ PORTINFO_CONNECTION
Information about an incoming or outgoing connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
A base class for objects that want information about port status changes.
A mini-server for network communication.
void setReader(PortReader &reader) override
Set an external reader for port data.
Contact where() const override
Returns information about how this port can be reached.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void includeNodeInName(bool flag) override
Choose whether to prepend a node name (if one is available) to the port's name.
void releaseProperties(Property *prop) override
End access unstructured port properties.
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.
Property * acquireProperties(bool readOnly) override
Access unstructured port properties.
A class for storing options and configuration information.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
static Contact rosify(const Contact &contact)
static std::string fromRosName(const std::string &name)
static std::string toRosName(const std::string &name)
Possible ROS names are a subset of YARP names.
std::string getName() const
A single value (typically within a Bottle).
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual Bottle * asList() const
Get list value.
virtual std::string asString() const
Get string value.
Client for YARP name server.
static NameClient & getNameClient()
Get an instance of the name client.
Contact queryName(const std::string &name)
Look up the address of a named port.
#define yCError(component,...)
#define yCAssert(component, x)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
int getpid()
Portable wrapper for the getppid() function.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)