47 if (
info.tag == PortInfo::PORTINFO_CONNECTION) {
93 return (
cat.empty() ||
cat ==
"-");
99 return (
cat.empty() ||
cat ==
"+");
105 return (
cat.empty() ||
cat ==
"+" ||
cat ==
"-");
111 return (
cat.empty() ||
cat ==
"-1");
117 return (
cat.empty() ||
cat ==
"+1");
123 return (
cat.empty() ||
cat ==
"+1" ||
cat ==
"-1");
207 if (!
mutex.try_lock()) {
234 std::vector<Contact>
query(
const std::string&
name,
const std::string& category = std::string());
253 unsigned int opaque_id = 1;
269 for (std::multimap<std::string, std::string>::const_iterator it = report.
outgoingURIs.begin(); it != report.
outgoingURIs.end(); ++it) {
280 for (std::multimap<std::string, std::string>::const_iterator it = report.
incomingURIs.begin(); it != report.
incomingURIs.end(); ++it) {
291 if (connections->
size() == 0) {
364 std::vector<Contact> contacts =
query(topic,
"-");
365 if (contacts.empty()) {
366 na.
fail(
"Cannot find topic");
370 for (
auto& c : contacts) {
391 std::vector<Contact> contacts =
query(topic,
"+");
392 if (contacts.empty()) {
393 na.
fail(
"Cannot find topic");
396 for (
auto& c : contacts) {
409 na.
fail(
"Cannot find topic");
419 if (prop !=
nullptr) {
420 prop->
put(
"node_like", 1);
437 yCError(NODE,
"Node name mismatch, expected [%s] but got [%s]\n", name.c_str(), item.
nc.
getNodeName().c_str());
444 name_cache[&contactable] = item;
445 by_part_name.insert(std::pair<std::string, NodeItem>(item.
nc.
getNestedName(), item));
446 by_category.insert(std::pair<std::string, NodeItem>(item.
nc.
getCategory(), item));
453 NodeItem item = name_cache[&contactable];
460 NodeItem item = name_cache[&contactable];
461 name_cache.erase(&contactable);
463 for (
auto it = by_part_name.begin(); it != by_part_name.end(); ++it) {
464 if (it->first == nestedName && it->second.contactable->where().toString() == contactable.
where().
toString()) {
465 by_part_name.erase(it);
470 for (
auto it = by_category.begin(); it != by_category.end(); ++it) {
471 if (it->first == category && it->second.contactable->where().toString() == contactable.
where().
toString()) {
472 by_category.erase(it);
481 std::vector<Contact> contacts;
483 for (std::multimap<std::string, NodeItem>::const_iterator it = by_part_name.begin(); it != by_part_name.end(); ++it) {
484 if (it->first == name && (category.empty() || category == it->second.nc.getCategory())) {
485 contacts.emplace_back(it->second.contactable->where());
503 if (key ==
"getBusStats") {
505 }
else if (key ==
"getBusInfo") {
507 }
else if (key ==
"getMasterUri") {
509 }
else if (key ==
"shutdown") {
511 }
else if (key ==
"getPid") {
513 }
else if (key ==
"getSubscriptions") {
514 getSubscriptions(na);
515 }
else if (key ==
"getPublications") {
517 }
else if (key ==
"paramUpdate") {
519 }
else if (key ==
"publisherUpdate") {
521 }
else if (key ==
"requestTopic") {
524 na.
error(
"I have no idea what you are talking about");
534 yCDebug(NODE,
"NODE %s <<< %s\n", name.c_str(), full.
toString().c_str());
553 Nodes& nodes = NameClient::getNameClient().getNodes();
566 Nodes& nodes = NameClient::getNameClient().getNodes();
575 mPriv->
add(contactable);
580 mPriv->
update(contactable);
585 mPriv->
remove(contactable);
590 std::vector<Contact> contacts = mPriv->
query(name, category);
591 if (!contacts.empty()) {
592 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 ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
virtual bool isValid() const =0
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.
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.
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.
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 get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
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.