YARP
Yet Another Robot Platform
NameServer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
11 #include <yarp/os/ManagedBytes.h>
12 #include <yarp/os/NetType.h>
17 #include <yarp/conf/version.h>
18 
19 #include <yarp/os/Network.h>
20 #include <yarp/os/Port.h>
21 #include <yarp/os/Property.h>
22 #include <yarp/os/Time.h>
23 #include <yarp/os/Value.h>
24 #include <yarp/os/Vocab.h>
25 
26 #include <map>
27 #include <set>
28 
29 using namespace yarp::os::impl;
30 using namespace yarp::os;
31 
32 YARP_OS_LOG_COMPONENT(NAMESERVER, "yarp.os.impl.NameServer")
33 
34 // produce a correctly parsed string in presence of quoting
35 static std::string STR_HELP(const char* txt)
36 {
37  Value v;
38  v.fromString(txt);
39  return v.asString();
40 }
41 #define STR(x) STR_HELP(x).c_str()
42 
45 //
46 // Basic functionality
47 //
50 
51 
52 Contact NameServer::unregisterName(const std::string& name)
53 {
54  Contact prev = queryName(name);
55  if (prev.isValid()) {
56  if (prev.getPort() != -1) {
57  NameRecord& rec = getNameRecord(prev.getRegName());
58  if (rec.isReusablePort()) {
59  HostRecord& host = getHostRecord(prev.getHost());
60  host.release(prev.getPort());
61  }
62  if (rec.isReusableIp()) {
63  if (rec.getAddress().getCarrier() == "mcast") {
64  mcastRecord.releaseAddress(rec.getAddress().getHost().c_str());
65  }
66  }
67  rec.clear();
68  tmpNames.release(name);
69 
70  Bottle event;
71  event.addVocab(Vocab::encode("del"));
72  event.addString(name.c_str());
73  onEvent(event);
74  }
75  }
76 
77  return queryName(name);
78 }
79 
80 
81 Contact NameServer::registerName(const std::string& name,
82  const Contact& address,
83  const std::string& remote)
84 {
85  bool reusablePort = false;
86  bool reusableIp = false;
87 
88  yCTrace(NAMESERVER, "in registerName...");
89 
90  if (name != "...") {
91  unregisterName(name);
92  }
93 
94  Contact suggestion = address;
95 
96  if (!suggestion.isValid()) {
97  suggestion = Contact(name, "...", "...", 0);
98  }
99 
100  std::string portName = name;
101  if (portName == "...") {
102  portName = tmpNames.get();
103  }
104 
105  std::string carrier = suggestion.getCarrier();
106  if (carrier == "...") {
107  carrier = "tcp";
108  }
109 
110  std::string machine = suggestion.getHost();
111  int overridePort = 0;
112  if (machine == "...") {
113  if (carrier != "mcast") {
114  if (remote == "...") {
115  yCError(NAMESERVER, "remote machine name was not found! can only guess it is local...");
116  machine = "127.0.0.1";
117  } else {
118  machine = remote;
119  }
120  } else {
121  machine = mcastRecord.get();
122  overridePort = mcastRecord.lastPortNumber();
123  reusableIp = true;
124  }
125  }
126 
127  int port = suggestion.getPort();
128  if (port == 0) {
129  if (overridePort != 0) {
130  port = overridePort;
131  } else {
132  port = getHostRecord(machine).get();
133  reusablePort = true;
134  }
135  }
136 
137  suggestion = Contact(portName, carrier, machine, port);
138 
139  yCDebug(NAMESERVER, "Registering %s for %s", suggestion.toURI().c_str(), suggestion.getRegName().c_str());
140 
141  NameRecord& nameRecord = getNameRecord(suggestion.getRegName());
142  nameRecord.setAddress(suggestion, reusablePort, reusableIp);
143 
144  Bottle event;
145  event.addVocab(Vocab::encode("add"));
146  event.addString(suggestion.getRegName().c_str());
147  onEvent(event);
148 
149  return nameRecord.getAddress();
150 }
151 
152 
153 Contact NameServer::queryName(const std::string& name)
154 {
155  std::string base = name;
156  std::string pat;
157  if (name.find("/net=") == 0) {
158  size_t patStart = 5;
159  size_t patEnd = name.find('/', patStart);
160  if (patEnd >= patStart && patEnd != std::string::npos) {
161  pat = name.substr(patStart, patEnd - patStart);
162  base = name.substr(patEnd);
163  yCDebug(NAMESERVER, "Special query form %s (%s/%s)", name.c_str(), pat.c_str(), base.c_str());
164  }
165  }
166 
167  NameRecord* rec = getNameRecord(base, false);
168  if (rec != nullptr) {
169  if (!pat.empty()) {
170  std::string ip = rec->matchProp("ips", pat);
171  if (!ip.empty()) {
172  SplitString sip(ip.c_str());
173  Contact c = rec->getAddress();
174  c.setHost(sip.get(0));
175  return c;
176  }
177  }
178  return rec->getAddress();
179  }
180  return Contact();
181 }
182 
183 
184 NameServer::NameRecord* NameServer::getNameRecord(const std::string& name,
185  bool create)
186 {
187  auto entry = nameMap.find(name);
188  if (entry == nameMap.end()) {
189  if (!create) {
190  return nullptr;
191  }
192  nameMap.emplace(name, NameRecord());
193  entry = nameMap.find(name);
194  }
195  yCAssert(NAMESERVER, entry != nameMap.end());
196  return &(entry->second);
197 }
198 
199 
200 NameServer::HostRecord* NameServer::getHostRecord(const std::string& name,
201  bool create)
202 {
203  auto entry = hostMap.find(name);
204  if (entry == hostMap.end()) {
205  if (!create) {
206  return nullptr;
207  }
208  hostMap[name] = HostRecord();
209  entry = hostMap.find(name);
210  entry->second.setBase(basePort);
211  }
212  yCAssert(NAMESERVER, entry != hostMap.end());
213  return &(entry->second);
214 }
215 
216 
219 //
220 // Remote interface
221 //
224 
225 
226 void NameServer::setup()
227 {
228 
229  basePort = NetworkBase::getDefaultPortRange() + 2;
230 
231  dispatcher.add("register", &NameServer::cmdRegister);
232  dispatcher.add("unregister", &NameServer::cmdUnregister);
233  dispatcher.add("query", &NameServer::cmdQuery);
234  dispatcher.add("help", &NameServer::cmdHelp);
235  dispatcher.add("set", &NameServer::cmdSet);
236  dispatcher.add("get", &NameServer::cmdGet);
237  dispatcher.add("check", &NameServer::cmdCheck);
238  dispatcher.add("match", &NameServer::cmdMatch);
239  dispatcher.add("list", &NameServer::cmdList);
240  dispatcher.add("route", &NameServer::cmdRoute);
241  dispatcher.add("gc", &NameServer::cmdGarbageCollect);
242  dispatcher.add("bot", &NameServer::cmdBot);
243  dispatcher.add("announce", &NameServer::cmdAnnounce);
244 
245  ndispatcher.add("list", &NameServer::ncmdList);
246  ndispatcher.add("query", &NameServer::ncmdQuery);
247  ndispatcher.add("version", &NameServer::ncmdVersion);
248  ndispatcher.add("set", &NameServer::ncmdSet);
249  ndispatcher.add("get", &NameServer::ncmdGet);
250 }
251 
252 std::string NameServer::cmdRegister(int argc, char* argv[])
253 {
254 
255  std::string remote = argv[0];
256  argc--;
257  argv++;
258 
259  if (argc < 1) {
260  return "need at least one argument";
261  }
262  std::string portName = STR(argv[0]);
263 
264  std::string machine = "...";
265  std::string carrier = "...";
266  int port = 0;
267  if (argc >= 2) {
268  carrier = argv[1];
269  }
270  if (argc >= 3) {
271  machine = argv[2];
272  }
273  if (argc >= 4) {
274  if (std::string("...") == argv[3]) {
275  port = 0;
276  } else {
277  port = NetType::toInt(argv[3]);
278  }
279  }
280 
281  Contact address = registerName(portName, Contact(portName, carrier, machine, port), remote);
282 
283  yCDebug(NAMESERVER, "name server register address -- %s", address.toString().c_str());
284 
285  return terminate(textify(address));
286 }
287 
288 
289 std::string NameServer::cmdQuery(int argc, char* argv[])
290 {
291  // ignore source
292  argc--;
293  argv++;
294 
295  if (argc < 1) {
296  return "need at least one argument";
297  }
298  std::string portName = STR(argv[0]);
299  Contact address = queryName(portName);
300  return terminate(textify(address));
301 }
302 
303 std::string NameServer::cmdUnregister(int argc, char* argv[])
304 {
305  // ignore source
306  argc--;
307  argv++;
308 
309  if (argc < 1) {
310  return "need at least one argument";
311  }
312  std::string portName = STR(argv[0]);
313  Contact address = unregisterName(portName);
314  return terminate(textify(address));
315 }
316 
317 
318 std::string NameServer::cmdAnnounce(int argc, char* argv[])
319 {
320  // ignore source
321  argc--;
322  argv++;
323 
324  return terminate("ok\n");
325 }
326 
327 std::string NameServer::cmdRoute(int argc, char* argv[])
328 {
329  // ignore source
330  argc--;
331  argv++;
332 
333  if (argc < 2) {
334  return terminate("need at least two arguments: the source port and the target port\n(followed by an optional list of carriers in decreasing order of desirability)");
335  }
336  std::string src = STR(argv[0]);
337  std::string dest = STR(argv[1]);
338 
339  argc -= 2;
340  argv += 2;
341 
342  const char* altArgv[] = {
343  "local",
344  "shmem",
345  "mcast",
346  "udp",
347  "tcp",
348  "text"};
349  int altArgc = 6;
350 
351  if (argc == 0) {
352  argc = altArgc;
353  argv = (char**)altArgv;
354  }
355 
356 
357  NameRecord& srcRec = getNameRecord(src);
358  NameRecord& destRec = getNameRecord(dest);
359  std::string pref;
360 
361  for (int i = 0; i < argc; i++) {
362  std::string carrier = argv[i];
363  if (srcRec.checkProp("offers", carrier) && destRec.checkProp("accepts", carrier)) {
364  bool ok = true;
365  if (carrier == "local" || carrier == "shmem") {
366  if (srcRec.getProp("ips") == destRec.getProp("ips")) {
367  if (carrier == "local") {
368  if (srcRec.getProp("process") != destRec.getProp("process")) {
369  ok = false;
370  }
371  }
372  } else {
373  ok = false;
374  }
375  }
376  if (ok) {
377  pref = carrier;
378  break;
379  }
380  }
381  }
382  if (!pref.empty()) {
383  pref = pref + ":/" + dest;
384  } else {
385  pref = dest;
386  }
387 
388  std::string result = "port ";
389  result += src + " route " + dest + " = " + pref + "\n";
390  return terminate(result);
391 }
392 
393 
394 std::string NameServer::cmdHelp(int argc, char* argv[])
395 {
396  // ignore source
397  argc--;
398  argv++;
399 
400  std::string result = "Here are some ways to use the name server:\n";
401  //ACE_Vector<std::string> names = dispatcher.getNames();
402  //for (unsigned i=0; i<names.size(); i++) {
403  //const std::string& name = names[i];
404  //result += std::string(" ") + name + " ...\n";
405  //}
406  result += std::string("+ help\n");
407  result += std::string("+ list\n");
408  result += std::string("+ register $portname\n");
409  result += std::string("+ register $portname $carrier $ipAddress $portNumber\n");
410  result += std::string(" (if you want a field set automatically, write '...')\n");
411  result += std::string("+ unregister $portname\n");
412  result += std::string("+ query $portname\n");
413  result += std::string("+ set $portname $property $value\n");
414  result += std::string("+ get $portname $property\n");
415  result += std::string("+ check $portname $property\n");
416  result += std::string("+ match $portname $property $prefix\n");
417  result += std::string("+ route $port1 $port2\n");
418  result += std::string("+ gc\n");
419  return terminate(result);
420 }
421 
422 
423 std::string NameServer::cmdSet(int argc, char* argv[])
424 {
425  // ignore source
426  argc--;
427  argv++;
428 
429  if (argc < 2) {
430  return "need at least two arguments: the port name, and a key";
431  }
432  std::string target = STR(argv[0]);
433  std::string key = argv[1];
434  NameRecord& nameRecord = getNameRecord(target);
435  nameRecord.clearProp(key);
436  for (int i = 2; i < argc; i++) {
437  nameRecord.addProp(key, argv[i]);
438  }
439  return terminate(std::string("port ") + target + " property " + key + " = " + nameRecord.getProp(key) + "\n");
440 }
441 
442 std::string NameServer::cmdGet(int argc, char* argv[])
443 {
444  // ignore source
445  argc--;
446  argv++;
447 
448  if (argc < 2) {
449  return "need exactly two arguments: the port name, and a key";
450  }
451  std::string target = STR(argv[0]);
452  std::string key = argv[1];
453  NameRecord& nameRecord = getNameRecord(target);
454  return terminate(std::string("port ") + target + " property " + key + " = " + nameRecord.getProp(key) + "\n");
455 }
456 
457 std::string NameServer::cmdMatch(int argc, char* argv[])
458 {
459  // ignore source
460  argc--;
461  argv++;
462 
463  if (argc < 3) {
464  return "need exactly three arguments: the port name, a key, and a prefix";
465  }
466  std::string target = STR(argv[0]);
467  std::string key = argv[1];
468  std::string prefix = argv[2];
469  NameRecord& nameRecord = getNameRecord(target);
470  return terminate(std::string("port ") + target + " property " + key + " = " + nameRecord.matchProp(key, prefix) + "\n");
471 }
472 
473 std::string NameServer::cmdCheck(int argc, char* argv[])
474 {
475  // ignore source
476  argc--;
477  argv++;
478 
479  if (argc < 2) {
480  return "need at least two arguments: the port name, and a key";
481  }
482  std::string response;
483  std::string target = STR(argv[0]);
484  std::string key = argv[1];
485  NameRecord& nameRecord = getNameRecord(target);
486  for (int i = 2; i < argc; i++) {
487  std::string val = "false";
488  if (nameRecord.checkProp(key, argv[i])) {
489  val = "true";
490  }
491  if (i > 2) {
492  response += "\n";
493  }
494  response.append("port ").append(target).append(" property ").append(key).append(" value ").append(argv[i]).append(" present ").append(val);
495  }
496  response += "\n";
497  return terminate(response);
498 }
499 
500 
501 std::string NameServer::cmdList(int argc, char* argv[])
502 {
503  YARP_UNUSED(argc);
504  YARP_UNUSED(argv);
505  std::string response;
506 
507  std::multiset<std::string> lines;
508  for (auto& it : nameMap) {
509  NameRecord& rec = it.second;
510  lines.insert(textify(rec.getAddress()));
511  }
512 
513  // return result in alphabetical order
514  for (const auto& line : lines) {
515  response += line;
516  }
517 
518  return terminate(response);
519 }
520 
521 
522 std::string NameServer::cmdBot(int argc, char* argv[])
523 {
524  std::string txt;
525  argc--;
526  argv++;
527  if (argc >= 1) {
528  std::string key = argv[0];
529  argc--;
530  argv++;
531  Bottle result = ndispatcher.dispatch(this, key.c_str(), argc, argv);
532  txt = result.toString();
533  }
534  return txt;
535 }
536 
537 
538 Bottle NameServer::ncmdList(int argc, char* argv[])
539 {
540  Bottle response;
541 
542  std::string prefix;
543 
544  if (argc == 1) {
545  prefix = STR(argv[0]);
546  }
547 
548  response.addString("ports");
549  for (auto& it : nameMap) {
550  NameRecord& rec = it.second;
551  std::string iname = rec.getAddress().getRegName();
552  if (iname.find(prefix) == 0) {
553  if (iname == prefix || iname[prefix.length()] == '/' || prefix[prefix.length() - 1] == '/') {
554  if (rec.getAddress().isValid()) {
555  response.addList() = botify(rec.getAddress());
556  }
557  }
558  }
559  }
560 
561  return response;
562 }
563 
564 
565 yarp::os::Bottle NameServer::ncmdQuery(int argc, char* argv[])
566 {
567  Bottle response;
568  if (argc == 1) {
569  std::string portName = STR(argv[0]);
570  Contact address = queryName(portName);
571  response = botify(address);
572  }
573  return response;
574 }
575 
576 
577 yarp::os::Bottle NameServer::ncmdVersion(int argc, char* argv[])
578 {
579  YARP_UNUSED(argc);
580  YARP_UNUSED(argv);
581  Bottle response;
582  response.addString("version");
583  response.addString(YARP_VERSION);
584  return response;
585 }
586 
587 
588 yarp::os::Bottle NameServer::ncmdSet(int argc, char* argv[])
589 {
590 
591  Bottle response;
592  if (argc >= 2) {
593  std::string target = STR(argv[0]);
594  std::string key = STR(argv[1]);
595  NameRecord& nameRecord = getNameRecord(target);
596  nameRecord.clearProp(key);
597  for (int i = 2; i < argc; i++) {
598  nameRecord.addProp(key, argv[i]);
599  }
600  response.addString("ok");
601  }
602  return response;
603 }
604 
605 yarp::os::Bottle NameServer::ncmdGet(int argc, char* argv[])
606 {
607  Bottle response;
608  if (argc == 2) {
609  std::string target = STR(argv[0]);
610  std::string key = argv[1];
611  NameRecord& nameRecord = getNameRecord(target);
612  return Bottle(nameRecord.getProp(key));
613  }
614  return response;
615 }
616 
617 
618 std::string NameServer::cmdGarbageCollect(int argc, char* argv[])
619 {
620  YARP_UNUSED(argc);
621  YARP_UNUSED(argv);
622  std::string response;
623 
624  response = "No cleaning done.\n";
625 
626  return terminate(response);
627 }
628 
629 
630 std::string NameServer::textify(const Contact& address)
631 {
632  std::string result;
633  if (address.isValid()) {
634  if (address.getPort() >= 0) {
635  result = "registration name ";
636  result = result + address.getRegName() + " ip " + address.getHost() + " port " + NetType::toString(address.getPort()) + " type " + address.getCarrier() + "\n";
637  } else {
638  result = "registration name ";
639  result = result + address.getRegName() + " ip " + "none" + " port " + "none" + " type " + address.getCarrier() + "\n";
640  }
641  }
642  return result;
643 }
644 
645 
647 {
648  Bottle result;
649  if (address.isValid()) {
650  Bottle bname;
651  bname.addString("name");
652  bname.addString(address.getRegName().c_str());
653  Bottle bip;
654  bip.addString("ip");
655  bip.addString(address.getHost().c_str());
656  Bottle bnum;
657  bnum.addString("port_number");
658  bnum.addInt32(address.getPort());
659  Bottle bcarrier;
660  bcarrier.addString("carrier");
661  bcarrier.addString(address.getCarrier().c_str());
662 
663  result.addString("port");
664  result.addList() = bname;
665  result.addList() = bip;
666  result.addList() = bnum;
667  result.addList() = bcarrier;
668  } else {
669  Bottle bstate;
670  bstate.addString("error");
671  bstate.addInt32(-2);
672  bstate.addString("port not known");
673  result.addString("port");
674  result.addList() = bstate;
675  }
676  return result;
677 }
678 
679 
680 static std::string ns_terminate(const std::string& str)
681 {
682  return str + "*** end of message";
683 }
684 
685 std::string NameServer::terminate(const std::string& str)
686 {
687  return ns_terminate(str);
688 }
689 
690 
691 std::string NameServer::apply(const std::string& txt, const Contact& remote)
692 {
693  std::string result = "no command given";
694  mutex.lock();
695 
696  SplitString ss(txt.c_str());
697  if (ss.size() >= 2) {
698  std::string key = ss.get(1);
699  yCTrace(NAMESERVER, "dispatching to %s", key.c_str());
700  ss.set(1, remote.getHost().c_str());
701  result = dispatcher.dispatch(this, key.c_str(), ss.size() - 1, (char**)(ss.get() + 1));
702  if (result.empty()) {
703  Bottle b = ndispatcher.dispatch(this, key.c_str(), ss.size() - 1, (char**)(ss.get() + 1));
704  result = b.toString();
705  if (!result.empty()) {
706  result = result + "\n";
707  result = terminate(result);
708  }
709  }
710  yCTrace(NAMESERVER, "name server request -- %s", txt.c_str());
711  yCTrace(NAMESERVER, "name server result -- %s", result.c_str());
712  }
713  mutex.unlock();
714  return result;
715 }
716 
717 
718 bool NameServer::apply(const Bottle& cmd, Bottle& result, const Contact& remote)
719 {
720  Bottle rcmd;
721  rcmd.addString("ignored_legacy");
722  rcmd.append(cmd);
723  std::string in = rcmd.toString();
724  std::string out = apply(in, remote);
725  result.fromString(out);
726  return true;
727 }
728 
729 
730 #ifndef DOXYGEN_SHOULD_SKIP_THIS
731 
732 class MainNameServerWorker :
733  public PortReader
734 {
735 private:
736  NameServer* server;
737 
738 public:
739  MainNameServerWorker(NameServer* server)
740  {
741  this->server = server;
742  }
743 
744  bool read(ConnectionReader& reader) override
745  {
746  yCTrace(NAMESERVER, "read start");
747  std::string ref = "NAME_SERVER ";
748  bool ok = true;
749  std::string msg = "?";
750  bool haveMessage = false;
751  if (ok) {
752  if (reader.isTextMode()) {
753  msg = reader.expectText();
754  } else {
755  // migrate to binary mode support, eventually optimize
756  Bottle b;
757  b.read(reader);
758  msg = b.toString();
759  }
760  haveMessage = (!msg.empty());
761  msg = ref + msg;
762  }
763  if (reader.isActive() && haveMessage) {
764  yCDebug(NAMESERVER, "name server got message %s", msg.c_str());
765  size_t index = msg.find("NAME_SERVER");
766  if (index == 0) {
767  Contact remote = reader.getRemoteContact();
768  yCDebug(NAMESERVER, "name server receiving from %s", remote.toURI().c_str());
769  yCDebug(NAMESERVER, "name server request is %s", msg.c_str());
770  std::string result = server->apply(msg, remote);
771  ConnectionWriter* os = reader.getWriter();
772  if (os != nullptr) {
773  if (result.empty()) {
774  result = ns_terminate(std::string("unknown command ") + msg + "\n");
775  }
776  // This change is just to make Microsoft Telnet happy
777  std::string tmp;
778  for (char i : result) {
779  if (i == '\n') {
780  tmp += '\r';
781  }
782  tmp += i;
783  }
784  tmp += '\r';
785  os->appendText(tmp);
786 
787  yCDebug(NAMESERVER, "name server reply is %s", result.c_str());
788  std::string resultSparse = result;
789  size_t end = resultSparse.find("\n*** end of message");
790  if (end != std::string::npos) {
791  resultSparse[end] = '\0';
792  }
793  yCInfo(NAMESERVER, "%s", resultSparse.c_str());
794  }
795  } else {
796  yCInfo(NAMESERVER, "Name server ignoring unknown command: %s", msg.c_str());
797  }
798  }
799  yCTrace(NAMESERVER, "read stop");
800  return true;
801  }
802 };
803 
804 
805 class MainNameServer :
806  public NameServer,
807  public PortReaderCreator
808 {
809 private:
810  Port* port;
811 
812 public:
813  MainNameServer(int basePort, Port* port = nullptr) :
814  port(port)
815  {
816  setBasePort(basePort);
817  }
818 
819  void setPort(Port& port)
820  {
821  this->port = &port;
822  }
823 
824  void onEvent(Bottle& event) override
825  {
826  if (port != nullptr) {
827  port->write(event);
828  }
829  }
830 
831  PortReader* create() const override
832  {
833  return new MainNameServerWorker(const_cast<MainNameServer*>(this));
834  }
835 };
836 
837 
838 #endif // DOXYGEN_SHOULD_SKIP_THIS
STR
#define STR(x)
Definition: NameServer.cpp:41
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::os::impl::NameServer::apply
std::string apply(const std::string &txt, const Contact &remote) override
Definition: NameServer.cpp:691
yarp::os::impl::NameServer::terminate
std::string terminate(const std::string &str)
Definition: NameServer.cpp:685
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
Network.h
yarp::sig::file::read
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:827
ConnectionWriter.h
yarp::os::impl::SplitString
Split a string into pieces.
Definition: SplitString.h:27
Port.h
STR_HELP
static std::string STR_HELP(const char *txt)
Definition: NameServer.cpp:35
ns_terminate
static std::string ns_terminate(const std::string &str)
Definition: NameServer.cpp:680
yarp::os::impl::SplitString::size
int size()
Definition: SplitString.cpp:31
yarp::os::impl::NameServer::botify
static yarp::os::Bottle botify(const Contact &address)
Definition: NameServer.cpp:646
yarp::os::Bottle::fromString
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:207
YARP_UNUSED
#define YARP_UNUSED(var)
Definition: api.h:159
yarp::os::impl::NameServer::unregisterName
Contact unregisterName(const std::string &name)
Definition: NameServer.cpp:52
version.h
LogComponent.h
yarp::os::Contact::getRegName
std::string getRegName() const
Get the name associated with this Contact.
Definition: Contact.cpp:220
yarp::os::Contact::toString
std::string toString() const
Get a textual representation of the Contact.
Definition: Contact.cpp:306
NetType.h
yarp::os::impl::SplitString::set
void set(int index, const char *txt)
Definition: SplitString.cpp:36
yarp::os::Contact::toURI
std::string toURI(bool includeCarrier=true) const
Get a representation of the Contact as a URI.
Definition: Contact.cpp:316
NAMESERVER
const yarp::os::LogComponent & NAMESERVER()
Definition: NameServer.cpp:32
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::NetworkBase::getDefaultPortRange
static int getDefaultPortRange()
Under normal operation, YARP has a name server that manages a pool of (socket) ports starting at a po...
Definition: Network.cpp:2005
ManagedBytes.h
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::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
Property.h
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::impl::NameServer
Implementation of a YARP2-conforming name server.
Definition: NameServer.h:46
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::PortReaderCreator
A creator for readers.
Definition: PortReaderCreator.h:34
YARP_VERSION
#define YARP_VERSION
Definition: version.h:17
yarp::os::Bottle::addInt32
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:143
yarp::os::Vocab::encode
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition: Vocab.cpp:14
yarp::os::impl::NameServer::registerName
Contact registerName(const std::string &name, const Contact &address)
Definition: NameServer.h:58
NameConfig.h
yarp::os::ConnectionReader::getWriter
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
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::Bottle::addVocab
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:167
yCAssert
#define yCAssert(component, x)
Definition: LogComponent.h:172
NameServer.h
yarp::os::ConnectionReader::isActive
virtual bool isActive() const =0
yarp::os::impl::NameServer::queryName
Contact queryName(const std::string &name)
Definition: NameServer.cpp:153
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::NetType::toString
static std::string toString(int x)
Definition: NetType.cpp:138
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
yarp::os::Port::write
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:430
yCInfo
#define yCInfo(component,...)
Definition: LogComponent.h:135
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::ConnectionReader::expectText
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
yarp::os::Contact::isValid
bool isValid() const
Checks if a Contact is tagged as valid.
Definition: Contact.cpp:301
yarp::os::Value::fromString
void fromString(const char *str)
Set value to correspond to a textual representation.
Definition: Value.cpp:354
yarp::os::ConnectionReader::isTextMode
virtual bool isTextMode() const =0
Check if the connection is text mode.
Vocab.h
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::impl::NameServer::textify
static std::string textify(const Contact &address)
Definition: NameServer.cpp:630
Time.h
yCTrace
#define yCTrace(component,...)
Definition: LogComponent.h:88
SplitString.h
yarp::os::ConnectionReader::getRemoteContact
virtual Contact getRemoteContact() const =0
Gets information about who is supplying the data being read, if that information is available.
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yarp::os::Contact::setHost
void setHost(const std::string &hostname)
Set the host name to be the input parameter.
Definition: Contact.cpp:236
yarp::os::impl::SplitString::get
const char * get(int idx)
Definition: SplitString.cpp:44
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::ConnectionWriter::appendText
virtual void appendText(const std::string &str, const char terminate='\n')=0
Send a terminated string to the network connection.
Value.h
yarp::os::Bottle::append
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Definition: Bottle.cpp:383
yarp::os::NetType::toInt
static int toInt(const std::string &x)
Definition: NetType.cpp:160