YARP
Yet Another Robot Platform
RosNameSpace.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #include <yarp/os/RosNameSpace.h>
7 
9 
10 #include <yarp/os/DummyConnector.h>
11 #include <yarp/os/Os.h>
12 #include <yarp/os/Vocab.h>
17 
18 #include <cstdio>
19 #include <cstdlib>
20 
21 using namespace yarp::os;
22 using namespace yarp::os::impl;
23 
24 namespace {
25 YARP_OS_LOG_COMPONENT(ROSNAMESPACE, "yarp.os.RosNameSpace")
26 } // namespace
27 
28 
30  mutex()
31 {
32  this->contact = contact;
33 }
34 
36 {
37  stop();
38 }
39 
41 {
42  return contact;
43 }
44 
45 Contact RosNameSpace::queryName(const std::string& name)
46 {
47  yCDebug(ROSNAMESPACE, "ROSNameSpace queryName(%s)", name.c_str());
48  NestedContact nc(name);
49  std::string node = nc.getNodeName();
50  std::string srv = nc.getNestedName();
51  std::string cat = nc.getCategory();
52  bool is_service = false;
53 
54  Bottle cmd;
55  Bottle reply;
56  if (cat.find("-1") == std::string::npos) {
57  cmd.addString("lookupNode");
58  cmd.addString("dummy_id");
59  cmd.addString(toRosNodeName(node));
61  cmd,
62  reply);
63  }
64  Contact contact;
65  if (reply.get(0).asInt32() != 1) {
66  cmd.clear();
67  reply.clear();
68  cmd.addString("lookupService");
69  cmd.addString("dummy_id");
70  cmd.addString(toRosNodeName(node));
72  cmd,
73  reply);
74  is_service = true;
75  }
76  contact = Contact::fromString(reply.get(2).asString());
77  // unfortunate differences in labeling carriers
78  if (contact.getCarrier() == "rosrpc") {
79  contact.setCarrier(std::string("rossrv+service.") + name);
80  } else {
81  contact.setCarrier("xmlrpc");
82  }
83  contact.setName(name);
84 
85  if (srv.empty() || !is_service) {
86  return contact;
87  }
88 
89  return Contact();
90 }
91 
92 Contact RosNameSpace::registerName(const std::string& name)
93 {
94  YARP_UNUSED(name);
95  yCError(ROSNAMESPACE, "ROS name server does not do 'raw' registrations.");
96  yCError(ROSNAMESPACE, "Use [Buffered]Port::open to get complete registrations.");
97  std::exit(1);
98 
99  return Contact();
100 }
101 
103 {
104  return registerAdvanced(contact, nullptr);
105 }
106 
108 {
109  yCDebug(ROSNAMESPACE, "ROSNameSpace registerContact(%s / %s)",
110  contact.toString().c_str(),
111  contact.toURI().c_str());
112  NestedContact nc = contact.getNested();
113  if (nc.getNestedName().empty()) {
114  nc.fromString(contact.getName());
115  }
116  std::string cat = nc.getCategory();
117  if (!nc.getNestedName().empty()) {
118  if (cat == "-1") {
119  Bottle cmd;
120  Bottle reply;
121  cmd.clear();
122  cmd.addString("registerService");
124  cmd.addString(toRosName(nc.getNestedName()));
125  Contact rosrpc = contact;
126  rosrpc.setCarrier("rosrpc");
127  cmd.addString(rosrpc.toURI());
128  Contact c;
129  if (store != nullptr) {
130  c = rosify(store->query(nc.getNodeName()));
131  } else {
132  Nodes& nodes = NameClient::getNameClient().getNodes();
133  c = rosify(nodes.getParent(contact.getName()));
134  }
135  cmd.addString(c.toURI());
137  cmd,
138  reply);
139  if (!ok) {
140  return Contact();
141  }
142  } else if (cat == "+" || cat == "-") {
143  Bottle cmd;
144  Bottle reply;
145  cmd.clear();
146  cmd.addString((cat == "+") ? "registerPublisher" : "registerSubscriber");
148  cmd.addString(toRosName(nc.getNestedName()));
149  std::string typ = nc.getTypeNameStar();
150  if (typ != "*" && !typ.empty()) {
151  // remap some basic native YARP types
152  if (typ == "yarp/image") {
153  typ = "sensor_msgs/Image";
154  }
155  if (typ.find('/') == std::string::npos) {
156  typ = std::string("yarp/") + typ;
157  }
158  }
159  cmd.addString(typ);
160  Contact c;
161  if (store != nullptr) {
162  c = rosify(store->query(nc.getNodeName()));
163  } else {
164  Nodes& nodes = NameClient::getNameClient().getNodes();
165  c = rosify(nodes.getParent(contact.getName()));
166  }
167  //Contact c = rosify(contact);
168  cmd.addString(c.toURI());
170  cmd,
171  reply);
172  if (!ok) {
173  yCError(ROSNAMESPACE, "ROS registration error: %s", reply.toString().c_str());
174  return Contact();
175  }
176  if (cat == "-") {
177  Bottle* publishers = reply.get(2).asList();
178  if ((publishers != nullptr) && publishers->size() >= 1) {
179  cmd.clear();
180  cmd.addString(contact.toURI());
181  cmd.addString("publisherUpdate");
182  cmd.addString("/yarp/RosNameSpace");
183  cmd.addString(toRosName(nc.getNestedName()));
184  cmd.addList() = *publishers;
185 
186  mutex.lock();
187  bool need_start = false;
188  if (pending.size() == 0) {
189  mutex.unlock();
190  stop();
191  need_start = true;
192  mutex.lock();
193  }
194  pending.addList() = cmd;
195  if (need_start) {
196  start();
197  }
198  mutex.unlock();
199  }
200  }
201  }
202  return contact;
203  }
204 
205  // Remainder of method is supporting older /name+#/foo syntax
206 
207  std::string name = contact.getName();
208  size_t pub_idx = name.find("+#");
209  size_t sub_idx = name.find("-#");
210 
211  std::string node;
212  std::string pub;
213  std::string sub;
214  if (pub_idx != std::string::npos) {
215  node = name.substr(0, pub_idx);
216  pub = name.substr(pub_idx + 2, name.length());
217  yCDebug(ROSNAMESPACE, "Publish to %s", pub.c_str());
218  }
219  if (sub_idx != std::string::npos) {
220  node = name.substr(0, sub_idx);
221  sub = name.substr(sub_idx + 2, name.length());
222  yCDebug(ROSNAMESPACE, "Subscribe to %s", sub.c_str());
223  }
224  if (node.empty()) {
225  node = name;
226  }
227  yCDebug(ROSNAMESPACE, "Name [%s] Node [%s] sub [%s] pub [%s]", name.c_str(), node.c_str(), sub.c_str(), pub.c_str());
228 
229  {
230  Bottle cmd;
231  Bottle reply;
232  // for ROS, we fake port name registrations by
233  // registering them as nodes that publish to an arbitrary
234  // topic
235  cmd.clear();
236  cmd.addString("registerPublisher");
237  cmd.addString(toRosNodeName(node));
238  cmd.addString("/yarp/registration");
239  cmd.addString("*");
240  Contact c = rosify(contact);
241  cmd.addString(c.toString());
243  cmd,
244  reply);
245  if (!ok) {
246  return Contact();
247  }
248  }
249 
250  if (!pub.empty()) {
251  NetworkBase::connect(node, std::string("topic:/") + pub);
252  }
253  if (!sub.empty()) {
254  NetworkBase::connect(std::string("topic:/") + sub, node);
255  }
256 
257  Contact c = contact;
258  c.setName(node);
259  return c;
260 }
261 
262 Contact RosNameSpace::unregisterName(const std::string& name)
263 {
264  return unregisterAdvanced(name, nullptr);
265 }
266 
267 Contact RosNameSpace::unregisterAdvanced(const std::string& name, NameStore* store)
268 {
269  NestedContact nc;
270  nc.fromString(name);
271  std::string cat = nc.getCategory();
272 
273  if (!nc.getNestedName().empty()) {
274  if (cat == "-1") {
275  Nodes& nodes = NameClient::getNameClient().getNodes();
276  Contact c = nodes.getURI(name);
277  c.setCarrier("rosrpc");
278  c = rosify(c);
279  Bottle cmd;
280  Bottle reply;
281  cmd.clear();
282  cmd.addString("unregisterService");
284  cmd.addString(nc.getNestedName());
285  cmd.addString(c.toURI());
287  cmd,
288  reply);
289  if (!ok) {
290  return Contact();
291  }
292  } else if (cat == "+" || cat == "-") {
293  Bottle cmd;
294  Bottle reply;
295  cmd.clear();
296  cmd.addString((cat == "+") ? "unregisterPublisher" : "unregisterSubscriber");
298  cmd.addString(nc.getNestedName());
299  Contact c;
300  if (store != nullptr) {
301  c = rosify(store->query(nc.getNodeName()));
302  } else {
303  Nodes& nodes = NameClient::getNameClient().getNodes();
304  c = rosify(nodes.getParent(name));
305  }
306  cmd.addString(c.toString());
308  cmd,
309  reply);
310  if (!ok) {
311  return Contact();
312  }
313  }
314  return Contact();
315  }
316 
317  // Remainder of method is supporting older /name+#/foo syntax
318 
319  size_t pub_idx = name.find("+#");
320  size_t sub_idx = name.find("-#");
321 
322  std::string node;
323  std::string pub;
324  std::string sub;
325  if (pub_idx != std::string::npos) {
326  node = name.substr(0, pub_idx);
327  pub = name.substr(pub_idx + 2, name.length());
328  }
329  if (sub_idx != std::string::npos) {
330  node = name.substr(0, sub_idx);
331  sub = name.substr(sub_idx + 2, name.length());
332  }
333  if (node.empty()) {
334  node = name;
335  }
336  yCDebug(ROSNAMESPACE, "Name [%s] sub [%s] pub [%s]", name.c_str(), sub.c_str(), pub.c_str());
337 
338  if (!pub.empty()) {
339  NetworkBase::disconnect(name, std::string("topic:/") + pub);
340  }
341  if (!sub.empty()) {
342  NetworkBase::disconnect(std::string("topic:/") + sub, name);
343  }
344 
345  Contact contact = NetworkBase::queryName(name);
346  Bottle cmd;
347  Bottle reply;
348  cmd.addString("unregisterPublisher");
349  cmd.addString(name);
350  cmd.addString("/yarp/registration");
351  Contact c("http", contact.getHost(), contact.getPort());
352  cmd.addString(c.toString());
354  cmd,
355  reply);
356  if (!ok) {
357  return Contact();
358  }
359 
360  return Contact();
361 }
362 
364 {
365  // Remainder of method is supporting older /name+#/foo syntax
366 
367  Bottle cmd;
368  Bottle reply;
369  cmd.addString("unregisterSubscriber");
370  cmd.addString(contact.getName());
371  cmd.addString("/yarp/registration");
372  Contact c("http", contact.getHost(), contact.getPort());
373  cmd.addString(c.toString());
375  cmd,
376  reply);
377  if (!ok) {
378  return Contact();
379  }
380  return Contact();
381 }
382 
383 bool RosNameSpace::setProperty(const std::string& name,
384  const std::string& key,
385  const Value& value)
386 {
387  YARP_UNUSED(name);
388  YARP_UNUSED(key);
389  YARP_UNUSED(value);
390  return false;
391 }
392 
393 Value* RosNameSpace::getProperty(const std::string& name,
394  const std::string& key)
395 {
396  YARP_UNUSED(name);
397  YARP_UNUSED(key);
398  return nullptr;
399 }
400 
402  const Contact& dest,
403  const ContactStyle& style)
404 {
405  Bottle cmd;
406  cmd.addString("registerPublisher");
407  cmd.addString(toRosNodeName(src.getName()));
408  cmd.addString(dest.getName());
409  cmd.addString("*");
410  cmd.addString(rosify(src).toString());
411 
412  return connectTopic(cmd, false, src, dest, style, false);
413 }
414 
416  const Contact& dest,
417  const ContactStyle& style)
418 {
419  Bottle cmd;
420  cmd.addString("registerSubscriber");
421  cmd.addString(toRosNodeName(dest.getName()));
422  cmd.addString(src.getName());
423  cmd.addString("*");
424  cmd.addString(rosify(dest).toString());
425 
426  return connectTopic(cmd, true, src, dest, style, true);
427 }
428 
430  const Contact& dest,
431  const ContactStyle& style)
432 {
433  Bottle cmd;
434  cmd.addString("unregisterPublisher");
435  cmd.addString(toRosNodeName(src.getName()));
436  cmd.addString(dest.getName());
437  cmd.addString(rosify(src).toString());
438  return connectTopic(cmd, false, src, dest, style, false);
439 }
440 
442  const Contact& dest,
443  const ContactStyle& style)
444 {
445  Bottle cmd;
446  cmd.addString("unregisterSubscriber");
447  cmd.addString(toRosNodeName(dest.getName()));
448  cmd.addString(src.getName());
449  cmd.addString(rosify(dest).toString());
450  return connectTopic(cmd, true, src, dest, style, false);
451 }
452 
454  const Contact& dest,
455  const ContactStyle& style)
456 {
457  YARP_UNUSED(src);
458  YARP_UNUSED(dest);
459  YARP_UNUSED(style);
460  return false;
461 }
462 
464  const Contact& dest,
465  const ContactStyle& style)
466 {
467  YARP_UNUSED(src);
468  YARP_UNUSED(dest);
469  YARP_UNUSED(style);
470  return false;
471 }
472 
474  bool srcIsTopic,
475  const Contact& src,
476  const Contact& dest,
477  const ContactStyle& style,
478  bool activeRegistration)
479 {
480  Bottle reply;
481  Contact dynamicSrc = src;
482  Contact dynamicDest = dest;
483  if (!style.carrier.empty()) {
484  if (srcIsTopic) {
485  dynamicDest.setCarrier(style.carrier);
486  } else {
487  dynamicSrc.setCarrier(style.carrier);
488  }
489  }
490  Contact base = getNameServerContact();
491  bool ok = NetworkBase::write(base,
492  cmd,
493  reply);
494  bool fail = (reply.check("faultCode", Value(0)).asInt32() != 0) || !ok;
495  if (fail) {
496  if (!style.quiet) {
497  yCError(ROSNAMESPACE, "Failure: name server did not accept connection to topic.");
498  if (reply.check("faultString")) {
499  yCError(ROSNAMESPACE, "Cause: %s", reply.check("faultString", Value("")).asString().c_str());
500  }
501  }
502  }
503  if (!fail) {
504  if (activeRegistration) {
505  Bottle* lst = reply.get(2).asList();
506  Bottle cmd2;
507  if (lst != nullptr) {
508  cmd2.addString("publisherUpdate");
509  cmd2.addString("/yarp");
510  cmd2.addString(dynamicSrc.getName());
511  cmd2.addList() = *lst;
512  NetworkBase::write(dynamicDest,
513  cmd2,
514  reply,
515  true);
516  }
517  }
518  }
519  return !fail;
520 }
521 
523 {
524  return false;
525 }
526 
528 {
529  return true;
530 }
531 
533 {
534  return false;
535 }
536 
538 {
539  return false;
540 }
541 
543  bool& scanNeeded,
544  bool& serverUsed)
545 {
546  YARP_UNUSED(useDetectedServer);
547  NameConfig nc;
548  nc.fromFile();
549  Contact c = nc.getAddress();
550  scanNeeded = false;
551  serverUsed = false;
552 
553  if (!c.isValid()) {
554  scanNeeded = true;
555  yCInfo(ROSNAMESPACE, "Checking for ROS_MASTER_URI...");
556  std::string addr = yarp::conf::environment::get_string("ROS_MASTER_URI");
557  c = Contact::fromString(addr);
558  if (c.isValid()) {
559  c.setCarrier("xmlrpc");
560  c.setName(nc.getNamespace());
561  NameConfig nc;
562  nc.setAddress(c);
563  nc.setMode("ros");
564  nc.toFile();
565  serverUsed = true;
566  }
567  }
568  return c;
569 }
570 
572  PortReader& reply,
573  const ContactStyle& style)
574 {
575  DummyConnector con0;
576  cmd.write(con0.getWriter());
577  Bottle in;
578  in.read(con0.getReader());
579  std::string key = in.get(0).asString();
580  std::string arg1 = in.get(1).asString();
581 
582  Bottle cmd2;
583  Bottle cache;
584 
585  if (key == "query") {
586  Contact c = queryName(arg1);
587  c.setName("");
588  Bottle reply2;
589  reply2.addString(arg1);
590  reply2.addString(c.toString());
591  DummyConnector con;
592  reply2.write(con.getWriter());
593  reply.read(con.getReader());
594  return true;
595  }
596 
597  if (key == "list") {
598  cmd2.addString("getSystemState");
599  cmd2.addString("dummy_id");
600 
601  if (!NetworkBase::write(getNameServerContact(), cmd2, cache, style)) {
602  yCError(ROSNAMESPACE, "Failed to contact ROS server");
603  return false;
604  }
605 
606  Bottle out;
607  out.addVocab32("many");
608  Bottle* parts = cache.get(2).asList();
609  Property nodes;
610  Property topics;
611  Property services;
612  if (parts != nullptr) {
613  for (int i = 0; i < 3; i++) {
614  Bottle* part = parts->get(i).asList();
615  if (part == nullptr) {
616  continue;
617  }
618  for (size_t j = 0; j < part->size(); j++) {
619  Bottle* unit = part->get(j).asList();
620  if (unit == nullptr) {
621  continue;
622  }
623  std::string stem = unit->get(0).asString();
624  Bottle* links = unit->get(1).asList();
625  if (links == nullptr) {
626  continue;
627  }
628  if (i < 2) {
629  topics.put(stem, 1);
630  } else {
631  services.put(stem, 1);
632  }
633  for (size_t j = 0; j < links->size(); j++) {
634  nodes.put(links->get(j).asString(), 1);
635  }
636  }
637  }
638  Property* props[3] = {&nodes, &topics, &services};
639  const char* title[3] = {"node", "topic", "service"};
640  for (int p = 0; p < 3; p++) {
641  Bottle blist;
642  blist.read(*props[p]);
643  for (size_t i = 0; i < blist.size(); i++) {
644  std::string name = blist.get(i).asList()->get(0).asString();
645  Bottle& info = out.addList();
646  info.addString(title[p]);
647  info.addString(name);
648  }
649  }
650  }
651  out.write(reply);
652  return true;
653  }
654 
655  return false;
656 }
657 
658 
659 std::string RosNameSpace::toRosName(const std::string& name)
660 {
661  if (name.find(':') == std::string::npos) {
662  return name;
663  }
664  std::string result;
665  for (char i : name) {
666  if (i != ':') {
667  result += i;
668  } else {
669  result += "__";
670  }
671  }
672  return result;
673 }
674 
675 std::string RosNameSpace::fromRosName(const std::string& name)
676 {
677  if (name.find("__") == std::string::npos) {
678  return name;
679  }
680  // length is at least 2
681  std::string result;
682  int ct = 0;
683  for (char i : name) {
684  if (i != '_') {
685  if (ct != 0) {
686  result += '_';
687  }
688  result += i;
689  ct = 0;
690  } else {
691  ct++;
692  if (ct == 2) {
693  result += ':';
694  ct = 0;
695  }
696  }
697  }
698  if (ct != 0) {
699  result += '_';
700  }
701  return result;
702 }
703 
704 std::string RosNameSpace::toRosNodeName(const std::string& name)
705 {
706  return toRosName(name);
707 }
708 
709 std::string RosNameSpace::fromRosNodeName(const std::string& name)
710 {
711  return fromRosName(name);
712 }
713 
715 {
716  std::string carrier = ((contact.getCarrier() == "rosrpc") ? "rosrpc" : "http");
717  std::string hostname = contact.getHost();
719  char hn[HOST_NAME_MAX];
720  yarp::os::gethostname(hn, sizeof(hn));
721  hostname = hn;
722  }
723  return Contact(carrier, hostname, contact.getPort());
724 }
725 
726 
728 {
729  int pct = 0;
730  do {
731  mutex.lock();
732  pct = pending.size();
733  mutex.unlock();
734  if (pct > 0) {
735  mutex.lock();
736  Bottle* bot = pending.get(0).asList();
737  Bottle curr = *bot;
738  mutex.unlock();
739 
740  yCDebug(ROSNAMESPACE, "ROS connection begins: %s", curr.toString().c_str());
741  ContactStyle style;
742  style.admin = true;
743  style.carrier = "tcp";
744  Bottle cmd = curr.tail();
745  Contact contact = Contact::fromString(curr.get(0).asString());
746  contact.setName("");
747  Bottle reply;
748  NetworkBase::write(contact, cmd, reply, style);
749  yCDebug(ROSNAMESPACE, "ROS connection ends: %s", curr.toString().c_str());
750 
751  mutex.lock();
752  pending = pending.tail();
753  pct = pending.size();
754  mutex.unlock();
755  }
756  } while (pct > 0);
757 }
void cat(Vector &a, const Vector &b)
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:164
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition: Bottle.cpp:182
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:251
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition: Bottle.cpp:240
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Bottle.cpp:277
Bottle tail() const
Get all but the first element of a bottle.
Definition: Bottle.cpp:388
void clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:121
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition: Bottle.cpp:230
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition: Bottle.cpp:170
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:24
bool quiet
Suppress all outputs and warnings.
Definition: ContactStyle.h:36
std::string carrier
Request that communication be made using a particular carrier.
Definition: ContactStyle.h:53
bool admin
Ask recipient to treat message as administrative.
Definition: ContactStyle.h:31
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
void setCarrier(const std::string &carrier)
Set the carrier to use for this Contact.
Definition: Contact.cpp:255
const NestedContact & getNested() const
Get the NestedContact containing extra information for this Contact.
Definition: Contact.cpp:261
bool isValid() const
Checks if a Contact is tagged as valid.
Definition: Contact.cpp:298
std::string getName() const
Get the name associated with this Contact.
Definition: Contact.cpp:205
std::string toString() const
Get a textual representation of the Contact.
Definition: Contact.cpp:303
static Contact fromString(const std::string &txt)
Factory method.
Definition: Contact.cpp:139
std::string toURI(bool includeCarrier=true) const
Get a representation of the Contact as a URI.
Definition: Contact.cpp:313
int getPort() const
Get the port number associated with this Contact for socket communication.
Definition: Contact.cpp:239
void setName(const std::string &name)
Set the name associated with this Contact.
Definition: Contact.cpp:222
std::string getCarrier() const
Get the carrier associated with this Contact for socket communication.
Definition: Contact.cpp:250
std::string getHost() const
Get the host name associated with this Contact for socket communication.
Definition: Contact.cpp:228
A dummy connection to test yarp::os::Portable implementations.
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
ConnectionReader & getReader(ConnectionWriter *replyWriter=nullptr)
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
Abstract interface for a database of port names.
Definition: NameStore.h:20
virtual Contact query(const std::string &name)=0
A placeholder for rich contact information.
Definition: NestedContact.h:24
bool fromString(const std::string &nFullName)
std::string getNodeName() const
std::string getNestedName() const
std::string getCategory() const
std::string getTypeNameStar() const
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:682
static Contact queryName(const std::string &name)
Find out information about a registered name.
Definition: Network.cpp:995
static bool disconnect(const std::string &src, const std::string &dest, bool quiet)
Request that an output port disconnect from an input port.
Definition: Network.cpp:700
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.
Definition: Network.cpp:1226
The Nodes class.
Definition: Nodes.h:32
Contact getURI(const std::string &name)
getURI queries the Node specified in the name parameter to get Contact information about the specifie...
Definition: Nodes.cpp:305
Contact getParent(const std::string &name)
getParent get info about node associated with the specified port.
Definition: Nodes.cpp:300
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
virtual bool write(ConnectionWriter &writer) const =0
Write this object to a network connection.
A class for storing options and configuration information.
Definition: Property.h:34
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:1015
bool usesCentralServer() const override
Check if a central server is involved in managing the NameSpace.
Contact getNameServerContact() const override
Get an address for a name server that manages the name space, if available.
RosNameSpace(const Contact &contact)
bool localOnly() const override
Check if the NameSpace is only valid for the current process ("local").
virtual bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style) override
Write a message to a name server for this NameSpace, if applicable.
Contact unregisterName(const std::string &name) override
Disassociate contact information from a port name.
Contact unregisterContact(const Contact &contact) override
Disassociate contact information (should include a port name).
virtual bool disconnectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Disconnect two ports, removing any persistence.
Contact queryName(const std::string &name) override
Map from port name to contact information.
virtual bool connectTopicToPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Subscribe a port to a topic.
Contact registerContact(const Contact &contact) override
Record contact information (should include a port name).
virtual bool connectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style) override
Connect two ports with persistence.
virtual bool disconnectTopicFromPort(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop subscribing a port to a topic.
bool serverAllocatesPortNumbers() const override
Check if a central server is responsible for allocating port numbers, or if this should be left up to...
static Contact rosify(const Contact &contact)
virtual Value * getProperty(const std::string &name, const std::string &key) override
Get the value of a named key from a named port.
virtual bool connectTopic(Bottle &cmd, bool srcIsTopic, const Contact &src, const Contact &dest, const ContactStyle &style, bool activeRegistration)
virtual Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed) override
Find a name server for this NameSpace, if applicable.
Contact registerName(const std::string &name) override
Record contact information to tie to a port name.
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.
virtual bool setProperty(const std::string &name, const std::string &key, const Value &value) override
Associate a key/value pair with a named port.
static std::string fromRosNodeName(const std::string &name)
static std::string toRosNodeName(const std::string &name)
virtual Contact unregisterAdvanced(const std::string &name, NameStore *store) override
Remove contact information, with access to the contact information of other ports for cross-referenci...
bool connectionHasNameOfEndpoints() const override
When connections are made involving ports managed by this NameSpace do the ports involved end up know...
virtual Contact registerAdvanced(const Contact &contact, NameStore *store) override
Record contact information, with access to the contact information of other ports for cross-referenci...
virtual bool connectPortToTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Publish a port to a topic.
virtual bool disconnectPortFromTopic(const Contact &src, const Contact &dest, const ContactStyle &style) override
Stop publishing a port to a topic.
void run() override
Main body of the new thread.
bool stop()
Stop the thread.
Definition: Thread.cpp:81
bool start()
Start the new thread running.
Definition: Thread.cpp:93
A single value (typically within a Bottle).
Definition: Value.h:45
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:240
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
Small helper class to help deal with legacy YARP configuration files.
Definition: NameConfig.h:25
std::string getNamespace(bool refresh=false)
Definition: NameConfig.cpp:441
static bool isLocalName(const std::string &name)
Definition: NameConfig.cpp:318
void setMode(const std::string &mode)
Definition: NameConfig.h:60
bool fromFile(const char *ns=nullptr)
Definition: NameConfig.cpp:158
void setAddress(const Contact &address)
Definition: NameConfig.cpp:430
bool toFile(bool clean=false)
Definition: NameConfig.cpp:171
std::string toString(const T &value)
convert an arbitrary type to string.
#define yCInfo(component,...)
Definition: LogComponent.h:132
#define yCError(component,...)
Definition: LogComponent.h:154
#define yCDebug(component,...)
Definition: LogComponent.h:109
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:34
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
Definition: environment.h:68
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
void gethostname(char *hostname, size_t size)
Portable wrapper for the gethostname() function.
Definition: Os.cpp:97
#define YARP_UNUSED(var)
Definition: api.h:162