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