YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Network.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <yarp/os/Network.h>
8
11#include <yarp/os/Bottle.h>
12#include <yarp/os/Carriers.h>
13#include <yarp/os/Face.h>
15#include <yarp/os/NameSpace.h>
16#include <yarp/os/NetType.h>
18#include <yarp/os/Port.h>
19#include <yarp/os/Route.h>
20#include <yarp/os/Time.h>
21#include <yarp/os/Vocab.h>
22#include <yarp/os/YarpPlugin.h>
33
34#ifdef YARP_HAS_ACE
35# include <ace/Init_ACE.h>
36# include <ace/config.h>
37// In one the ACE headers there is a definition of "main" for WIN32
38# ifdef main
39# undef main
40# endif
41#endif
42
43#include <cstdio>
44#include <cstdlib>
45#include <mutex>
46#include <string>
47
48using namespace yarp::os::impl;
49using namespace yarp::os;
50
51namespace {
52YARP_OS_LOG_COMPONENT(NETWORK, "yarp.os.Network")
53}
54
55static int __yarp_is_initialized = 0;
56static bool __yarp_auto_init_active = false; // was yarp auto-initialized?
57
58
64{
65public:
82};
84
90
91static bool needsLookup(const Contact& contact)
92{
93 if (!contact.getHost().empty()) {
94 return false;
95 }
96 if (contact.getCarrier() == "topic") {
97 return false;
98 }
99 return true;
100}
101
102static int noteDud(const Contact& src)
103{
104 NameStore* store = getNameSpace().getQueryBypass();
105 if (store != nullptr) {
106 return store->announce(src.getName(), 0);
107 }
108 Bottle cmd;
109 Bottle reply;
110 cmd.addString("announce");
111 cmd.addString(src.getName().c_str());
112 cmd.addInt32(0);
113 ContactStyle style;
114 bool ok = NetworkBase::writeToNameServer(cmd,
115 reply,
116 style);
117 return ok ? 0 : 1;
118}
119
120
121static int enactConnection(const Contact& src,
122 const Contact& dest,
123 const ContactStyle& style,
124 int mode,
125 bool reversed)
126{
128 rpc.admin = true;
129 rpc.quiet = style.quiet;
130 rpc.timeout = style.timeout;
131
133 "enactConnection: SRC %s DST %s using carrier %s, MODE=%d, rev=%d",
134 src.getName().c_str(),
135 dest.getName().c_str(),
136 style.carrier.c_str(),
137 mode,
138 reversed);
139
140 if (style.persistent) {
141 bool ok = false;
142 // we don't talk to the ports, we talk to the nameserver
143 NameSpace& ns = getNameSpace();
144 if (mode == YARP_ENACT_CONNECT) {
145 ok = ns.connectPortToPortPersistently(src, dest, style);
146 } else if (mode == YARP_ENACT_DISCONNECT) {
147 ok = ns.disconnectPortToPortPersistently(src, dest, style);
148 } else {
149 yCError(NETWORK, "Failure: cannot check subscriptions yet");
150 return 1;
151 }
152 if (!ok) {
153 return 1;
154 }
155 if (!style.quiet) {
156 yCInfo(NETWORK, "Success: port-to-port persistent connection added.");
157 }
158 return 0;
159 }
160
161 Bottle cmd;
162 Bottle reply;
163 cmd.addVocab32("list");
164 cmd.addVocab32(reversed ? "in" : "out");
165 cmd.addString(dest.getName().c_str());
166 yCDebug(NETWORK, "asking %s: %s", src.toString().c_str(), cmd.toString().c_str());
167 bool ok = NetworkBase::write(src, cmd, reply, rpc);
168 if (!ok) {
169 noteDud(src);
170 return 1;
171 }
172 if (reply.check("carrier")) {
173 std::string carrier = reply.find("carrier").asString();
174 if (!style.quiet) {
176 "Connection found between %s and %s using carrier %s",
177 src.getName().c_str(),
178 dest.getName().c_str(),
179 carrier.c_str());
180 }
181 if (mode == YARP_ENACT_EXISTS) {
182 return (carrier == style.carrier) ? 0 : 1;
183 }
184
185 // This is either a connect or a disconnect command, but the current
186 // connection is connectionless, the other side will not know that we
187 // are closing the connection and therefore will continue sending data.
188 // Therefore we send an explicit disconnect here.
189 bool currentIsConnectionLess = false;
190 bool currentIsPush = true;
191 if (reply.check("push")) {
192 currentIsPush = reply.find("push").asBool();
193 }
194 if (reply.check("connectionless")) {
195 currentIsConnectionLess = reply.find("connectionless").asBool();
196 }
197 if (currentIsConnectionLess && ((reversed && currentIsPush) || (!reversed && !currentIsPush))) {
198 enactConnection(dest, src, style, YARP_ENACT_DISCONNECT, !reversed);
199 }
200 }
201 if (mode == YARP_ENACT_EXISTS) {
202 return 1;
203 }
204
206
207 // Let's ask the destination to connect/disconnect to the source.
208 // We assume the YARP carrier will reverse the connection if
209 // appropriate when connecting.
210 cmd.clear();
211 reply.clear();
212 cmd.addVocab32(act);
213 Contact c = dest;
214 if (!style.carrier.empty()) {
215 c.setCarrier(style.carrier);
216 }
217 if (mode != YARP_ENACT_DISCONNECT) {
218 cmd.addString(c.toString());
219 } else {
220 cmd.addString(c.getName());
221 }
222
223 Contact c2 = src;
224 if (c2.getPort() <= 0) {
226 }
227
228 yCDebug(NETWORK, "** asking %s: %s", src.toString().c_str(), cmd.toString().c_str());
229 ok = NetworkBase::write(c2, cmd, reply, rpc);
230 if (!ok) {
231 noteDud(src);
232 return 1;
233 }
234 std::string msg;
235 if (reply.get(0).isInt32()) {
236 ok = (reply.get(0).asInt32() == 0);
237 msg = reply.get(1).asString();
238 } else {
239 // older protocol
240 // FIXME Is this protocol still in use?
241 msg = reply.get(0).asString();
242 ok = msg[0] == 'A' || msg[0] == 'R';
243 }
244 if (mode == YARP_ENACT_DISCONNECT && !ok) {
245 msg = "no such connection";
246 }
247 if (mode == YARP_ENACT_CONNECT && !ok) {
248 noteDud(dest);
249 }
250 if (!style.quiet) {
251 if (!ok) {
252 yCError(NETWORK, "%s %s", "Failure:", msg.c_str());
253 } else if (style.verboseOnSuccess) {
254 yCInfo(NETWORK, "%s %s", "Success:", msg.c_str());
255 }
256 }
257 return ok ? 0 : 1;
258}
259
260static std::string collectParams(Contact& c)
261{
262 std::string carrier_name = c.getCarrier();
263 auto pos = carrier_name.find('+');
264 if (pos != std::string::npos) {
265 return carrier_name.substr(pos);
266 }
267 return {};
268}
269
270static std::string extractCarrierNameOnly(const std::string& carrier_name_with_params)
271{
272 return carrier_name_with_params.substr(0, carrier_name_with_params.find('+'));
273}
274
275/*
276
277 Connect two ports, bearing in mind that one of them may not be
278 a regular YARP port.
279
280 Normally, YARP sends a request to the source port asking it to
281 connect to the destination port. But the source port may not
282 be capable of initiating connections, in which case we can
283 request the destination port to connect to the source (this
284 is appropriate for carriers that can reverse the initiative).
285
286 The source or destination could also be topic ports, which are
287 entirely virtual. In that case, we just need to tell the name
288 server, and it will take care of the details.
289
290*/
291
292static int metaConnect(const std::string& src,
293 const std::string& dest,
294 ContactStyle style,
295 int mode)
296{
298 "working on connection %s to %s (%s)",
299 src.c_str(),
300 dest.c_str(),
301 (mode == YARP_ENACT_CONNECT) ? "connect" : ((mode == YARP_ENACT_DISCONNECT) ? "disconnect" : "check"));
302 // check if source name and destination name contain spaces
303 if (dest.find(' ') != std::string::npos || src.find(' ') != std::string::npos) {
305 "Failure: no way to make connection %s->%s, one of the port names contains a space character.",
306 src.c_str(),
307 dest.c_str());
308 return 1;
309 }
310
312 "METACONNECT: src=%s dest=%s style=%s",
313 src.c_str(),
314 dest.c_str(),
315 style.carrier.c_str());
316
317 // get the expressed contacts, without name server input
320
322 "DYNAMIC_SRC: name=%s, carrier=%s",
323 dynamicSrc.getName().c_str(),
324 dynamicSrc.getCarrier().c_str());
326 "DYNAMIC_DST: name=%s, carrier=%s",
327 dynamicDest.getName().c_str(),
328 dynamicDest.getCarrier().c_str());
329
332 "Failure: no way to make connection, invalid source '%s'",
333 dynamicSrc.getName().c_str());
334 return 1;
335 }
338 "Failure: no way to make connection, invalid destination '%s'",
339 dynamicDest.getName().c_str());
340 return 1;
341 }
342
343 bool topical = style.persistent;
344 if (dynamicSrc.getCarrier() == "topic" || dynamicDest.getCarrier() == "topic") {
345 topical = true;
346 }
347
348 bool topicalNeedsLookup = !getNameSpace().connectionHasNameOfEndpoints();
349
350 // fetch completed contacts from name server, if needed
355 if (!staticSrc.isValid()) {
356 if (!style.persistent) {
357 if (!style.quiet) {
359 "Failure: could not find source port %s",
360 src.c_str());
361 }
362 return 1;
363 }
365 }
366 } else {
368 }
369 if (staticSrc.getCarrier().empty()) {
370 staticSrc.setCarrier("tcp");
371 }
372 if (staticDest.getCarrier().empty()) {
373 staticDest.setCarrier("tcp");
374 }
375
378 if (!staticDest.isValid()) {
379 if (!style.persistent) {
380 if (!style.quiet) {
382 "Failure: could not find destination port %s",
383 dest.c_str());
384 }
385 return 1;
386 }
388 }
389 } else {
391 }
392
394 "STATIC_SRC: name=%s, carrier=%s",
395 staticSrc.getName().c_str(),
396 staticSrc.getCarrier().c_str());
398 "STATIC_DST: name=%s, carrier=%s",
399 staticDest.getName().c_str(),
400 staticDest.getCarrier().c_str());
401
402 //DynamicSrc and DynamicDst are the contacts created by connect command
403 //while staticSrc and staticDest are contacts created by querying th server
404
405 if (staticSrc.getCarrier() == "xmlrpc" && (staticDest.getCarrier() == "xmlrpc" || (staticDest.getCarrier().find("rossrv") == 0)) && mode == YARP_ENACT_CONNECT) {
406 // Unconnectable in general
407 // Let's assume the first part is a YARP port, and use "tcp" instead
408 staticSrc.setCarrier("tcp");
409 staticDest.setCarrier("tcp");
410 }
411
412 std::string carrierConstraint;
413
414 // see if we can do business with the source port
415 bool srcIsCompetent = false;
416 bool srcIsTopic = false;
417 if (staticSrc.getCarrier() != "topic") {
418 if (!topical) {
419 Carrier* srcCarrier = nullptr;
421 "staticSrc.getCarrier = %s",
422 staticSrc.getCarrier().c_str());
423 if (!staticSrc.getCarrier().empty()) {
425 }
426 if (srcCarrier != nullptr) {
428 "srcCarrier is NOT null; its name is %s",
429 srcCarrier->getName().c_str());
430 std::string srcBootstrap = srcCarrier->getBootstrapCarrierName();
431 if (!srcBootstrap.empty()) {
432
434 "it is competent (bootstrapname is %s), while its name is %s",
435 srcBootstrap.c_str(),
436 srcCarrier->getName().c_str());
437 srcIsCompetent = true;
438 } else {
439 //if the srcCarrier is not competent, (that is it can't perform the starting yarp handshaking)
440 //set the carrier constraint equal to the carrier with which the posrt had been registered.
441 carrierConstraint = staticSrc.getCarrier();
443 "it is NOT competent. its constraint is %s",
444 carrierConstraint.c_str());
445 }
446 delete srcCarrier;
447 srcCarrier = nullptr;
448 }
449 }
450 } else {
451 srcIsTopic = true;
452 }
453
454 // see if we can do business with the destination port
455 bool destIsCompetent = false;
456 bool destIsTopic = false;
457 if (staticDest.getCarrier() != "topic") {
458 if (!topical) {
459 Carrier* destCarrier = nullptr;
461 "staticDest.getCarrier = %s",
462 staticDest.getCarrier().c_str());
463 if (!staticDest.getCarrier().empty()) {
465 }
466 if (destCarrier != nullptr) {
468 "destCarrier is NOT null; its name is %s",
469 destCarrier->getName().c_str());
470 std::string destBootstrap = destCarrier->getBootstrapCarrierName();
471 if (!destBootstrap.empty()) {
473 "it is competent (bootstrapname is %s), while its name is %s",
474 destBootstrap.c_str(),
475 destCarrier->getName().c_str());
476 destIsCompetent = true;
477 } else {
478 //if the destCarrier is not competent, (that is it can't perform the starting yarp handshaking)
479 //set the carrier constraint equal to the carrier with which the posrt had been registered.
480 carrierConstraint = staticDest.getCarrier();
482 "it is NOT competent. its constraint is %s",
483 carrierConstraint.c_str());
484 }
485 delete destCarrier;
486 destCarrier = nullptr;
487 }
488 }
489 } else {
490 destIsTopic = true;
491 }
492
493 if (srcIsTopic || destIsTopic) {
494 Bottle cmd;
495 Bottle reply;
496 NameSpace& ns = getNameSpace();
497
498 bool ok = false;
499 if (srcIsTopic) {
500 if (mode == YARP_ENACT_CONNECT) {
501 ok = ns.connectTopicToPort(staticSrc, staticDest, style);
502 } else if (mode == YARP_ENACT_DISCONNECT) {
504 } else {
505 yCError(NETWORK, "Failure: cannot check subscriptions yet");
506 return 1;
507 }
508 } else {
509 if (mode == YARP_ENACT_CONNECT) {
510 ok = ns.connectPortToTopic(staticSrc, staticDest, style);
511 } else if (mode == YARP_ENACT_DISCONNECT) {
513 } else {
514 yCError(NETWORK, "Failure: cannot check subscriptions yet");
515 return 1;
516 }
517 }
518 if (!ok) {
519 return 1;
520 }
521 if (!style.quiet) {
522 if (style.verboseOnSuccess) {
523 yCInfo(NETWORK, "Success: connection to topic %s.", mode == YARP_ENACT_CONNECT ? "added" : "removed");
524 }
525 }
526 return 0;
527 }
528
530 "dynamicSrc.getCarrier() = %s",
531 dynamicSrc.getCarrier().c_str());
533 "dynamicDest.getCarrier() = %s",
534 dynamicDest.getCarrier().c_str());
536 "staticSrc.getCarrier() = %s",
537 staticSrc.getCarrier().c_str());
539 "staticDest.getCarrier() = %s",
540 staticDest.getCarrier().c_str());
542 "carrierConstraint is %s",
543 carrierConstraint.c_str());
544
546 "style.carrier (1) is %s",
547 style.carrier.c_str());
548
549
550 if (!dynamicSrc.getCarrier().empty()) { //if in connect command the user specified the carrier of src port
551 style.carrier = dynamicSrc.getCarrier();
553 "style.carrier is %s ==> in connect command the user specified the carrier of src port",
554 style.carrier.c_str());
555 }
556
557 if (!dynamicDest.getCarrier().empty()) { //if in connect command the user specified the carrier of dest port or the carrier of the connection
558 style.carrier = dynamicDest.getCarrier();
560 "style.carrier is %s ==> in connect command the user specified the carrier of dest port or the carrier of the connection",
561 style.carrier.c_str());
562 }
563
565 "at the end style style.carrier is %s",
566 style.carrier.c_str());
567
568 //here we'll check if the style carrier and the constraint carrier are equal.
569 //note that in both string may contain params of carrier, so we need to comapare only the name of carrier.
570 if (!style.carrier.empty() && !carrierConstraint.empty()) {
571 //get only carrier name of style.
573
574 //get only carrier name of carrierConstraint.
576
578 yCError(NETWORK, "Failure: conflict between %s and %s", style_carrier_name.c_str(), carrier_constraint_name.c_str());
579 return 1;
580 }
582 "style_carrier_name=%s and carrier_constraint_name=%s are equals!",
583 style_carrier_name.c_str(),
585 }
586 //we are going to choose the carrier of this connection, and we collect parameters specified by user
587 //in order to pass them to the carrier, so it can configure itself.
588 if (!carrierConstraint.empty()) {
590 //if I'm here means that sorce or dest is not competent.
591 //so we need to get parameters of carrier given in connect command.
593 "if I'm here means that source or dest is not competent");
594 std::string c = dynamicSrc.getCarrier();
597 }
598 c = dynamicDest.getCarrier();
601 }
602 }
603 if (style.carrier.empty()) {
604 style.carrier = staticDest.getCarrier();
605 //if I'm here means that both src and dest are copentent and the user didn't specified a carrier in the connect command
607 "if I'm here means that both src and dest are compentent and the user didn't specified a carrier in the connect command");
608 std::string c = dynamicSrc.getCarrier();
611 }
612 }
613
614 if (style.carrier.empty()) {
615 style.carrier = staticSrc.getCarrier();
616 yCTrace(NETWORK, "the chosen style carrier is static src");
617 }
618
619 //now stylecarrier contains the carrier chosen for this connection
620
622 "style_carrier with params =%s",
623 style.carrier.c_str());
624
625 bool connectionIsPush = false;
626 bool connectionIsPull = false;
627 Carrier* connectionCarrier = nullptr;
628 if (style.carrier != "topic") {
630 if (connectionCarrier != nullptr) {
633 }
634 }
635
636 int result = -1;
638 // Classic case.
640 delete connectionCarrier;
641 return enactConnection(staticSrc, c, style, mode, false);
642 }
645 delete connectionCarrier;
646 return enactConnection(staticDest, c, style, mode, true);
647 }
648
649 if (connectionCarrier != nullptr) {
650 if (!connectionIsPull) {
652 result = connectionCarrier->connect(staticSrc, c, style, mode, false);
653 } else {
655 result = connectionCarrier->connect(staticDest, c, style, mode, true);
656 }
657 }
658 if (connectionCarrier != nullptr) {
659 delete connectionCarrier;
660 connectionCarrier = nullptr;
661 }
662 if (result != -1) {
663 if (!style.quiet) {
664 if (result == 0) {
665 if (style.verboseOnSuccess) {
666 yCInfo(NETWORK, "Success: added connection using custom carrier method");
667 }
668 } else {
669 yCError(NETWORK, "Failure: custom carrier method did not work");
670 }
671 }
672 return result;
673 }
674
675 if (mode != YARP_ENACT_DISCONNECT) {
676 yCError(NETWORK, "Failure: no way to make connection %s->%s", src.c_str(), dest.c_str());
677 }
678
679 return 1;
680}
681
682bool NetworkBase::connect(const std::string& src, const std::string& dest, const std::string& carrier, bool quiet)
683{
684 ContactStyle style;
685 style.quiet = quiet;
686 if (!carrier.empty()) {
687 style.carrier = carrier;
688 }
689 return connect(src, dest, style);
690}
691
692bool NetworkBase::connect(const std::string& src,
693 const std::string& dest,
694 const ContactStyle& style)
695{
696 int result = metaConnect(src, dest, style, YARP_ENACT_CONNECT);
697 return result == 0;
698}
699
700bool NetworkBase::disconnect(const std::string& src,
701 const std::string& dest,
702 bool quiet)
703{
704 ContactStyle style;
705 style.quiet = quiet;
706 return disconnect(src, dest, style);
707}
708
709bool NetworkBase::disconnect(const std::string& src,
710 const std::string& dest,
711 const ContactStyle& style)
712{
713 int result = metaConnect(src, dest, style, YARP_ENACT_DISCONNECT);
714 return result == 0;
715}
716
717bool NetworkBase::disconnect(const std::string& src, const std::string& dest, const std::string& carrier, bool quiet)
718{
719 ContactStyle style;
720 style.quiet = quiet;
721 if (!carrier.empty()) {
722 style.carrier = carrier;
723 }
724 return disconnect(src, dest, style);
725}
726
727bool NetworkBase::isConnected(const std::string& src,
728 const std::string& dest,
729 bool quiet)
730{
731 ContactStyle style;
732 style.quiet = quiet;
733 return isConnected(src, dest, style);
734}
735
736bool NetworkBase::isConnected(const std::string& src, const std::string& dest, const std::string& carrier, bool quiet)
737{
738 ContactStyle style;
739 style.quiet = quiet;
740 if (!carrier.empty()) {
741 style.carrier = carrier;
742 }
743 return isConnected(src, dest, style);
744}
745
746bool NetworkBase::exists(const std::string& port, bool quiet, bool checkVer)
747{
748 ContactStyle style;
749 style.quiet = quiet;
750 return exists(port, style, checkVer);
751}
752
753bool NetworkBase::exists(const std::string& port, const ContactStyle& style, bool checkVer)
754{
755 bool silent = style.quiet;
756 Contact address = NetworkBase::queryName(port);
757 if (!address.isValid()) {
758 if (!silent) {
759 yCInfo(NETWORK, "Address of port %s is not valid", port.c_str());
760 }
761 return false;
762 }
763
764 Contact address2(address);
765 if (style.timeout >= 0) {
766 address2.setTimeout((float)style.timeout);
767 }
769
770 if (out == nullptr) {
771 if (!silent) {
772 yCInfo(NETWORK, "Cannot connect to port %s", port.c_str());
773 }
774 return false;
775 }
776 out->close();
777 delete out;
778 out = nullptr;
779
780 if (!checkVer) {
781 return true;
782 }
783
784 ContactStyle style2 = style;
785 style2.admin = true;
786 Bottle cmd("[ver]");
787 Bottle resp;
788 bool ok = NetworkBase::write(Contact(port), cmd, resp, style2);
789 if (!ok) {
790 return false;
791 }
792 if (resp.get(0).toString() != "ver" && resp.get(0).toString() != "dict") {
793 // YARP nameserver responds with a version
794 // ROS nameserver responds with a dictionary of error data
795 // Treat everything else an unknown
796 return false;
797 }
798
799 return true;
800}
801
802
803bool NetworkBase::waitConnection(const std::string& source, const std::string& destination, bool quiet)
804{
805 int ct = 1;
806 while (true) {
807
808 if (ct % 30 == 1) {
809 if (!quiet) {
810 yCInfo(NETWORK, "Waiting for %s->%s...", source.c_str(), destination.c_str());
811 }
812 }
813 ct++;
814
815 int result = NetworkBase::isConnected(source, destination, true) ? 0 : 1;
816 if (result != 0) {
818 } else {
819 return true;
820 }
821 }
822}
823
824
825bool NetworkBase::waitPort(const std::string& target, bool quiet)
826{
827 int ct = 1;
828 while (true) {
829
830 if (ct % 30 == 1) {
831 if (!quiet) {
832 yCInfo(NETWORK, "Waiting for %s...", target.c_str());
833 }
834 }
835 ct++;
836
837 bool result = exists(target, true, false);
838 if (!result) {
840 } else {
841 return true;
842 }
843 }
844}
845
846
847bool NetworkBase::sync(const std::string& port, bool quiet)
848{
849 bool result = waitPort(port, quiet);
850 if (result) {
851 poll(port, true);
852 }
853 return result;
854}
855
856
861
870
875
880
881#if defined(YARP_HAS_ACE)
882namespace {
883class YARP_ACE
884{
885private:
886 YARP_ACE()
887 {
888 ACE::init();
889 }
890
891public:
892 ~YARP_ACE()
893 {
894 ACE::fini();
895 }
896
897 static YARP_ACE& init()
898 {
899 static YARP_ACE ace;
900 return ace;
901 }
902};
903} // namespace
904#endif
905
906
908{
909 YARP_UNUSED(custom);
910 if (__yarp_is_initialized == 0) {
911 // Broken pipes need to be dealt with through other means
912 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
913
914#ifdef YARP_HAS_ACE
915 YARP_ACE::init();
916#endif
917
918 // make sure system is actually able to do things fast
920
921 // MultiNameSpace is a c++11 singleton and need to be initialized
922 // before the first port that is opened and it has to exist until
923 // the last port is closed.
924 getNameSpace();
925
926 // Increment counter before initializing the clock.
928
929 // The network clock open a port, and inside the open of the port
930 // the __yarp_is_initialized counter is checked > 0.
933 }
934 } else {
936 }
937}
938
940{
941 if (__yarp_is_initialized == 1) {
942 // The log forwarder needs to be shut down in order to close the
943 // internal port. The shutdown method will do nothing if the
944 // LogForwarded was not used.
946
949
950 // reset system timer resolution
952 }
953 if (__yarp_is_initialized > 0) {
955 }
956}
957
959{
960 std::string clock;
963 if (!clock.empty()) {
965 } else {
967 }
968 }
969
970 switch (clockType) {
972 yCDebug(NETWORK, "Using SYSTEM clock");
974 break;
975
977 yCDebug(NETWORK, "Using NETWORK clock");
979 // check of valid parameter is done inside the call, throws YARP_FAIL in case of error
981 break;
982
983 case YARP_CLOCK_CUSTOM: {
984 yCDebug(NETWORK, "Using CUSTOM clock");
985 // check of valid parameter is done inside the call, throws YARP_FAIL in case of error
987 } break;
988
989 default:
990 yCFatal(NETWORK, "yarpClockInit called with unknown clock type. Quitting");
991 break;
992 }
993}
994
995Contact NetworkBase::queryName(const std::string& name)
996{
997 yCDebug(NETWORK, "query name %s", name.c_str());
998 if (getNameServerName() == name) {
999 yCDebug(NETWORK, "query recognized as name server: %s", name.c_str());
1000 return getNameServerContact();
1001 }
1002 Contact c = c.fromString(name);
1003 if (c.isValid() && c.getPort() > 0) {
1004 return c;
1005 }
1006 return getNameSpace().queryName(name);
1007}
1008
1009
1010Contact NetworkBase::registerName(const std::string& name)
1011{
1012 yCDebug(NETWORK, "register name %s", name.c_str());
1013 return getNameSpace().registerName(name);
1014}
1015
1016
1018{
1019 yCDebug(NETWORK, "register contact %s", contact.toString().c_str());
1020 return getNameSpace().registerContact(contact);
1021}
1022
1023Contact NetworkBase::unregisterName(const std::string& name)
1024{
1025 return getNameSpace().unregisterName(name);
1026}
1027
1028
1030{
1031 return getNameSpace().unregisterContact(contact);
1032}
1033
1034
1035bool NetworkBase::setProperty(const char* name,
1036 const char* key,
1037 const Value& value)
1038{
1039 return getNameSpace().setProperty(name, key, value);
1040}
1041
1042
1043Value* NetworkBase::getProperty(const char* name, const char* key)
1044{
1045 return getNameSpace().getProperty(name, key);
1046}
1047
1048
1050{
1051 return getNameSpace().setLocalMode(flag);
1052}
1053
1055{
1056 NameSpace& ns = getNameSpace();
1057 return ns.localOnly();
1058}
1059
1061{
1062 // could replace with ACE assertions, except should not
1063 // evaporate in release mode
1065}
1066
1067bool NetworkBase::setConnectionQos(const std::string& src, const std::string& dest, const QosStyle& style, bool quiet)
1068{
1069 return setConnectionQos(src, dest, style, style, quiet);
1070}
1071
1072bool NetworkBase::setConnectionQos(const std::string& src, const std::string& dest, const QosStyle& srcStyle, const QosStyle& destStyle, bool quiet)
1073{
1074
1075 //e.g., prop set /portname (sched ((priority 30) (policy 1))) (qos ((tos 0)))
1076 yarp::os::Bottle cmd;
1077 yarp::os::Bottle reply;
1078
1079 // ignore if everything left as default
1080 if (srcStyle.getPacketPriorityAsTOS() != -1 || srcStyle.getThreadPolicy() != -1) {
1081 // set the source Qos
1082 cmd.addString("prop");
1083 cmd.addString("set");
1084 cmd.addString(dest.c_str());
1085 Bottle& sched = cmd.addList();
1086 sched.addString("sched");
1087 Property& sched_prop = sched.addDict();
1088 sched_prop.put("priority", srcStyle.getThreadPriority());
1089 sched_prop.put("policy", srcStyle.getThreadPolicy());
1090 Bottle& qos = cmd.addList();
1091 qos.addString("qos");
1092 Property& qos_prop = qos.addDict();
1093 qos_prop.put("tos", srcStyle.getPacketPriorityAsTOS());
1095 bool ret = write(srcCon, cmd, reply, true, true, 2.0);
1096 if (!ret) {
1097 if (!quiet) {
1098 yCError(NETWORK, "Cannot write to '%s'", src.c_str());
1099 }
1100 return false;
1101 }
1102 if (reply.get(0).asString() != "ok") {
1103 if (!quiet) {
1104 yCError(NETWORK, "Cannot set qos properties of '%s'. (%s)", src.c_str(), reply.toString().c_str());
1105 }
1106 return false;
1107 }
1108 }
1109
1110 // ignore if everything left as default
1111 if (destStyle.getPacketPriorityAsTOS() != -1 || destStyle.getThreadPolicy() != -1) {
1112 // set the destination Qos
1113 cmd.clear();
1114 reply.clear();
1115 cmd.addString("prop");
1116 cmd.addString("set");
1117 cmd.addString(src.c_str());
1118 Bottle& sched2 = cmd.addList();
1119 sched2.addString("sched");
1120 Property& sched_prop2 = sched2.addDict();
1121 sched_prop2.put("priority", destStyle.getThreadPriority());
1122 sched_prop2.put("policy", destStyle.getThreadPolicy());
1123 Bottle& qos2 = cmd.addList();
1124 qos2.addString("qos");
1125 Property& qos_prop2 = qos2.addDict();
1126 qos_prop2.put("tos", destStyle.getPacketPriorityAsTOS());
1128 bool ret = write(destCon, cmd, reply, true, true, 2.0);
1129 if (!ret) {
1130 if (!quiet) {
1131 yCError(NETWORK, "Cannot write to '%s'", dest.c_str());
1132 }
1133 return false;
1134 }
1135 if (reply.get(0).asString() != "ok") {
1136 if (!quiet) {
1137 yCError(NETWORK, "Cannot set qos properties of '%s'. (%s)", dest.c_str(), reply.toString().c_str());
1138 }
1139 return false;
1140 }
1141 }
1142 return true;
1143}
1144
1145static bool getPortQos(const std::string& port, const std::string& unit, QosStyle& style, bool quiet)
1146{
1147 // request: "prop get /portname"
1148 // reply : "(sched ((priority 30) (policy 1))) (qos ((priority HIGH)))"
1149 yarp::os::Bottle cmd;
1150 yarp::os::Bottle reply;
1151
1152 // set the source Qos
1153 cmd.addString("prop");
1154 cmd.addString("get");
1155 cmd.addString(unit.c_str());
1157 bool ret = NetworkBase::write(portCon, cmd, reply, true, true, 2.0);
1158 if (!ret) {
1159 if (!quiet) {
1160 yCError(NETWORK, "Cannot write to '%s'", port.c_str());
1161 }
1162 return false;
1163 }
1164 if (reply.size() == 0 || reply.get(0).asString() == "fail") {
1165 if (!quiet) {
1166 yCError(NETWORK, "Cannot get qos properties of '%s'. (%s)", port.c_str(), reply.toString().c_str());
1167 }
1168 return false;
1169 }
1170
1171 Bottle& sched = reply.findGroup("sched");
1172 Bottle* sched_prop = sched.find("sched").asList();
1173 style.setThreadPriority(sched_prop->find("priority").asInt32());
1174 style.setThreadPolicy(sched_prop->find("policy").asInt32());
1175 Bottle& qos = reply.findGroup("qos");
1176 Bottle* qos_prop = qos.find("qos").asList();
1177 style.setPacketPrioritybyTOS(qos_prop->find("tos").asInt32());
1178
1179 return true;
1180}
1181
1182bool NetworkBase::getConnectionQos(const std::string& src, const std::string& dest, QosStyle& srcStyle, QosStyle& destStyle, bool quiet)
1183{
1184 if (!getPortQos(src, dest, srcStyle, quiet)) {
1185 return false;
1186 }
1187 if (!getPortQos(dest, src, destStyle, quiet)) {
1188 return false;
1189 }
1190 return true;
1191}
1192
1193bool NetworkBase::isValidPortName(const std::string& portName)
1194{
1195 if (portName.empty()) {
1196 return false;
1197 }
1198
1199 if (portName == "...") {
1200 return true;
1201 }
1202
1203 if (portName.at(0) != '/') {
1204 return false;
1205 }
1206
1207 if (portName.at(portName.size() - 1) == '/') {
1208 return false;
1209 }
1210
1211 if (portName.find(' ') != std::string::npos) {
1212 return false;
1213 }
1214
1215 return true;
1216}
1217
1218
1219bool NetworkBase::write(const Contact& contact,
1220 PortWriter& cmd,
1221 PortReader& reply,
1222 bool admin,
1223 bool quiet,
1224 double timeout)
1225{
1226 ContactStyle style;
1227 style.admin = admin;
1228 style.quiet = quiet;
1229 style.timeout = timeout;
1230 style.carrier = contact.getCarrier();
1231 return write(contact, cmd, reply, style);
1232}
1233
1234bool NetworkBase::write(const Contact& contact,
1235 PortWriter& cmd,
1236 PortReader& reply,
1237 const ContactStyle& style)
1238{
1239 if (!getNameSpace().serverAllocatesPortNumbers()) {
1240 // switch to more up-to-date method
1241
1242 Port port;
1243 port.setAdminMode(style.admin);
1244 port.openFake("network_write");
1245 Contact ec = contact;
1246 if (!style.carrier.empty()) {
1247 ec.setCarrier(style.carrier);
1248 }
1249 if (!port.addOutput(ec)) {
1250 if (!style.quiet) {
1251 yCError(NETWORK, "Cannot make connection to '%s'", ec.toString().c_str());
1252 }
1253 return false;
1254 }
1255
1256 bool ok = port.write(cmd, reply);
1257 return ok;
1258 }
1259
1260 const char* connectionName = "admin";
1261 std::string name = contact.getName();
1262 const char* targetName = name.c_str(); // use carefully!
1263 Contact address = contact;
1264 if (!address.isValid()) {
1265 address = getNameSpace().queryName(targetName);
1266 }
1267 if (!address.isValid()) {
1268 if (!style.quiet) {
1269 yCError(NETWORK, "cannot find port %s", targetName);
1270 }
1271 return false;
1272 }
1273
1274 if (style.timeout > 0) {
1275 address.setTimeout((float)style.timeout);
1276 }
1277 OutputProtocol* out = Carriers::connect(address);
1278 if (out == nullptr) {
1279 if (!style.quiet) {
1280 yCError(NETWORK, "Cannot connect to port %s", targetName);
1281 }
1282 return false;
1283 }
1284 if (style.timeout > 0) {
1285 out->setTimeout(style.timeout);
1286 }
1287
1288 Route r(connectionName, targetName, (!style.carrier.empty()) ? style.carrier.c_str() : "text_ack");
1289 out->open(r);
1290
1291 PortCommand pc(0, style.admin ? "a" : "d");
1292 BufferedConnectionWriter bw(out->getConnection().isTextMode(),
1293 out->getConnection().isBareMode());
1294 bool ok = true;
1295 if (out->getConnection().canEscape()) {
1296 ok = pc.write(bw);
1297 }
1298 if (!ok) {
1299 if (!style.quiet) {
1300 yCError(NETWORK, "could not write to connection");
1301 }
1302 delete out;
1303 return false;
1304 }
1305 ok = cmd.write(bw);
1306 if (!ok) {
1307 if (!style.quiet) {
1308 yCError(NETWORK, "could not write to connection");
1309 }
1310 delete out;
1311 return false;
1312 }
1313 if (style.expectReply) {
1314 bw.setReplyHandler(reply);
1315 }
1316 out->write(bw);
1317 if (out != nullptr) {
1318 delete out;
1319 out = nullptr;
1320 }
1321 return true;
1322}
1323
1324bool NetworkBase::write(const std::string& port_name,
1325 PortWriter& cmd,
1326 PortReader& reply)
1327{
1328 return write(Contact(port_name), cmd, reply);
1329}
1330
1331bool NetworkBase::isConnected(const std::string& src, const std::string& dest, const ContactStyle& style)
1332{
1333 int result = metaConnect(src, dest, style, YARP_ENACT_EXISTS);
1334 if (result != 0) {
1335 if (!style.quiet) {
1336 yCInfo(NETWORK, "No connection from %s to %s found",
1337 src.c_str(),
1338 dest.c_str());
1339 }
1340 }
1341 return result == 0;
1342}
1343
1344
1346{
1347 NameConfig nc;
1348 std::string name = nc.getNamespace(false);
1349 return name;
1350}
1351
1352
1354{
1355 return getNameSpace().getNameServerContact();
1356}
1357
1358
1359bool NetworkBase::setNameServerName(const std::string& name)
1360{
1361 NameConfig nc;
1363 nc.writeConfig(fname, name + "\n");
1364 nc.getNamespace(true);
1365 getNameSpace().activate(true);
1366 return true;
1367}
1368
1369
1371{
1372 return getNameSpace().checkNetwork();
1373}
1374
1375
1376bool NetworkBase::checkNetwork(double timeout)
1377{
1378 return getNameSpace().checkNetwork(timeout);
1379}
1380
1381
1383{
1384 return __yarp_is_initialized > 0;
1385}
1386
1387#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
1398#endif
1399
1401{
1402 getNameSpace().queryBypass(store);
1403}
1404
1406{
1407 return getNameSpace().getQueryBypass();
1408}
1409
1410namespace {
1411std::mutex& getNetworkMutex()
1412{
1413 static std::mutex mutex;
1414 return mutex;
1415}
1416} // namespace
1417
1419{
1420 getNetworkMutex().lock();
1421}
1422
1424{
1425 getNetworkMutex().unlock();
1426}
1427
1428
1429int NetworkBase::sendMessage(const std::string& port,
1431 bool silent)
1432{
1433 std::string output;
1434 return sendMessage(port, writable, output, silent);
1435}
1436
1437int NetworkBase::sendMessage(const std::string& port,
1439 std::string& output,
1440 bool quiet)
1441{
1442 output = "";
1444 if (!srcAddress.isValid()) {
1445 if (!quiet) {
1446 yCError(NETWORK, "Cannot find port named %s", port.c_str());
1447 }
1448 return 1;
1449 }
1451 if (out == nullptr) {
1452 if (!quiet) {
1453 yCError(NETWORK, "Cannot connect to port named %s at %s", port.c_str(), srcAddress.toURI().c_str());
1454 }
1455 return 1;
1456 }
1457 Route route("admin", port, "text");
1458
1459
1460 bool ok = out->open(route);
1461 if (!ok) {
1462 if (!quiet) {
1463 yCError(NETWORK, "Cannot make connection");
1464 }
1465 delete out;
1466 return 1;
1467 }
1468
1469 BufferedConnectionWriter bw(out->getConnection().isTextMode());
1470 PortCommand disconnect('\0', "q");
1471 bool wok = writable.write(bw);
1472 if (!wok) {
1473 if (!quiet) {
1474 yCError(NETWORK, "Cannot write on connection");
1475 }
1476 delete out;
1477 return 1;
1478 }
1479 if (!disconnect.write(bw)) {
1480 if (!quiet) {
1481 yCError(NETWORK, "Cannot write on connection");
1482 }
1483 delete out;
1484 return 1;
1485 }
1486
1487 out->write(bw);
1488 InputProtocol& ip = out->getInput();
1489 ConnectionReader& con = ip.beginRead();
1490 Bottle b;
1491 b.read(con);
1492 b.read(con);
1493 output = b.toString();
1494 if (!quiet) {
1495 yCInfo(NETWORK, "%s", b.toString().c_str());
1496 }
1497 ip.endRead();
1498 out->close();
1499 delete out;
1500 out = nullptr;
1501
1502 return 0;
1503}
1504
1505int NetworkBase::poll(const std::string& target, bool silent)
1506{
1507 PortCommand pc('\0', "*");
1508 return sendMessage(target, pc, silent);
1509}
1510
1511int NetworkBase::disconnectInput(const std::string& src,
1512 const std::string& dest,
1513 bool silent)
1514{
1515 PortCommand pc('\0', std::string("~") + dest);
1516 return sendMessage(src, pc, silent);
1517}
1518
1520{
1521public:
1525
1527 {
1528 owner = nullptr;
1529 factory = nullptr;
1530 }
1531
1533 Carrier* owner) :
1534 factory(factory),
1535 owner(owner)
1536 {
1537 factory->addRef();
1538 car.open(*factory);
1539 }
1540
1542 {
1543 car.close();
1544 if (factory == nullptr) {
1545 return;
1546 }
1547 factory->removeRef();
1548 if (factory->getReferenceCount() <= 0) {
1549 delete factory;
1550 }
1551 factory = nullptr;
1552 }
1553
1555 {
1556 return car.getContent();
1557 }
1558
1559 virtual const Carrier& getContent() const
1560 {
1561 return car.getContent();
1562 }
1563
1564 Carrier* create() const override
1565 {
1566 return owner->create();
1567 }
1568
1569
1570 // Forward yarp::os::Connection methods
1571
1572 bool isValid() const override
1573 {
1574 return car.isValid();
1575 }
1576
1577 bool isTextMode() const override
1578 {
1579 return getContent().isTextMode();
1580 }
1581
1582 bool isBareMode() const override
1583 {
1584 return getContent().isBareMode();
1585 }
1586
1587 bool canEscape() const override
1588 {
1589 return getContent().canEscape();
1590 }
1591
1592 void handleEnvelope(const std::string& envelope) override
1593 {
1594 getContent().handleEnvelope(envelope);
1595 }
1596
1597 bool requireAck() const override
1598 {
1599 return getContent().requireAck();
1600 }
1601
1602 bool supportReply() const override
1603 {
1604 return getContent().supportReply();
1605 }
1606
1607 bool isLocal() const override
1608 {
1609 return getContent().isLocal();
1610 }
1611
1612 bool isPush() const override
1613 {
1614 return getContent().isPush();
1615 }
1616
1617 bool isConnectionless() const override
1618 {
1619 return getContent().isConnectionless();
1620 }
1621
1622 bool isBroadcast() const override
1623 {
1624 return getContent().isBroadcast();
1625 }
1626
1627 bool isActive() const override
1628 {
1629 return getContent().isActive();
1630 }
1631
1632 bool modifiesIncomingData() const override
1633 {
1634 return getContent().modifiesIncomingData();
1635 }
1636
1638 {
1639 return getContent().modifyIncomingData(reader);
1640 }
1641
1643 {
1644 return getContent().acceptIncomingData(reader);
1645 }
1646
1647 bool modifiesOutgoingData() const override
1648 {
1649 return getContent().modifiesOutgoingData();
1650 }
1651
1652 const PortWriter& modifyOutgoingData(const PortWriter& writer) override
1653 {
1654 return getContent().modifyOutgoingData(writer);
1655 }
1656
1657 bool acceptOutgoingData(const PortWriter& writer) override
1658 {
1659 return getContent().acceptOutgoingData(writer);
1660 }
1661
1662 bool modifiesReply() const override
1663 {
1664 return getContent().modifiesReply();
1665 }
1666
1668 {
1669 return getContent().modifyReply(reader);
1670 }
1671
1672 void setCarrierParams(const Property& params) override
1673 {
1674 getContent().setCarrierParams(params);
1675 }
1676
1677 void getCarrierParams(Property& params) const override
1678 {
1679 getContent().getCarrierParams(params);
1680 }
1681
1682 void getHeader(yarp::os::Bytes& header) const override
1683 {
1684 getContent().getHeader(header);
1685 }
1686
1687 void prepareDisconnect() override
1688 {
1689 getContent().prepareDisconnect();
1690 }
1691
1692 std::string getName() const override
1693 {
1694 return getContent().getName();
1695 }
1696
1697
1698 // Forward yarp::os::Carrier methods
1699
1700 bool checkHeader(const yarp::os::Bytes& header) override
1701 {
1702 return getContent().checkHeader(header);
1703 }
1704
1705 void setParameters(const yarp::os::Bytes& header) override
1706 {
1707 getContent().setParameters(header);
1708 }
1709
1710 bool canAccept() const override
1711 {
1712 return getContent().canAccept();
1713 }
1714
1715 bool canOffer() const override
1716 {
1717 return getContent().canOffer();
1718 }
1719
1720 bool prepareSend(ConnectionState& proto) override
1721 {
1722 return getContent().prepareSend(proto);
1723 }
1724
1725 bool sendHeader(ConnectionState& proto) override
1726 {
1727 return getContent().sendHeader(proto);
1728 }
1729
1731 {
1732 return getContent().expectReplyToHeader(proto);
1733 }
1734
1735 bool write(ConnectionState& proto, SizedWriter& writer) override
1736 {
1737 return getContent().write(proto, writer);
1738 }
1739
1740 bool reply(ConnectionState& proto, SizedWriter& writer) override
1741 {
1742 return getContent().reply(proto, writer);
1743 }
1744
1746 {
1747 return getContent().expectExtraHeader(proto);
1748 }
1749
1750 bool respondToHeader(ConnectionState& proto) override
1751 {
1752 return getContent().respondToHeader(proto);
1753 }
1754
1755 bool expectIndex(ConnectionState& proto) override
1756 {
1757 return getContent().expectIndex(proto);
1758 }
1759
1761 {
1762 return getContent().expectSenderSpecifier(proto);
1763 }
1764
1765 bool sendAck(ConnectionState& proto) override
1766 {
1767 return getContent().sendAck(proto);
1768 }
1769
1770 bool expectAck(ConnectionState& proto) override
1771 {
1772 return getContent().expectAck(proto);
1773 }
1774
1775 std::string toString() const override
1776 {
1777 return getContent().toString();
1778 }
1779
1780 void close() override
1781 {
1782 getContent().close();
1783 }
1784
1785 std::string getBootstrapCarrierName() const override
1786 {
1787 return getContent().getBootstrapCarrierName();
1788 }
1789
1791 const yarp::os::Contact& dest,
1792 const yarp::os::ContactStyle& style,
1793 int mode,
1794 bool reversed) override
1795 {
1796 return getContent().connect(src, dest, style, mode, reversed);
1797 }
1798
1799 bool configure(ConnectionState& proto) override
1800 {
1801 return getContent().configure(proto);
1802 }
1804 {
1805 return getContent().configureFromProperty(options);
1806 }
1807
1808 yarp::os::Face* createFace() const override
1809 {
1810 return getContent().createFace();
1811 }
1812};
1813
1814
1816{
1817private:
1818 YarpPluginSettings settings;
1819 YarpPlugin<Carrier> plugin;
1820
1821public:
1822 StubCarrier(const char* dll_name, const char* fn_name)
1823 {
1824 settings.setLibraryMethodName(dll_name, fn_name);
1825 init();
1826 }
1827
1828 StubCarrier(const char* name)
1829 {
1830 settings.setPluginName(name);
1831 init();
1832 }
1833
1834 void init()
1835 {
1836 YarpPluginSelector selector;
1837 selector.scan();
1838 settings.setSelector(selector);
1839 if (plugin.open(settings)) {
1840 car.open(*plugin.getFactory());
1841 settings.setLibraryMethodName(plugin.getFactory()->getName(),
1842 settings.getMethodName());
1843 }
1844 }
1845
1847 {
1848 return car.getContent();
1849 }
1850
1851 const Carrier& getContent() const override
1852 {
1853 return car.getContent();
1854 }
1855
1856 Carrier* create() const override
1857 {
1858 auto* ncar = new ForwardingCarrier(plugin.getFactory(), const_cast<StubCarrier*>(this));
1859 if (ncar == nullptr) {
1860 return nullptr;
1861 }
1862 if (!ncar->isValid()) {
1863 delete ncar;
1864 ncar = nullptr;
1865 return nullptr;
1866 }
1867 return ncar;
1868 }
1869
1870 std::string getDllName() const
1871 {
1872 return settings.getLibraryName();
1873 }
1874
1875 std::string getFnName() const
1876 {
1877 return settings.getMethodName();
1878 }
1879};
1880
1881
1882bool NetworkBase::registerCarrier(const char* name, const char* dll)
1883{
1884 StubCarrier* factory = nullptr;
1885 if (dll == nullptr) {
1886 factory = new StubCarrier(name);
1887 if (factory == nullptr) {
1888 return false;
1889 }
1890 } else {
1891 factory = new StubCarrier(dll, name);
1892 }
1893 if (factory == nullptr) {
1894 yCError(NETWORK, "Failed to register carrier");
1895 return false;
1896 }
1897 if (!factory->isValid()) {
1898 if (dll != nullptr) {
1899 yCError(NETWORK, "Failed to find library %s with carrier %s", dll, name);
1900 } else {
1901 yCError(NETWORK, "Failed to find library support for carrier %s", name);
1902 }
1903 delete factory;
1904 factory = nullptr;
1905 return false;
1906 }
1908 return true;
1909}
1910
1911
1913{
1914 bool globalAlloc = getNameSpace().serverAllocatesPortNumbers();
1915 return !globalAlloc;
1916}
1917
1918
1920 bool& scanNeeded,
1921 bool& serverUsed)
1922{
1923 return getNameSpace().detectNameServer(useDetectedServer,
1924 scanNeeded,
1925 serverUsed);
1926}
1927
1929{
1931 if (!nameServerContact.getName().empty()) {
1933 }
1934 nameConfig.fromFile();
1935 nameConfig.setAddress(nameServerContact);
1936 bool result = nameConfig.toFile();
1937 getNameSpace().activate(true);
1938 return result;
1939}
1940
1941
1943 PortReader& reply,
1944 const ContactStyle& style)
1945{
1946 NameStore* store = getNameSpace().getQueryBypass();
1947 if (store != nullptr) {
1948 Contact contact;
1949 return store->process(cmd, reply, contact);
1950 }
1951 return getNameSpace().writeToNameServer(cmd, reply, style);
1952}
1953
1954
1955std::string NetworkBase::getConfigFile(const char* fname)
1956{
1958}
1959
1960
1962{
1963 std::string range = yarp::conf::environment::get_string("YARP_PORT_RANGE");
1964 if (!range.empty()) {
1965 int irange = yarp::conf::numeric::from_string<int>(range);
1966 if (irange != 0) {
1967 return irange;
1968 }
1969 }
1970 return 10000;
1971}
#define YARP_ENACT_DISCONNECT
Definition Carrier.h:13
#define YARP_ENACT_EXISTS
Definition Carrier.h:14
#define YARP_ENACT_CONNECT
Definition Carrier.h:12
bool ret
#define YARP_CONFIG_NAMESPACE_FILENAME
Definition NameConfig.h:16
static int enactConnection(const Contact &src, const Contact &dest, const ContactStyle &style, int mode, bool reversed)
Definition Network.cpp:121
static bool getPortQos(const std::string &port, const std::string &unit, QosStyle &style, bool quiet)
Definition Network.cpp:1145
static MultiNameSpace & getNameSpace()
Definition Network.cpp:85
static std::string collectParams(Contact &c)
Definition Network.cpp:260
static int metaConnect(const std::string &src, const std::string &dest, ContactStyle style, int mode)
Definition Network.cpp:292
static bool needsLookup(const Contact &contact)
Definition Network.cpp:91
static int __yarp_is_initialized
Definition Network.cpp:55
static YarpAutoInit yarp_auto_init
destructor is called on shutdown.
Definition Network.cpp:83
static std::string extractCarrierNameOnly(const std::string &carrier_name_with_params)
Definition Network.cpp:270
static int noteDud(const Contact &src)
Definition Network.cpp:102
static bool __yarp_auto_init_active
Definition Network.cpp:56
bool modifiesReply() const override
Check if this carrier modifies outgoing data through the Carrier::modifyReply method.
Definition Network.cpp:1662
void getHeader(yarp::os::Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
Definition Network.cpp:1682
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition Network.cpp:1587
bool checkHeader(const yarp::os::Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
Definition Network.cpp:1700
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition Network.cpp:1692
ConnectionReader & modifyIncomingData(ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
Definition Network.cpp:1637
bool sendAck(ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
Definition Network.cpp:1765
bool isTextMode() const override
Check if carrier is textual in nature.
Definition Network.cpp:1577
bool expectAck(ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
Definition Network.cpp:1770
void prepareDisconnect() override
Do cleanup and preparation for the coming disconnect, if necessary.
Definition Network.cpp:1687
bool reply(ConnectionState &proto, SizedWriter &writer) override
Definition Network.cpp:1740
bool isBareMode() const override
Check if carrier excludes type information from payload.
Definition Network.cpp:1582
bool modifiesIncomingData() const override
Check if this carrier modifies incoming data through the Carrier::modifyIncomingData method.
Definition Network.cpp:1632
SharedLibraryClassFactory< Carrier > * factory
Definition Network.cpp:1522
void handleEnvelope(const std::string &envelope) override
Carriers that do not distinguish data from administrative headers (i.e.
Definition Network.cpp:1592
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
Definition Network.cpp:1730
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
Definition Network.cpp:1725
bool isBroadcast() const override
Check if this carrier uses a broadcast mechanism.
Definition Network.cpp:1622
bool write(ConnectionState &proto, SizedWriter &writer) override
Write a message.
Definition Network.cpp:1735
bool modifiesOutgoingData() const override
Check if this carrier modifies outgoing data through the Carrier::modifyOutgoingData method.
Definition Network.cpp:1647
const PortWriter & modifyOutgoingData(const PortWriter &writer) override
Modify outgoing payload data, if appropriate.
Definition Network.cpp:1652
SharedLibraryClass< Carrier > car
Definition Network.cpp:1523
Carrier * create() const override
Factory method.
Definition Network.cpp:1564
bool isPush() const override
Check if carrier is "push" or "pull" style.
Definition Network.cpp:1612
bool canAccept() const override
Check if reading is implemented for this carrier.
Definition Network.cpp:1710
bool configure(ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
Definition Network.cpp:1799
PortReader & modifyReply(PortReader &reader) override
Modify reply payload data, if appropriate.
Definition Network.cpp:1667
bool configureFromProperty(yarp::os::Property &options) override
Definition Network.cpp:1803
bool isLocal() const override
Check if carrier operates within a single process.
Definition Network.cpp:1607
bool acceptIncomingData(ConnectionReader &reader) override
Determine whether incoming data should be accepted.
Definition Network.cpp:1642
virtual const Carrier & getContent() const
Definition Network.cpp:1559
virtual Carrier & getContent()
Definition Network.cpp:1554
ForwardingCarrier(SharedLibraryClassFactory< Carrier > *factory, Carrier *owner)
Definition Network.cpp:1532
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
Definition Network.cpp:1602
std::string toString() const override
Get name of carrier.
Definition Network.cpp:1775
bool canOffer() const override
Check if writing is implemented for this carrier.
Definition Network.cpp:1715
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition Network.cpp:1617
bool prepareSend(ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
Definition Network.cpp:1720
std::string getBootstrapCarrierName() const override
Get the name of the carrier that should be used prior to handshaking, if a port is registered with th...
Definition Network.cpp:1785
void setCarrierParams(const Property &params) override
Configure carrier from port administrative commands.
Definition Network.cpp:1672
~ForwardingCarrier() override
Definition Network.cpp:1541
bool isValid() const override
Check if this object is really a connection, or just an empty placeholder.
Definition Network.cpp:1572
int connect(const yarp::os::Contact &src, const yarp::os::Contact &dest, const yarp::os::ContactStyle &style, int mode, bool reversed) override
Some carrier types may require special connection logic.
Definition Network.cpp:1790
bool acceptOutgoingData(const PortWriter &writer) override
Determine whether outgoing data should be accepted.
Definition Network.cpp:1657
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
Definition Network.cpp:1745
yarp::os::Face * createFace() const override
Create new Face object that the carrier needs.
Definition Network.cpp:1808
bool respondToHeader(ConnectionState &proto) override
Respond to the header.
Definition Network.cpp:1750
bool expectIndex(ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
Definition Network.cpp:1755
bool isActive() const override
Check if carrier is alive and error free.
Definition Network.cpp:1627
void close() override
Close the carrier.
Definition Network.cpp:1780
bool expectSenderSpecifier(ConnectionState &proto) override
Expect the name of the sending port.
Definition Network.cpp:1760
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
Definition Network.cpp:1705
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
Definition Network.cpp:1597
void getCarrierParams(Property &params) const override
Get carrier configuration and deliver it by port administrative commands.
Definition Network.cpp:1677
std::string getDllName() const
Definition Network.cpp:1870
void init()
Definition Network.cpp:1834
StubCarrier(const char *dll_name, const char *fn_name)
Definition Network.cpp:1822
std::string getFnName() const
Definition Network.cpp:1875
Carrier * create() const override
Factory method.
Definition Network.cpp:1856
StubCarrier(const char *name)
Definition Network.cpp:1828
const Carrier & getContent() const override
Definition Network.cpp:1851
Carrier & getContent() override
Definition Network.cpp:1846
A single-use class to shut down the yarp library if it was initialized automatically.
Definition Network.cpp:64
~YarpAutoInit()
Shut down the yarp library if it was automatically initialized.
Definition Network.cpp:75
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
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
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
Definition Bottle.cpp:293
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:277
void clear()
Empties the bottle of any objects it contains.
Definition Bottle.cpp:121
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition Bottle.cpp:140
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
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition Bottle.cpp:287
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition Carrier.h:44
virtual Carrier * create() const =0
Factory method.
static bool addCarrierPrototype(Carrier *carrier)
Add a new connection type.
Definition Carriers.cpp:303
static Carrier * chooseCarrier(const std::string &name)
Select a carrier by name.
Definition Carriers.cpp:233
static OutputProtocol * connect(const Contact &address)
Initiate a connection to an address.
Definition Carriers.cpp:282
An interface for reading from a network connection.
The basic state of a connection - route, streams in use, etc.
Preferences for how to communicate with a contact.
double timeout
Set a timeout for communication (in units of seconds, fractional seconds allowed).
bool quiet
Suppress all outputs and warnings.
std::string carrier
Request that communication be made using a particular carrier.
bool verboseOnSuccess
Allow output on success.
bool expectReply
Specify whether you expect a reply to a message.
bool admin
Ask recipient to treat message as administrative.
bool persistent
Specify whether a requested connection should be persistent.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
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
void setTimeout(float timeout)
Set timeout for this Contact.
Definition Contact.cpp:282
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
The initial point-of-contact with a port.
Definition Face.h:20
The input side of an active connection between two ports.
virtual void endRead()=0
End the current read operation, begin by beginRead().
virtual ConnectionReader & beginRead()=0
Begin a read operation, with bytes read via the returned yarp::os::ConnectionReader object.
@ DebugType
Definition Log.h:93
@ WarningType
Definition Log.h:95
static void setMinimumForwardLevel(LogType level)
Set current minimum forward level (it does nothing if forwarding is not enabled)
Definition Log.cpp:846
static void setMinimumPrintLevel(LogType level)
Set current minimum print level.
Definition Log.cpp:828
An abstract name space for ports.
Definition NameSpace.h:22
virtual bool disconnectTopicFromPort(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Stop subscribing a port to a topic.
virtual bool localOnly() const =0
Check if the NameSpace is only valid for the current process ("local").
virtual bool disconnectPortFromTopic(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Stop publishing a port to a topic.
virtual bool connectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Connect two ports with persistence.
virtual bool connectTopicToPort(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Subscribe a port to a topic.
virtual bool connectPortToTopic(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Publish a port to a topic.
virtual bool disconnectPortToPortPersistently(const Contact &src, const Contact &dest, const ContactStyle &style)=0
Disconnect two ports, removing any persistence.
Abstract interface for a database of port names.
Definition NameStore.h:19
virtual bool announce(const std::string &name, int activity)=0
virtual bool process(PortWriter &in, PortReader &out, const Contact &source)=0
static bool initialized()
Returns true if YARP has been fully initialized.
Definition Network.cpp:1382
static std::string getNameServerName()
Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten...
Definition Network.cpp:1345
static bool isNetworkInitialized()
Definition Network.cpp:876
static bool getLocalMode()
Get current value of flag "localMode", see setLocalMode function.
Definition Network.cpp:1054
static Contact getNameServerContact()
Get the contact information for the port associated with the nameserver (usually "/root",...
Definition Network.cpp:1353
static bool sync(const std::string &port, bool quiet=true)
Wait for a port to be ready and responsive.
Definition Network.cpp:847
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 void queryBypass(NameStore *store)
Redirect queries to another source.
Definition Network.cpp:1400
static void yarpClockInit(yarp::os::yarpClockType clockType, Clock *custom=nullptr)
This function specifically initialize the clock In case clockType is one of the valid cases: YARP_CLO...
Definition Network.cpp:958
static void unlock()
Call post() on a global mutual-exclusion semaphore allocated by YARP.
Definition Network.cpp:1423
static bool registerCarrier(const char *name, const char *dll)
Register a carrier to make available at runtime.
Definition Network.cpp:1882
static Contact unregisterName(const std::string &name)
Removes the registration for a name from the name server.
Definition Network.cpp:1023
static NameStore * getQueryBypass()
Definition Network.cpp:1405
static Contact unregisterContact(const Contact &contact)
Removes the registration for a contact from the name server.
Definition Network.cpp:1029
static bool waitPort(const std::string &target, bool quiet=false)
Delays the system until a specified port is open.
Definition Network.cpp:825
static bool setNameServerName(const std::string &name)
Set the name of the port associated with the nameserver (usually "/root", but this can be overwritten...
Definition Network.cpp:1359
static bool getConnectionQos(const std::string &src, const std::string &dest, QosStyle &srcStyle, QosStyle &destStyle, bool quiet=true)
Gets the Qos preferences of a connection.
Definition Network.cpp:1182
static Contact registerContact(const Contact &contact)
Register contact information with the name server.
Definition Network.cpp:1017
static bool setNameServerContact(Contact &nameServerContact)
Set explicitly the nameserver information.
Definition Network.cpp:1928
static int poll(const std::string &target, bool silent=false)
Sends a 'describe yourself' message to a specified port, in order to receive information about the po...
Definition Network.cpp:1505
static Contact queryName(const std::string &name)
Find out information about a registered name.
Definition Network.cpp:995
static bool exists(const std::string &port, bool quiet=true, bool checkVer=true)
Check for a port to be ready and responsive.
Definition Network.cpp:746
static void setVerbosity(int verbosity)
Set level of verbosity of YARP messages.
Definition Network.cpp:1388
static void initMinimum()
Basic system initialization, not including plugins.
Definition Network.cpp:871
static int sendMessage(const std::string &port, yarp::os::PortWriter &writable, bool silent=false)
Just a reminder to sendMessage with temporary output parameter that will be discarded.
Definition Network.cpp:1429
static void autoInitMinimum()
Basic system initialization, not including plugins.
Definition Network.cpp:857
static void finiMinimum()
Deinitialization, excluding plugins.
Definition Network.cpp:939
static Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed)
Scan for an available name server.
Definition Network.cpp:1919
static bool setProperty(const char *name, const char *key, const Value &value)
Names registered with the nameserver can have arbitrary key->value properties associated with them.
Definition Network.cpp:1035
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:1961
static void lock()
Call wait() on a global mutual-exclusion semaphore allocated by YARP.
Definition Network.cpp:1418
static std::string getConfigFile(const char *fname)
Search for a configuration file in YARP's standard config file path.
Definition Network.cpp:1955
static Contact registerName(const std::string &name)
Register a name with the name server.
Definition Network.cpp:1010
static int disconnectInput(const std::string &src, const std::string &dest, bool silent=false)
Sends a disconnection command to the specified port.
Definition Network.cpp:1511
static bool waitConnection(const std::string &source, const std::string &destination, bool quiet=false)
Delays the system until a specified connection is established.
Definition Network.cpp:803
static void assertion(bool shouldBeTrue)
An assertion.
Definition Network.cpp:1060
static bool checkNetwork()
Check if the YARP Network is up and running.
Definition Network.cpp:1370
static bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style)
Variant write method specialized to name server.
Definition Network.cpp:1942
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 localNetworkAllocation()
Check where the name server in use expects processes to allocate their own network resources.
Definition Network.cpp:1912
static Value * getProperty(const char *name, const char *key)
Look up the value associated with a particular key for a named entry registered with the nameserver.
Definition Network.cpp:1043
static bool isValidPortName(const std::string &portName)
Checks that the port has a valid name.
Definition Network.cpp:1193
static bool setConnectionQos(const std::string &src, const std::string &dest, const QosStyle &srcStyle, const QosStyle &destStyle, bool quiet=true)
Adjust the Qos preferences of a connection.
Definition Network.cpp:1072
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:1219
static bool isConnected(const std::string &src, const std::string &dest, bool quiet)
Check if a connection with tcp carrier exists between two ports.
Definition Network.cpp:727
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1049
The output side of an active connection between two ports.
virtual Connection & getConnection()=0
Get the connection whose protocol operations we are managing.
virtual bool open(const Route &route)=0
Start negotiating a carrier, using the given route (this should generally match the name of the sendi...
virtual InputProtocol & getInput()=0
Get an interface for doing read operations on the connection.
virtual void close()=0
Negotiate an end to operations.
virtual bool setTimeout(double timeout)=0
Set the timeout to be used for network operations.
virtual bool write(SizedWriter &writer)=0
Write a message on the connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition PortWriter.h:23
virtual bool write(ConnectionWriter &writer) const =0
Write this object to a network connection.
A mini-server for network communication.
Definition Port.h:46
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:436
void setAdminMode(bool adminMode=true)
Turn on/off "admin" mode.
Definition Port.cpp:595
bool addOutput(const std::string &name) override
Add an output connection to the specified port.
Definition Port.cpp:353
bool openFake(const std::string &name)
Start port without making it accessible from the network.
Definition Port.cpp:74
A class for storing options and configuration information.
Definition Property.h:33
Preferences for the port's Quality of Service.
Definition QosStyle.h:23
void setThreadPriority(int priority)
sets the communication thread priority level
Definition QosStyle.h:127
void setPacketPrioritybyTOS(int tos)
sets the packet priority given as TOS value
Definition QosStyle.h:97
void setThreadPolicy(int policy)
sets the communication thread scheduling policy
Definition QosStyle.h:137
Information about a connection between two ports.
Definition Route.h:28
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
static void delaySystem(double seconds)
A single value (typically within a Bottle).
Definition Value.h:43
virtual bool asBool() const
Get boolean value.
Definition Value.cpp:186
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
virtual bool isInt32() const
Checks if value is a 32-bit integer.
Definition Value.cpp:132
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
Pick out a set of relevant plugins.
void scan()
Find plugin configuration files, and run [plugin] sections through the select method.
Collect hints for finding a particular plugin.
bool setSelector(YarpPluginSelector &selector)
Use a selector to find a plugin or plugins.
void setLibraryMethodName(const std::string &dll_name, const std::string &fn_name)
Set the name of the library to load and the method name to use as a factory.
void setPluginName(const std::string &name)
Set the name of the plugin to load.
A helper for creating cached object descriptions.
Small helper class to help deal with legacy YARP configuration files.
Definition NameConfig.h:23
std::string getNamespace(bool refresh=false)
static std::string expandFilename(const char *fname)
bool writeConfig(const std::string &fileName, const std::string &text)
std::string getConfigFileName(const char *stem=nullptr, const char *ns=nullptr)
Simple Readable and Writable object representing a command to a YARP port.
Definition PortCommand.h:24
#define yCInfo(component,...)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define yCFatal(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
Definition environment.h:66
std::int32_t vocab32_t
Definition numeric.h:78
yarpClockType getClockType()
Definition Time.cpp:270
void useSystemClock()
Configure YARP to use system time (this is the default).
Definition Time.cpp:137
bool isClockInitialized()
Check if YARP clock is initialized.
Definition Time.cpp:250
void useNetworkClock(const std::string &clock, const std::string &localPortName="")
Configure YARP to read time from a specified topic.
Definition Time.cpp:177
void useCustomClock(Clock *clock)
Configure YARP clients to use a custom clock source provided by the user.
Definition Time.cpp:220
void startTurboBoost()
For OS where it makes sense sets the scheduler to be called more often.
Definition Time.cpp:91
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
yarpClockType
Definition Time.h:25
@ YARP_CLOCK_UNINITIALIZED
Definition Time.h:26
@ YARP_CLOCK_CUSTOM
Definition Time.h:30
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
@ YARP_CLOCK_NETWORK
Definition Time.h:29
@ YARP_CLOCK_DEFAULT
Definition Time.h:27
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition Vocab.h:27
#define YARP_UNUSED(var)
Definition api.h:162