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>
23
35
36#ifdef YARP_HAS_ACE
37# include <ace/Init_ACE.h>
38# include <ace/config.h>
39// In one the ACE headers there is a definition of "main" for WIN32
40# ifdef main
41# undef main
42# endif
43#endif
44
45#include <cstdio>
46#include <cstdlib>
47#include <mutex>
48#include <string>
49
50using namespace yarp::os::impl;
51using namespace yarp::os;
52
53namespace {
54YARP_OS_LOG_COMPONENT(NETWORK, "yarp.os.Network")
55}
56
57static int __yarp_is_initialized = 0;
58static bool __yarp_auto_init_active = false; // was yarp auto-initialized?
59
60
66{
67public:
84};
86
92
93static bool needsLookup(const Contact& contact)
94{
95 if (!contact.getHost().empty()) {
96 return false;
97 }
98 if (contact.getCarrier() == "topic") {
99 return false;
100 }
101 return true;
102}
103
116static int noteDud(const Contact& src)
117{
118 NameStore* store = getNameSpace().getQueryBypass();
119 if (store != nullptr) {
120 return store->announce(src.getName(), 0);
121 }
122 Bottle cmd;
123 Bottle reply;
124 cmd.addString("announce");
125 cmd.addString(src.getName().c_str());
126 cmd.addInt32(0);
127 ContactStyle style;
128 bool ok = NetworkBase::writeToNameServer(cmd,
129 reply,
130 style);
131 return ok ? 0 : 1;
132}
133
134
161static int enactConnection(const Contact& src,
162 const Contact& dest,
163 const ContactStyle& style,
164 int mode,
165 bool reversed)
166{
168 rpc.admin = true;
169 rpc.quiet = style.quiet;
170 rpc.timeout = style.timeout;
171
173 "enactConnection: SRC %s DST %s using carrier %s, MODE=%d, rev=%d",
174 src.getName().c_str(),
175 dest.getName().c_str(),
176 style.carrier.c_str(),
177 mode,
178 reversed);
179
180 if (style.persistent) {
181 bool ok = false;
182 // we don't talk to the ports, we talk to the nameserver
183 NameSpace& ns = getNameSpace();
184 if (mode == YARP_ENACT_CONNECT) {
185 ok = ns.connectPortToPortPersistently(src, dest, style);
186 } else if (mode == YARP_ENACT_DISCONNECT) {
187 ok = ns.disconnectPortToPortPersistently(src, dest, style);
188 } else {
189 yCError(NETWORK, "Failure: cannot check subscriptions yet");
190 return 1;
191 }
192 if (!ok) {
193 return 1;
194 }
195 if (!style.quiet) {
196 yCInfo(NETWORK, "Success: port-to-port persistent connection added.");
197 }
198 return 0;
199 }
200
201 PortCoreClient client(src, rpc);
202 const return_getConnectionInfo info = reversed ? client.getConnectionInfoIn(dest.getName())
203 : client.getConnectionInfoOut(dest.getName());
204 if (!info.ret) {
205 noteDud(src);
206 return 1;
207 }
208 if (info.found) {
209 if (!style.quiet) {
211 "Connection found between %s and %s using carrier %s",
212 src.getName().c_str(),
213 dest.getName().c_str(),
214 info.carrier.c_str());
215 }
216 if (mode == YARP_ENACT_EXISTS) {
217 return (info.carrier == style.carrier) ? 0 : 1;
218 }
219
220 // This is either a connect or a disconnect command, but the current
221 // connection is connectionless, the other side will not know that we
222 // are closing the connection and therefore will continue sending data.
223 // Therefore we send an explicit disconnect here.
224 if (info.connectionless && ((reversed && info.push) || (!reversed && !info.push))) {
225 enactConnection(dest, src, style, YARP_ENACT_DISCONNECT, !reversed);
226 }
227 }
228 if (mode == YARP_ENACT_EXISTS) {
229 return 1;
230 }
231
232 // Let's ask the destination to connect/disconnect to the source.
233 // We assume the YARP carrier will reverse the connection if
234 // appropriate when connecting.
235 Contact c = dest;
236 if (!style.carrier.empty()) {
237 c.setCarrier(style.carrier);
238 }
239
240 Contact c2 = src;
241 if (c2.getPort() <= 0) {
243 }
244
246 bool ret = false;
247 bool ok = false;
248 std::string msg;
250 const return_delConnection result = srcClient.delConnection(c.getName());
251 ret = result.ret;
252 ok = result.success;
253 msg = result.message;
254 } else {
255 const return_addConnection result = srcClient.addConnection(c.toString());
256 ret = result.ret;
257 ok = result.success;
258 msg = result.message;
259 }
260 if (!ret) {
261 noteDud(src);
262 return 1;
263 }
264 if (mode == YARP_ENACT_DISCONNECT && !ok) {
265 msg = "no such connection";
266 }
267 if (mode == YARP_ENACT_CONNECT && !ok) {
268 noteDud(dest);
269 }
270 if (!style.quiet) {
271 if (!ok) {
272 yCError(NETWORK, "%s %s", "Failure:", msg.c_str());
273 } else if (style.verboseOnSuccess) {
274 yCInfo(NETWORK, "%s %s", "Success:", msg.c_str());
275 }
276 }
277 return ok ? 0 : 1;
278}
279
280static std::string collectParams(Contact& c)
281{
282 std::string carrier_name = c.getCarrier();
283 auto pos = carrier_name.find('+');
284 if (pos != std::string::npos) {
285 return carrier_name.substr(pos);
286 }
287 return {};
288}
289
290static std::string extractCarrierNameOnly(const std::string& carrier_name_with_params)
291{
292 return carrier_name_with_params.substr(0, carrier_name_with_params.find('+'));
293}
294
303static bool is_log_port(const std::string& src,
304 const std::string& dest)
305{
306 if (src.find ("/log") != std::string::npos &&
307 dest.find("/log") != std::string::npos &&
308 src.find ("/logger") != std::string::npos &&
309 dest.find("/logger") != std::string::npos)
310 {
311 return true;
312 }
313 return false;
314}
315
324static bool is_stats_port(const std::string& src,
325 const std::string& dest)
326{
327 if (src.find ("/stats_monitor") != std::string::npos &&
328 dest.find("/stats_monitor") != std::string::npos &&
329 src.find ("/yarpConnectionsStats") != std::string::npos &&
330 dest.find("/yarpConnectionsStats") != std::string::npos)
331 {
332 return true;
333 }
334 return false;
335}
336
337static void addStatsMonitorIfNeeded(const std::string& src,
338 const std::string& dest,
339 ContactStyle& style,
340 int mode)
341{
342 // If YARP_CONNECTIONS_STATS_ENABLE is set in the environment, automatically
343 // inject the stats_monitor portmonitor into the carrier string for every new connection
344 if (mode == YARP_ENACT_CONNECT && !style.carrier.empty())
345 {
346 std::string statsEnabled;
347 bool statsEnabledFound = false;
348 statsEnabled = yarp::conf::environment::get_string("YARP_CONNECTIONS_STATS_ENABLE", &statsEnabledFound);
349 if (statsEnabledFound && statsEnabled == "1")
350 {
351 //The stats and the log ports must be skipped
352 if (!is_log_port(src,dest) && !is_stats_port(src,dest))
353 {
354 //bool stat_portmonitor_is_available = true;
357 {
358 //If the connection already uses a portmonitor, we need to concatenate the stats_monitor to the existing portmonitor.
359 if (style.carrier.find("portmonitor") != std::string::npos)
360 {
361 // Find the next available numeric suffix for file/type parameters.
362 // "file." (no suffix) is treated as the base entry already present;
363 // we scan "file1.", "file2.", ... and take the first missing index.
364 int idx = 1;
365 while (style.carrier.find("file" + std::to_string(idx) + ".") != std::string::npos) {
366 ++idx;
367 }
368 const std::string suffix = std::to_string(idx);
369 style.carrier += "+file" + suffix + ".stats_monitor+type" + suffix + ".dll";
370 }
371 // otherwise, we inject the stats_monitor portmonitor into the carrier string
372 else
373 {
374 style.carrier += "+send.portmonitor+file.stats_monitor+type.dll";
375 }
376 }
377 else
378 {
379 yCWarning(NETWORK, "Failure: stats_monitor not available. Using default connection.");
380 }
381 }
382 }
383 }
384}
385
386/*
387 Connect two ports, bearing in mind that one of them may not be
388 a regular YARP port.
389
390 Normally, YARP sends a request to the source port asking it to
391 connect to the destination port. But the source port may not
392 be capable of initiating connections, in which case we can
393 request the destination port to connect to the source (this
394 is appropriate for carriers that can reverse the initiative).
395
396 The source or destination could also be topic ports, which are
397 entirely virtual. In that case, we just need to tell the name
398 server, and it will take care of the details.
399*/
400static int metaConnect(const std::string& src,
401 const std::string& dest,
402 ContactStyle style,
403 int mode)
404{
406 "working on connection %s to %s (%s)",
407 src.c_str(),
408 dest.c_str(),
409 (mode == YARP_ENACT_CONNECT) ? "connect" : ((mode == YARP_ENACT_DISCONNECT) ? "disconnect" : "check"));
410 // check if source name and destination name contain spaces
411 if (dest.find(' ') != std::string::npos || src.find(' ') != std::string::npos) {
413 "Failure: no way to make connection %s->%s, one of the port names contains a space character.",
414 src.c_str(),
415 dest.c_str());
416 return 1;
417 }
418
420 "METACONNECT: src=%s dest=%s style=%s",
421 src.c_str(),
422 dest.c_str(),
423 style.carrier.c_str());
424
425 // get the expressed contacts, without name server input
428
430 "DYNAMIC_SRC: name=%s, carrier=%s",
431 dynamicSrc.getName().c_str(),
432 dynamicSrc.getCarrier().c_str());
434 "DYNAMIC_DST: name=%s, carrier=%s",
435 dynamicDest.getName().c_str(),
436 dynamicDest.getCarrier().c_str());
437
440 "Failure: no way to make connection, invalid source '%s'",
441 dynamicSrc.getName().c_str());
442 return 1;
443 }
446 "Failure: no way to make connection, invalid destination '%s'",
447 dynamicDest.getName().c_str());
448 return 1;
449 }
450
451 bool topical = style.persistent;
452 if (dynamicSrc.getCarrier() == "topic" || dynamicDest.getCarrier() == "topic") {
453 topical = true;
454 }
455
456 bool topicalNeedsLookup = !getNameSpace().connectionHasNameOfEndpoints();
457
458 // fetch completed contacts from name server, if needed
463 if (!staticSrc.isValid()) {
464 if (!style.persistent) {
465 if (!style.quiet) {
467 "Failure: could not find source port %s",
468 src.c_str());
469 }
470 return 1;
471 }
473 }
474 } else {
476 }
477 if (staticSrc.getCarrier().empty()) {
478 staticSrc.setCarrier("tcp");
479 }
480 if (staticDest.getCarrier().empty()) {
481 staticDest.setCarrier("tcp");
482 }
483
486 if (!staticDest.isValid()) {
487 if (!style.persistent) {
488 if (!style.quiet) {
490 "Failure: could not find destination port %s",
491 dest.c_str());
492 }
493 return 1;
494 }
496 }
497 } else {
499 }
500
502 "STATIC_SRC: name=%s, carrier=%s",
503 staticSrc.getName().c_str(),
504 staticSrc.getCarrier().c_str());
506 "STATIC_DST: name=%s, carrier=%s",
507 staticDest.getName().c_str(),
508 staticDest.getCarrier().c_str());
509
510 //DynamicSrc and DynamicDst are the contacts created by connect command
511 //while staticSrc and staticDest are contacts created by querying the server
512 std::string carrierConstraint;
513
514 // see if we can do business with the source port
515 bool srcIsCompetent = false;
516 bool srcIsTopic = false;
517 if (staticSrc.getCarrier() != "topic") {
518 if (!topical) {
519 Carrier* srcCarrier = nullptr;
521 "staticSrc.getCarrier = %s",
522 staticSrc.getCarrier().c_str());
523 if (!staticSrc.getCarrier().empty()) {
525 }
526 if (srcCarrier != nullptr) {
528 "srcCarrier is NOT null; its name is %s",
529 srcCarrier->getName().c_str());
530 std::string srcBootstrap = srcCarrier->getBootstrapCarrierName();
531 if (!srcBootstrap.empty()) {
532
534 "it is competent (bootstrapname is %s), while its name is %s",
535 srcBootstrap.c_str(),
536 srcCarrier->getName().c_str());
537 srcIsCompetent = true;
538 } else {
539 //if the srcCarrier is not competent, (that is it can't perform the starting yarp handshaking)
540 //set the carrier constraint equal to the carrier with which the posrt had been registered.
541 carrierConstraint = staticSrc.getCarrier();
543 "it is NOT competent. its constraint is %s",
544 carrierConstraint.c_str());
545 }
546 delete srcCarrier;
547 srcCarrier = nullptr;
548 }
549 }
550 } else {
551 srcIsTopic = true;
552 }
553
554 // see if we can do business with the destination port
555 bool destIsCompetent = false;
556 bool destIsTopic = false;
557 if (staticDest.getCarrier() != "topic") {
558 if (!topical) {
559 Carrier* destCarrier = nullptr;
561 "staticDest.getCarrier = %s",
562 staticDest.getCarrier().c_str());
563 if (!staticDest.getCarrier().empty()) {
565 }
566 if (destCarrier != nullptr) {
568 "destCarrier is NOT null; its name is %s",
569 destCarrier->getName().c_str());
570 std::string destBootstrap = destCarrier->getBootstrapCarrierName();
571 if (!destBootstrap.empty()) {
573 "it is competent (bootstrapname is %s), while its name is %s",
574 destBootstrap.c_str(),
575 destCarrier->getName().c_str());
576 destIsCompetent = true;
577 } else {
578 //if the destCarrier is not competent, (that is it can't perform the starting yarp handshaking)
579 //set the carrier constraint equal to the carrier with which the posrt had been registered.
580 carrierConstraint = staticDest.getCarrier();
582 "it is NOT competent. its constraint is %s",
583 carrierConstraint.c_str());
584 }
585 delete destCarrier;
586 destCarrier = nullptr;
587 }
588 }
589 } else {
590 destIsTopic = true;
591 }
592
593 if (srcIsTopic || destIsTopic) {
594 Bottle cmd;
595 Bottle reply;
596 NameSpace& ns = getNameSpace();
597
598 bool ok = false;
599 if (srcIsTopic) {
600 if (mode == YARP_ENACT_CONNECT) {
601 ok = ns.connectTopicToPort(staticSrc, staticDest, style);
602 } else if (mode == YARP_ENACT_DISCONNECT) {
604 } else {
605 yCError(NETWORK, "Failure: cannot check subscriptions yet");
606 return 1;
607 }
608 } else {
609 if (mode == YARP_ENACT_CONNECT) {
610 ok = ns.connectPortToTopic(staticSrc, staticDest, style);
611 } else if (mode == YARP_ENACT_DISCONNECT) {
613 } else {
614 yCError(NETWORK, "Failure: cannot check subscriptions yet");
615 return 1;
616 }
617 }
618 if (!ok) {
619 return 1;
620 }
621 if (!style.quiet) {
622 if (style.verboseOnSuccess) {
623 yCInfo(NETWORK, "Success: connection to topic %s.", mode == YARP_ENACT_CONNECT ? "added" : "removed");
624 }
625 }
626 return 0;
627 }
628
630 "dynamicSrc.getCarrier() = %s",
631 dynamicSrc.getCarrier().c_str());
633 "dynamicDest.getCarrier() = %s",
634 dynamicDest.getCarrier().c_str());
636 "staticSrc.getCarrier() = %s",
637 staticSrc.getCarrier().c_str());
639 "staticDest.getCarrier() = %s",
640 staticDest.getCarrier().c_str());
642 "carrierConstraint is %s",
643 carrierConstraint.c_str());
644
646 "style.carrier (1) is %s",
647 style.carrier.c_str());
648
649
650 if (!dynamicSrc.getCarrier().empty()) { //if in connect command the user specified the carrier of src port
651 style.carrier = dynamicSrc.getCarrier();
653 "style.carrier is %s ==> in connect command the user specified the carrier of src port",
654 style.carrier.c_str());
655 }
656
657 if (!dynamicDest.getCarrier().empty()) { //if in connect command the user specified the carrier of dest port or the carrier of the connection
658 style.carrier = dynamicDest.getCarrier();
660 "style.carrier is %s ==> in connect command the user specified the carrier of dest port or the carrier of the connection",
661 style.carrier.c_str());
662 }
663
665 "at the end style style.carrier is %s",
666 style.carrier.c_str());
667
668 //here we'll check if the style carrier and the constraint carrier are equal.
669 //note that in both string may contain params of carrier, so we need to comapare only the name of carrier.
670 if (!style.carrier.empty() && !carrierConstraint.empty()) {
671 //get only carrier name of style.
673
674 //get only carrier name of carrierConstraint.
676
678 yCError(NETWORK, "Failure: conflict between %s and %s", style_carrier_name.c_str(), carrier_constraint_name.c_str());
679 return 1;
680 }
682 "style_carrier_name=%s and carrier_constraint_name=%s are equals!",
683 style_carrier_name.c_str(),
685 }
686 //we are going to choose the carrier of this connection, and we collect parameters specified by user
687 //in order to pass them to the carrier, so it can configure itself.
688 if (!carrierConstraint.empty()) {
690 //if I'm here means that sorce or dest is not competent.
691 //so we need to get parameters of carrier given in connect command.
693 "if I'm here means that source or dest is not competent");
694 std::string c = dynamicSrc.getCarrier();
697 }
698 c = dynamicDest.getCarrier();
701 }
702 }
703 if (style.carrier.empty()) {
704 style.carrier = staticDest.getCarrier();
705 //if I'm here means that both src and dest are copentent and the user didn't specified a carrier in the connect command
707 "if I'm here means that both src and dest are compentent and the user didn't specified a carrier in the connect command");
708 std::string c = dynamicSrc.getCarrier();
711 }
712 }
713
714 if (style.carrier.empty()) {
715 style.carrier = staticSrc.getCarrier();
716 yCTrace(NETWORK, "the chosen style carrier is static src");
717 }
718
719 //now stylecarrier contains the carrier chosen for this connection
720
722 "style_carrier with params =%s",
723 style.carrier.c_str());
724
725 addStatsMonitorIfNeeded(src,dest,style,mode);
726
727 bool connectionIsPush = false;
728 bool connectionIsPull = false;
729 Carrier* connectionCarrier = nullptr;
730 if (style.carrier != "topic") {
732 if (connectionCarrier != nullptr) {
735 }
736 }
737
738 int result = -1;
740 // Classic case.
742 delete connectionCarrier;
743 return enactConnection(staticSrc, c, style, mode, false);
744 }
747 delete connectionCarrier;
748 return enactConnection(staticDest, c, style, mode, true);
749 }
750
751 if (connectionCarrier != nullptr) {
752 if (!connectionIsPull) {
754 result = connectionCarrier->connect(staticSrc, c, style, mode, false);
755 } else {
757 result = connectionCarrier->connect(staticDest, c, style, mode, true);
758 }
759 }
760 if (connectionCarrier != nullptr) {
761 delete connectionCarrier;
762 connectionCarrier = nullptr;
763 }
764 if (result != -1) {
765 if (!style.quiet) {
766 if (result == 0) {
767 if (style.verboseOnSuccess) {
768 yCInfo(NETWORK, "Success: added connection using custom carrier method");
769 }
770 } else {
771 yCError(NETWORK, "Failure: custom carrier method did not work");
772 }
773 }
774 return result;
775 }
776
778 yCError(NETWORK, "Failure: no way to make connection %s->%s", src.c_str(), dest.c_str());
779 }
780
781 return 1;
782}
783
784bool NetworkBase::connect(const std::string& src, const std::string& dest, const std::string& carrier, bool quiet)
785{
786 ContactStyle style;
787 style.quiet = quiet;
788 if (!carrier.empty()) {
789 style.carrier = carrier;
790 }
791 return connect(src, dest, style);
792}
793
794bool NetworkBase::connect(const std::string& src,
795 const std::string& dest,
796 const ContactStyle& style)
797{
798 int result = metaConnect(src, dest, style, YARP_ENACT_CONNECT);
799 return result == 0;
800}
801
802bool NetworkBase::disconnect(const std::string& src,
803 const std::string& dest,
804 bool quiet)
805{
806 ContactStyle style;
807 style.quiet = quiet;
808 return disconnect(src, dest, style);
809}
810
811bool NetworkBase::disconnect(const std::string& src,
812 const std::string& dest,
813 const ContactStyle& style)
814{
815 int result = metaConnect(src, dest, style, YARP_ENACT_DISCONNECT);
816 return result == 0;
817}
818
819bool NetworkBase::disconnect(const std::string& src, const std::string& dest, const std::string& carrier, bool quiet)
820{
821 ContactStyle style;
822 style.quiet = quiet;
823 if (!carrier.empty()) {
824 style.carrier = carrier;
825 }
826 return disconnect(src, dest, style);
827}
828
829bool NetworkBase::isConnected(const std::string& src,
830 const std::string& dest,
831 bool quiet)
832{
833 ContactStyle style;
834 style.quiet = quiet;
835 return isConnected(src, dest, style);
836}
837
838bool NetworkBase::isConnected(const std::string& src, const std::string& dest, const std::string& carrier, bool quiet)
839{
840 ContactStyle style;
841 style.quiet = quiet;
842 if (!carrier.empty()) {
843 style.carrier = carrier;
844 }
845 return isConnected(src, dest, style);
846}
847
848bool NetworkBase::exists(const std::string& port, bool quiet, bool checkVer)
849{
850 ContactStyle style;
851 style.quiet = quiet;
852 return exists(port, style, checkVer);
853}
854
855bool NetworkBase::exists(const std::string& port, const ContactStyle& style, bool checkVer)
856{
857 bool silent = style.quiet;
858 Contact address = NetworkBase::queryName(port);
859 if (!address.isValid()) {
860 if (!silent) {
861 yCInfo(NETWORK, "Address of port %s is not valid", port.c_str());
862 }
863 return false;
864 }
865
866 Contact address2(address);
867 if (style.timeout >= 0) {
868 address2.setTimeout((float)style.timeout);
869 }
871
872 if (out == nullptr) {
873 if (!silent) {
874 yCInfo(NETWORK, "Cannot connect to port %s", port.c_str());
875 }
876 return false;
877 }
878 out->close();
879 delete out;
880 out = nullptr;
881
882 if (!checkVer) {
883 return true;
884 }
885
886 PortCoreClient client(Contact(port), style);
887 return client.getAdminProtocolVersion().ret;
888}
889
890
891bool NetworkBase::waitConnection(const std::string& source, const std::string& destination, bool quiet)
892{
893 int ct = 1;
894 while (true) {
895
896 if (ct % 30 == 1) {
897 if (!quiet) {
898 yCInfo(NETWORK, "Waiting for %s->%s...", source.c_str(), destination.c_str());
899 }
900 }
901 ct++;
902
903 int result = NetworkBase::isConnected(source, destination, true) ? 0 : 1;
904 if (result != 0) {
906 } else {
907 return true;
908 }
909 }
910}
911
912
913bool NetworkBase::waitPort(const std::string& target, bool quiet)
914{
915 int ct = 1;
916 while (true) {
917
918 if (ct % 30 == 1) {
919 if (!quiet) {
920 yCInfo(NETWORK, "Waiting for %s...", target.c_str());
921 }
922 }
923 ct++;
924
925 bool result = exists(target, true, false);
926 if (!result) {
928 } else {
929 return true;
930 }
931 }
932}
933
934
935bool NetworkBase::sync(const std::string& port, bool quiet)
936{
937 bool result = waitPort(port, quiet);
938 if (result) {
939 poll(port, true);
940 }
941 return result;
942}
943
944
949
958
963
968
969#if defined(YARP_HAS_ACE)
970namespace {
971class YARP_ACE
972{
973private:
974 YARP_ACE()
975 {
976 ACE::init();
977 }
978
979public:
980 ~YARP_ACE()
981 {
982 ACE::fini();
983 }
984
985 static YARP_ACE& init()
986 {
987 static YARP_ACE ace;
988 return ace;
989 }
990};
991} // namespace
992#endif
993
994
996{
997 YARP_UNUSED(custom);
998 if (__yarp_is_initialized == 0) {
999 // Broken pipes need to be dealt with through other means
1000 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
1001
1002#ifdef YARP_HAS_ACE
1003 YARP_ACE::init();
1004#endif
1005
1006 // make sure system is actually able to do things fast
1008
1009 // MultiNameSpace is a c++11 singleton and need to be initialized
1010 // before the first port that is opened and it has to exist until
1011 // the last port is closed.
1012 getNameSpace();
1013
1014 // Increment counter before initializing the clock.
1016
1017 // The network clock open a port, and inside the open of the port
1018 // the __yarp_is_initialized counter is checked > 0.
1021 }
1022 } else {
1024 }
1025}
1026
1028{
1029 if (__yarp_is_initialized == 1) {
1030 // The log forwarder needs to be shut down in order to close the
1031 // internal port. The shutdown method will do nothing if the
1032 // LogForwarded was not used.
1034
1037
1038 // reset system timer resolution
1040 }
1041 if (__yarp_is_initialized > 0) {
1043 }
1044}
1045
1047{
1048 std::string clock;
1051 if (!clock.empty()) {
1053 } else {
1055 }
1056 }
1057
1058 switch (clockType) {
1059 case YARP_CLOCK_SYSTEM:
1060 yCDebug(NETWORK, "Using SYSTEM clock");
1062 break;
1063
1064 case YARP_CLOCK_NETWORK:
1065 yCDebug(NETWORK, "Using NETWORK clock");
1067 // check of valid parameter is done inside the call, throws YARP_FAIL in case of error
1069 break;
1070
1071 case YARP_CLOCK_CUSTOM: {
1072 yCDebug(NETWORK, "Using CUSTOM clock");
1073 // check of valid parameter is done inside the call, throws YARP_FAIL in case of error
1075 } break;
1076
1077 default:
1078 yCFatal(NETWORK, "yarpClockInit called with unknown clock type. Quitting");
1079 break;
1080 }
1081}
1082
1083Contact NetworkBase::queryName(const std::string& name)
1084{
1085 yCDebug(NETWORK, "query name %s", name.c_str());
1086 if (getNameServerName() == name) {
1087 yCDebug(NETWORK, "query recognized as name server: %s", name.c_str());
1088 return getNameServerContact();
1089 }
1090 Contact c = c.fromString(name);
1091 if (c.isValid() && c.getPort() > 0) {
1092 return c;
1093 }
1094 return getNameSpace().queryName(name);
1095}
1096
1097
1098Contact NetworkBase::registerName(const std::string& name)
1099{
1100 yCDebug(NETWORK, "register name %s", name.c_str());
1101 return getNameSpace().registerName(name);
1102}
1103
1104
1106{
1107 yCDebug(NETWORK, "register contact %s", contact.toString().c_str());
1108 return getNameSpace().registerContact(contact);
1109}
1110
1111Contact NetworkBase::unregisterName(const std::string& name)
1112{
1113 return getNameSpace().unregisterName(name);
1114}
1115
1116
1118{
1119 return getNameSpace().unregisterContact(contact);
1120}
1121
1122
1123bool NetworkBase::setProperty(const char* name,
1124 const char* key,
1125 const Value& value)
1126{
1127 return getNameSpace().setProperty(name, key, value);
1128}
1129
1130
1131Value* NetworkBase::getProperty(const char* name, const char* key)
1132{
1133 return getNameSpace().getProperty(name, key);
1134}
1135
1136
1138{
1139 return getNameSpace().setLocalMode(flag);
1140}
1141
1143{
1144 NameSpace& ns = getNameSpace();
1145 return ns.localOnly();
1146}
1147
1149{
1150 // could replace with ACE assertions, except should not
1151 // evaporate in release mode
1153}
1154
1155bool NetworkBase::setConnectionQos(const std::string& src, const std::string& dest, const QosStyle& style, bool quiet)
1156{
1157 return setConnectionQos(src, dest, style, style, quiet);
1158}
1159
1160// Sets the Qos of the connection between `port` and `other`, as seen from `port`.
1161// isOutput: true if the connection goes from `port` to `other`, false if it
1162// goes from `other` to `port`.
1163static bool setPortQos(const std::string& port, const std::string& other, bool isOutput, const QosStyle& style, bool quiet)
1164{
1165 // ignore if everything left as default
1166 if (style.getPacketPriorityAsTOS() == -1 && style.getThreadPolicy() == -1) {
1167 return true;
1168 }
1169
1170 PortCoreClient client(port);
1171 const return_setConnectionQos result = isOutput
1172 ? client.setConnectionQosOut(other, style.getThreadPriority(), style.getThreadPolicy(), style.getPacketPriorityAsTOS())
1173 : client.setConnectionQosIn(other, style.getThreadPriority(), style.getThreadPolicy(), style.getPacketPriorityAsTOS());
1174 if (!result.ret) {
1175 if (!quiet) {
1176 yCError(NETWORK, "Cannot write to '%s'", port.c_str());
1177 }
1178 return false;
1179 }
1180 if (!result.success) {
1181 if (!quiet) {
1182 yCError(NETWORK, "Cannot set qos properties of '%s'. (%s)", port.c_str(), result.message.c_str());
1183 }
1184 return false;
1185 }
1186 return true;
1187}
1188
1189bool NetworkBase::setConnectionQos(const std::string& src, const std::string& dest, const QosStyle& srcStyle, const QosStyle& destStyle, bool quiet)
1190{
1191 if (!setPortQos(src, dest, true, srcStyle, quiet)) {
1192 return false;
1193 }
1194 if (!setPortQos(dest, src, false, destStyle, quiet)) {
1195 return false;
1196 }
1197 return true;
1198}
1199
1201{
1202 NameConfig nc;
1203 std::string name = nc.getNamespace();
1204 Bottle msg, reply;
1205 msg.addString("bot");
1206 msg.addString("list");
1207 yCInfo(NETWORK, "Requesting list of ports from name server... ");
1208 NetworkBase::write(name,
1209 msg,
1210 reply);
1211 int ct = reply.size()-1;
1212 yCInfo(NETWORK, "got %d port%s", ct, (ct!=1)?"s":"");
1213
1214 for (size_t i=1; i<reply.size(); i++) {
1215 Bottle *entry = reply.get(i).asList();
1216 if (entry != nullptr) {
1217 std::string port = entry->check("name", Value("")).asString();
1218 if (port!="" && port!="fallback" && port!=name) {
1220 if (c.getCarrier()=="mcast") {
1221 yCInfo(NETWORK, "Skipping mcast port %s...", port.c_str());
1222 } else {
1223 Contact addr = c;
1224 yCInfo(NETWORK, "Testing %s at %s",
1225 port.c_str(),
1226 addr.toURI().c_str());
1227 if (addr.isValid()) {
1228 if (timeout>=0) {
1229 addr.setTimeout((float)timeout);
1230 }
1232 if (out == nullptr) {
1233 yCInfo(NETWORK, "* No response, removing port %s", port.c_str());
1235 } else {
1236 delete out;
1237 }
1238 }
1239 }
1240 } else {
1241 if (port!="") {
1242 yCInfo(NETWORK, "Ignoring %s", port.c_str());
1243 }
1244 }
1245 }
1246 }
1247 yCInfo(NETWORK, "Giving name server a chance to do garbage collection.");
1249 Bottle cmd2("gc"), reply2;
1251 yCInfo(NETWORK, "Name server says: %s", reply2.toString().c_str());
1252
1253 return true;
1254}
1255
1256// Gets the Qos of the connection between `port` and `other`, as seen from `port`.
1257// isOutput: true if the connection goes from `port` to `other`, false if it
1258// goes from `other` to `port`.
1259static bool getPortQos(const std::string& port, const std::string& other, bool isOutput, QosStyle& style, bool quiet)
1260{
1261 PortCoreClient client(port);
1262 const return_getConnectionQos result = isOutput ? client.getConnectionQosOut(other)
1263 : client.getConnectionQosIn(other);
1264 if (!result.ret) {
1265 if (!quiet) {
1266 yCError(NETWORK, "Cannot write to '%s'", port.c_str());
1267 }
1268 return false;
1269 }
1270 if (!result.found) {
1271 if (!quiet) {
1272 yCError(NETWORK, "Cannot get qos properties of '%s': no connection %s '%s'",
1273 port.c_str(), isOutput ? "to" : "from", other.c_str());
1274 }
1275 return false;
1276 }
1277
1278 style.setThreadPriority(result.thread.priority);
1279 style.setThreadPolicy(result.thread.policy);
1280 style.setPacketPrioritybyTOS(result.qos_tos);
1281
1282 return true;
1283}
1284
1285bool NetworkBase::getConnectionQos(const std::string& src, const std::string& dest, QosStyle& srcStyle, QosStyle& destStyle, bool quiet)
1286{
1287 if (!getPortQos(src, dest, true, srcStyle, quiet)) {
1288 return false;
1289 }
1290 if (!getPortQos(dest, src, false, destStyle, quiet)) {
1291 return false;
1292 }
1293 return true;
1294}
1295
1296bool NetworkBase::isValidPortName(const std::string& portName)
1297{
1298 if (portName.empty()) {
1299 return false;
1300 }
1301
1302 if (portName == "...") {
1303 return true;
1304 }
1305
1306 if (portName.at(0) != '/') {
1307 return false;
1308 }
1309
1310 if (portName.at(portName.size() - 1) == '/') {
1311 return false;
1312 }
1313
1314 if (portName.find(' ') != std::string::npos) {
1315 return false;
1316 }
1317
1318 return true;
1319}
1320
1321
1322bool NetworkBase::write(const Contact& contact,
1323 PortWriter& cmd,
1324 PortReader& reply,
1325 bool admin,
1326 bool quiet,
1327 double timeout)
1328{
1329 ContactStyle style;
1330 style.admin = admin;
1331 style.quiet = quiet;
1332 style.timeout = timeout;
1333 style.carrier = contact.getCarrier();
1334 return write(contact, cmd, reply, style);
1335}
1336
1337bool NetworkBase::write(const Contact& contact,
1338 PortWriter& cmd,
1339 PortReader& reply,
1340 const ContactStyle& style)
1341{
1342 if (!getNameSpace().serverAllocatesPortNumbers()) {
1343 // switch to more up-to-date method
1344
1345 Port port;
1346 port.setAdminMode(style.admin);
1347 port.openFake("network_write");
1348 Contact ec = contact;
1349 if (!style.carrier.empty()) {
1350 ec.setCarrier(style.carrier);
1351 }
1352 if (!port.addOutput(ec)) {
1353 if (!style.quiet) {
1354 yCError(NETWORK, "Cannot make connection to '%s'", ec.toString().c_str());
1355 }
1356 return false;
1357 }
1358
1359 bool ok = port.write(cmd, reply);
1360 return ok;
1361 }
1362
1363 const char* connectionName = "admin";
1364 std::string name = contact.getName();
1365 const char* targetName = name.c_str(); // use carefully!
1366 Contact address = contact;
1367 if (!address.isValid()) {
1368 address = getNameSpace().queryName(targetName);
1369 }
1370 if (!address.isValid()) {
1371 if (!style.quiet) {
1372 yCError(NETWORK, "cannot find port %s", targetName);
1373 }
1374 return false;
1375 }
1376
1377 if (style.timeout > 0) {
1378 address.setTimeout((float)style.timeout);
1379 }
1380 OutputProtocol* out = Carriers::connect(address);
1381 if (out == nullptr) {
1382 if (!style.quiet) {
1383 yCError(NETWORK, "Cannot connect to port %s", targetName);
1384 }
1385 return false;
1386 }
1387 if (style.timeout > 0) {
1388 out->setTimeout(style.timeout);
1389 }
1390
1391 Route r(connectionName, targetName, (!style.carrier.empty()) ? style.carrier.c_str() : "text_ack");
1392 out->open(r);
1393
1394 PortCommand pc(0, style.admin ? "a" : "d");
1395 BufferedConnectionWriter bw(out->getConnection().isTextMode(),
1396 out->getConnection().isBareMode());
1397 bool ok = true;
1398 if (out->getConnection().canEscape()) {
1399 ok = pc.write(bw);
1400 }
1401 if (!ok) {
1402 if (!style.quiet) {
1403 yCError(NETWORK, "could not write to connection");
1404 }
1405 delete out;
1406 return false;
1407 }
1408 ok = cmd.write(bw);
1409 if (!ok) {
1410 if (!style.quiet) {
1411 yCError(NETWORK, "could not write to connection");
1412 }
1413 delete out;
1414 return false;
1415 }
1416 if (style.expectReply) {
1417 bw.setReplyHandler(reply);
1418 }
1419 out->write(bw);
1420 if (out != nullptr) {
1421 delete out;
1422 out = nullptr;
1423 }
1424 return true;
1425}
1426
1427bool NetworkBase::write(const std::string& port_name,
1428 PortWriter& cmd,
1429 PortReader& reply)
1430{
1431 return write(Contact(port_name), cmd, reply);
1432}
1433
1434bool NetworkBase::isConnected(const std::string& src, const std::string& dest, const ContactStyle& style)
1435{
1436 int result = metaConnect(src, dest, style, YARP_ENACT_EXISTS);
1437 if (result != 0) {
1438 if (!style.quiet) {
1439 yCInfo(NETWORK, "No connection from %s to %s found",
1440 src.c_str(),
1441 dest.c_str());
1442 }
1443 }
1444 return result == 0;
1445}
1446
1447
1449{
1450 NameConfig nc;
1451 std::string name = nc.getNamespace(false);
1452 return name;
1453}
1454
1455
1457{
1458 return getNameSpace().getNameServerContact();
1459}
1460
1461
1462bool NetworkBase::setNameServerName(const std::string& name)
1463{
1464 NameConfig nc;
1465 std::string fname = nc.getConfigFileName(YARP_CONFIG_NAMESPACE_FILENAME);
1466 nc.writeConfig(fname, name + "\n");
1467 nc.getNamespace(true);
1468 getNameSpace().activate(true);
1469 return true;
1470}
1471
1472
1474{
1475 return getNameSpace().checkNetwork();
1476}
1477
1478
1479bool NetworkBase::checkNetwork(double timeout)
1480{
1481 return getNameSpace().checkNetwork(timeout);
1482}
1483
1484
1486{
1487 return __yarp_is_initialized > 0;
1488}
1489
1490#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
1501#endif
1502
1504{
1505 getNameSpace().queryBypass(store);
1506}
1507
1509{
1510 return getNameSpace().getQueryBypass();
1511}
1512
1513namespace {
1514std::mutex& getNetworkMutex()
1515{
1516 static std::mutex mutex;
1517 return mutex;
1518}
1519} // namespace
1520
1522{
1523 getNetworkMutex().lock();
1524}
1525
1527{
1528 getNetworkMutex().unlock();
1529}
1530
1531
1532int NetworkBase::sendMessage(const std::string& port,
1534 bool silent)
1535{
1536 std::string output;
1537 return sendMessage(port, writable, output, silent);
1538}
1539
1540int NetworkBase::sendMessage(const std::string& port,
1542 std::string& output,
1543 bool quiet)
1544{
1545 output = "";
1547 if (!srcAddress.isValid()) {
1548 if (!quiet) {
1549 yCError(NETWORK, "Cannot find port named %s", port.c_str());
1550 }
1551 return 1;
1552 }
1554 if (out == nullptr) {
1555 if (!quiet) {
1556 yCError(NETWORK, "Cannot connect to port named %s at %s", port.c_str(), srcAddress.toURI().c_str());
1557 }
1558 return 1;
1559 }
1560 Route route("admin", port, "text");
1561
1562
1563 bool ok = out->open(route);
1564 if (!ok) {
1565 if (!quiet) {
1566 yCError(NETWORK, "Cannot make connection");
1567 }
1568 delete out;
1569 return 1;
1570 }
1571
1572 BufferedConnectionWriter bw(out->getConnection().isTextMode());
1573 PortCommand disconnect('\0', "q");
1574 bool wok = writable.write(bw);
1575 if (!wok) {
1576 if (!quiet) {
1577 yCError(NETWORK, "Cannot write on connection");
1578 }
1579 delete out;
1580 return 1;
1581 }
1582 if (!disconnect.write(bw)) {
1583 if (!quiet) {
1584 yCError(NETWORK, "Cannot write on connection");
1585 }
1586 delete out;
1587 return 1;
1588 }
1589
1590 out->write(bw);
1591 InputProtocol& ip = out->getInput();
1592 ConnectionReader& con = ip.beginRead();
1593 Bottle b;
1594 b.read(con);
1595 b.read(con);
1596 output = b.toString();
1597 if (!quiet) {
1598 yCInfo(NETWORK, "%s", b.toString().c_str());
1599 }
1600 ip.endRead();
1601 out->close();
1602 delete out;
1603 out = nullptr;
1604
1605 return 0;
1606}
1607
1608int NetworkBase::poll(const std::string& target, bool silent)
1609{
1610 PortCommand pc('\0', "*");
1611 return sendMessage(target, pc, silent);
1612}
1613
1614int NetworkBase::disconnectInput(const std::string& src,
1615 const std::string& dest,
1616 bool silent)
1617{
1618 PortCommand pc('\0', std::string("~") + dest);
1619 return sendMessage(src, pc, silent);
1620}
1621
1623{
1624public:
1628
1630 {
1631 owner = nullptr;
1632 factory = nullptr;
1633 }
1634
1636 Carrier* owner) :
1638 owner(owner)
1639 {
1640 factory->addRef();
1641 car.open(*factory);
1642 }
1643
1645 {
1646 car.close();
1647 if (factory == nullptr) {
1648 return;
1649 }
1650 factory->removeRef();
1651 if (factory->getReferenceCount() <= 0) {
1652 delete factory;
1653 }
1654 factory = nullptr;
1655 }
1656
1658 {
1659 return car.getContent();
1660 }
1661
1662 virtual const Carrier& getContent() const
1663 {
1664 return car.getContent();
1665 }
1666
1667 Carrier* create() const override
1668 {
1669 return owner->create();
1670 }
1671
1672
1673 // Forward yarp::os::Connection methods
1674
1675 bool isValid() const override
1676 {
1677 return car.isValid();
1678 }
1679
1680 bool isTextMode() const override
1681 {
1682 return getContent().isTextMode();
1683 }
1684
1685 bool isBareMode() const override
1686 {
1687 return getContent().isBareMode();
1688 }
1689
1690 bool canEscape() const override
1691 {
1692 return getContent().canEscape();
1693 }
1694
1695 void handleEnvelope(const std::string& envelope) override
1696 {
1697 getContent().handleEnvelope(envelope);
1698 }
1699
1700 bool requireAck() const override
1701 {
1702 return getContent().requireAck();
1703 }
1704
1705 bool supportReply() const override
1706 {
1707 return getContent().supportReply();
1708 }
1709
1710 bool isLocal() const override
1711 {
1712 return getContent().isLocal();
1713 }
1714
1715 bool isPush() const override
1716 {
1717 return getContent().isPush();
1718 }
1719
1720 bool isConnectionless() const override
1721 {
1722 return getContent().isConnectionless();
1723 }
1724
1725 bool isBroadcast() const override
1726 {
1727 return getContent().isBroadcast();
1728 }
1729
1730 bool isActive() const override
1731 {
1732 return getContent().isActive();
1733 }
1734
1735 bool modifiesIncomingData() const override
1736 {
1737 return getContent().modifiesIncomingData();
1738 }
1739
1741 {
1742 return getContent().modifyIncomingData(reader);
1743 }
1744
1746 {
1747 return getContent().acceptIncomingData(reader);
1748 }
1749
1750 bool modifiesOutgoingData() const override
1751 {
1752 return getContent().modifiesOutgoingData();
1753 }
1754
1755 const PortWriter& modifyOutgoingData(const PortWriter& writer) override
1756 {
1757 return getContent().modifyOutgoingData(writer);
1758 }
1759
1760 bool acceptOutgoingData(const PortWriter& writer) override
1761 {
1762 return getContent().acceptOutgoingData(writer);
1763 }
1764
1765 bool modifiesReply() const override
1766 {
1767 return getContent().modifiesReply();
1768 }
1769
1771 {
1772 return getContent().modifyReply(reader);
1773 }
1774
1775 void setCarrierParams(const Property& params) override
1776 {
1777 getContent().setCarrierParams(params);
1778 }
1779
1780 void getCarrierParams(Property& params) const override
1781 {
1782 getContent().getCarrierParams(params);
1783 }
1784
1785 void getHeader(yarp::os::Bytes& header) const override
1786 {
1787 getContent().getHeader(header);
1788 }
1789
1790 void prepareDisconnect() override
1791 {
1792 getContent().prepareDisconnect();
1793 }
1794
1795 std::string getName() const override
1796 {
1797 return getContent().getName();
1798 }
1799
1800
1801 // Forward yarp::os::Carrier methods
1802
1803 bool checkHeader(const yarp::os::Bytes& header) override
1804 {
1805 return getContent().checkHeader(header);
1806 }
1807
1808 void setParameters(const yarp::os::Bytes& header) override
1809 {
1810 getContent().setParameters(header);
1811 }
1812
1813 bool canAccept() const override
1814 {
1815 return getContent().canAccept();
1816 }
1817
1818 bool canOffer() const override
1819 {
1820 return getContent().canOffer();
1821 }
1822
1824 {
1825 return getContent().prepareSend(proto);
1826 }
1827
1829 {
1830 return getContent().sendHeader(proto);
1831 }
1832
1834 {
1835 return getContent().expectReplyToHeader(proto);
1836 }
1837
1838 bool write(ConnectionState& proto, SizedWriter& writer) override
1839 {
1840 return getContent().write(proto, writer);
1841 }
1842
1843 bool reply(ConnectionState& proto, SizedWriter& writer) override
1844 {
1845 return getContent().reply(proto, writer);
1846 }
1847
1849 {
1850 return getContent().expectExtraHeader(proto);
1851 }
1852
1854 {
1855 return getContent().respondToHeader(proto);
1856 }
1857
1859 {
1860 return getContent().expectIndex(proto);
1861 }
1862
1864 {
1865 return getContent().expectSenderSpecifier(proto);
1866 }
1867
1869 {
1870 return getContent().sendAck(proto);
1871 }
1872
1874 {
1875 return getContent().expectAck(proto);
1876 }
1877
1878 std::string toString() const override
1879 {
1880 return getContent().toString();
1881 }
1882
1883 void close() override
1884 {
1885 getContent().close();
1886 }
1887
1888 std::string getBootstrapCarrierName() const override
1889 {
1890 return getContent().getBootstrapCarrierName();
1891 }
1892
1894 const yarp::os::Contact& dest,
1895 const yarp::os::ContactStyle& style,
1896 int mode,
1897 bool reversed) override
1898 {
1899 return getContent().connect(src, dest, style, mode, reversed);
1900 }
1901
1903 {
1904 return getContent().configure(proto);
1905 }
1907 {
1908 return getContent().configureFromProperty(options);
1909 }
1910
1911 yarp::os::Face* createFace() const override
1912 {
1913 return getContent().createFace();
1914 }
1915};
1916
1917
1919{
1920private:
1921 YarpPluginSettings settings;
1922 YarpPlugin<Carrier> plugin;
1923
1924public:
1925 StubCarrier(const char* dll_name, const char* fn_name)
1926 {
1927 settings.setLibraryMethodName(dll_name, fn_name);
1928 init();
1929 }
1930
1931 StubCarrier(const char* name)
1932 {
1933 settings.setPluginName(name);
1934 init();
1935 }
1936
1937 void init()
1938 {
1939 YarpPluginSelector selector;
1940 selector.scan();
1941 settings.setSelector(selector);
1942 if (plugin.open(settings)) {
1943 car.open(*plugin.getFactory());
1944 settings.setLibraryMethodName(plugin.getFactory()->getName(),
1945 settings.getMethodName());
1946 }
1947 }
1948
1950 {
1951 return car.getContent();
1952 }
1953
1954 const Carrier& getContent() const override
1955 {
1956 return car.getContent();
1957 }
1958
1959 Carrier* create() const override
1960 {
1961 auto* ncar = new ForwardingCarrier(plugin.getFactory(), const_cast<StubCarrier*>(this));
1962 if (ncar == nullptr) {
1963 return nullptr;
1964 }
1965 if (!ncar->isValid()) {
1966 delete ncar;
1967 ncar = nullptr;
1968 return nullptr;
1969 }
1970 return ncar;
1971 }
1972
1973 std::string getDllName() const
1974 {
1975 return settings.getLibraryName();
1976 }
1977
1978 std::string getFnName() const
1979 {
1980 return settings.getMethodName();
1981 }
1982};
1983
1984
1985bool NetworkBase::registerCarrier(const char* name, const char* dll)
1986{
1987 StubCarrier* factory = nullptr;
1988 if (dll == nullptr) {
1989 factory = new StubCarrier(name);
1990 if (factory == nullptr) {
1991 return false;
1992 }
1993 } else {
1994 factory = new StubCarrier(dll, name);
1995 }
1996 if (factory == nullptr) {
1997 yCError(NETWORK, "Failed to register carrier");
1998 return false;
1999 }
2000 if (!factory->isValid()) {
2001 if (dll != nullptr) {
2002 yCError(NETWORK, "Failed to find library %s with carrier %s", dll, name);
2003 } else {
2004 yCError(NETWORK, "Failed to find library support for carrier %s", name);
2005 }
2006 delete factory;
2007 factory = nullptr;
2008 return false;
2009 }
2011 return true;
2012}
2013
2014
2016{
2017 bool globalAlloc = getNameSpace().serverAllocatesPortNumbers();
2018 return !globalAlloc;
2019}
2020
2021
2023 bool& scanNeeded,
2024 bool& serverUsed)
2025{
2026 return getNameSpace().detectNameServer(useDetectedServer,
2027 scanNeeded,
2028 serverUsed);
2029}
2030
2032{
2034 if (!nameServerContact.getName().empty()) {
2036 }
2037 nameConfig.fromFile();
2038 nameConfig.setAddress(nameServerContact);
2039 bool result = nameConfig.toFile();
2040 getNameSpace().activate(true);
2041 return result;
2042}
2043
2044
2046 PortReader& reply,
2047 const ContactStyle& style)
2048{
2049 NameStore* store = getNameSpace().getQueryBypass();
2050 if (store != nullptr) {
2051 Contact contact;
2052 return store->process(cmd, reply, contact);
2053 }
2054 return getNameSpace().writeToNameServer(cmd, reply, style);
2055}
2056
2057
2058std::string NetworkBase::getConfigFile(const char* fname)
2059{
2061}
2062
2063
2065{
2066 std::string range = yarp::conf::environment::get_string("YARP_PORT_RANGE");
2067 if (!range.empty()) {
2068 int irange = yarp::conf::numeric::from_string<int>(range);
2069 if (irange != 0) {
2070 return irange;
2071 }
2072 }
2073 return 10000;
2074}
#define YARP_ENACT_DISCONNECT
Definition Carrier.h:13
#define YARP_ENACT_EXISTS
Definition Carrier.h:14
#define YARP_ENACT_CONNECT
Definition Carrier.h:12
FeatureMode mode
#define YARP_CONFIG_NAMESPACE_FILENAME
Definition NameConfig.h:16
static bool is_stats_port(const std::string &src, const std::string &dest)
Check if the given source and destination ports are stats ports.
Definition Network.cpp:324
static int enactConnection(const Contact &src, const Contact &dest, const ContactStyle &style, int mode, bool reversed)
Connect, disconnect, or check the connection between two ports, by sending administrative commands to...
Definition Network.cpp:161
static void addStatsMonitorIfNeeded(const std::string &src, const std::string &dest, ContactStyle &style, int mode)
Definition Network.cpp:337
static MultiNameSpace & getNameSpace()
Definition Network.cpp:87
static bool is_log_port(const std::string &src, const std::string &dest)
Check if the given source and destination ports are log ports.
Definition Network.cpp:303
static bool getPortQos(const std::string &port, const std::string &other, bool isOutput, QosStyle &style, bool quiet)
Definition Network.cpp:1259
static std::string collectParams(Contact &c)
Definition Network.cpp:280
static int metaConnect(const std::string &src, const std::string &dest, ContactStyle style, int mode)
Definition Network.cpp:400
static bool needsLookup(const Contact &contact)
Definition Network.cpp:93
static int __yarp_is_initialized
Definition Network.cpp:57
static YarpAutoInit yarp_auto_init
destructor is called on shutdown.
Definition Network.cpp:85
static std::string extractCarrierNameOnly(const std::string &carrier_name_with_params)
Definition Network.cpp:290
static bool setPortQos(const std::string &port, const std::string &other, bool isOutput, const QosStyle &style, bool quiet)
Definition Network.cpp:1163
static int noteDud(const Contact &src)
Notify the name server that a port did not respond (i.e.
Definition Network.cpp:116
static bool __yarp_auto_init_active
Definition Network.cpp:58
bool modifiesReply() const override
Check if this carrier modifies outgoing data through the Carrier::modifyReply method.
Definition Network.cpp:1765
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:1785
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition Network.cpp:1690
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:1803
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition Network.cpp:1795
ConnectionReader & modifyIncomingData(ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
Definition Network.cpp:1740
bool sendAck(ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
Definition Network.cpp:1868
bool isTextMode() const override
Check if carrier is textual in nature.
Definition Network.cpp:1680
bool expectAck(ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
Definition Network.cpp:1873
void prepareDisconnect() override
Do cleanup and preparation for the coming disconnect, if necessary.
Definition Network.cpp:1790
bool reply(ConnectionState &proto, SizedWriter &writer) override
Definition Network.cpp:1843
bool isBareMode() const override
Check if carrier excludes type information from payload.
Definition Network.cpp:1685
bool modifiesIncomingData() const override
Check if this carrier modifies incoming data through the Carrier::modifyIncomingData method.
Definition Network.cpp:1735
SharedLibraryClassFactory< Carrier > * factory
Definition Network.cpp:1625
void handleEnvelope(const std::string &envelope) override
Carriers that do not distinguish data from administrative headers (i.e.
Definition Network.cpp:1695
bool expectReplyToHeader(ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
Definition Network.cpp:1833
bool sendHeader(ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
Definition Network.cpp:1828
bool isBroadcast() const override
Check if this carrier uses a broadcast mechanism.
Definition Network.cpp:1725
bool write(ConnectionState &proto, SizedWriter &writer) override
Write a message.
Definition Network.cpp:1838
bool modifiesOutgoingData() const override
Check if this carrier modifies outgoing data through the Carrier::modifyOutgoingData method.
Definition Network.cpp:1750
const PortWriter & modifyOutgoingData(const PortWriter &writer) override
Modify outgoing payload data, if appropriate.
Definition Network.cpp:1755
SharedLibraryClass< Carrier > car
Definition Network.cpp:1626
Carrier * create() const override
Factory method.
Definition Network.cpp:1667
bool isPush() const override
Check if carrier is "push" or "pull" style.
Definition Network.cpp:1715
bool canAccept() const override
Check if reading is implemented for this carrier.
Definition Network.cpp:1813
bool configure(ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
Definition Network.cpp:1902
PortReader & modifyReply(PortReader &reader) override
Modify reply payload data, if appropriate.
Definition Network.cpp:1770
bool configureFromProperty(yarp::os::Property &options) override
Definition Network.cpp:1906
bool isLocal() const override
Check if carrier operates within a single process.
Definition Network.cpp:1710
bool acceptIncomingData(ConnectionReader &reader) override
Determine whether incoming data should be accepted.
Definition Network.cpp:1745
virtual const Carrier & getContent() const
Definition Network.cpp:1662
virtual Carrier & getContent()
Definition Network.cpp:1657
ForwardingCarrier(SharedLibraryClassFactory< Carrier > *factory, Carrier *owner)
Definition Network.cpp:1635
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
Definition Network.cpp:1705
std::string toString() const override
Get name of carrier.
Definition Network.cpp:1878
bool canOffer() const override
Check if writing is implemented for this carrier.
Definition Network.cpp:1818
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition Network.cpp:1720
bool prepareSend(ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
Definition Network.cpp:1823
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:1888
void setCarrierParams(const Property &params) override
Configure carrier from port administrative commands.
Definition Network.cpp:1775
~ForwardingCarrier() override
Definition Network.cpp:1644
bool isValid() const override
Check if this object is really a connection, or just an empty placeholder.
Definition Network.cpp:1675
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:1893
bool acceptOutgoingData(const PortWriter &writer) override
Determine whether outgoing data should be accepted.
Definition Network.cpp:1760
bool expectExtraHeader(ConnectionState &proto) override
Receive any carrier-specific header.
Definition Network.cpp:1848
yarp::os::Face * createFace() const override
Create new Face object that the carrier needs.
Definition Network.cpp:1911
bool respondToHeader(ConnectionState &proto) override
Respond to the header.
Definition Network.cpp:1853
bool expectIndex(ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
Definition Network.cpp:1858
bool isActive() const override
Check if carrier is alive and error free.
Definition Network.cpp:1730
void close() override
Close the carrier.
Definition Network.cpp:1883
bool expectSenderSpecifier(ConnectionState &proto) override
Expect the name of the sending port.
Definition Network.cpp:1863
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
Definition Network.cpp:1808
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
Definition Network.cpp:1700
void getCarrierParams(Property &params) const override
Get carrier configuration and deliver it by port administrative commands.
Definition Network.cpp:1780
std::string getDllName() const
Definition Network.cpp:1973
void init()
Definition Network.cpp:1937
StubCarrier(const char *dll_name, const char *fn_name)
Definition Network.cpp:1925
std::string getFnName() const
Definition Network.cpp:1978
Carrier * create() const override
Factory method.
Definition Network.cpp:1959
StubCarrier(const char *name)
Definition Network.cpp:1931
const Carrier & getContent() const override
Definition Network.cpp:1954
Carrier & getContent() override
Definition Network.cpp:1949
A single-use class to shut down the yarp library if it was initialized automatically.
Definition Network.cpp:66
~YarpAutoInit()
Shut down the yarp library if it was automatically initialized.
Definition Network.cpp:77
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:252
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:241
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:247
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:176
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:212
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
static Contact fromConfig(const Searchable &config)
Factory method.
Definition Contact.cpp:129
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:865
static void setMinimumPrintLevel(LogType level)
Set current minimum print level.
Definition Log.cpp:847
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:1485
static std::string getNameServerName()
Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten...
Definition Network.cpp:1448
static bool isNetworkInitialized()
Definition Network.cpp:964
static bool getLocalMode()
Get current value of flag "localMode", see setLocalMode function.
Definition Network.cpp:1142
static Contact getNameServerContact()
Get the contact information for the port associated with the nameserver (usually "/root",...
Definition Network.cpp:1456
static bool sync(const std::string &port, bool quiet=true)
Wait for a port to be ready and responsive.
Definition Network.cpp:935
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:784
static void queryBypass(NameStore *store)
Redirect queries to another source.
Definition Network.cpp:1503
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:1046
static void unlock()
Call post() on a global mutual-exclusion semaphore allocated by YARP.
Definition Network.cpp:1526
static bool registerCarrier(const char *name, const char *dll)
Register a carrier to make available at runtime.
Definition Network.cpp:1985
static Contact unregisterName(const std::string &name)
Removes the registration for a name from the name server.
Definition Network.cpp:1111
static NameStore * getQueryBypass()
Definition Network.cpp:1508
static Contact unregisterContact(const Contact &contact)
Removes the registration for a contact from the name server.
Definition Network.cpp:1117
static bool waitPort(const std::string &target, bool quiet=false)
Delays the system until a specified port is open.
Definition Network.cpp:913
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:1462
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:1285
static Contact registerContact(const Contact &contact)
Register contact information with the name server.
Definition Network.cpp:1105
static bool setNameServerContact(Contact &nameServerContact)
Set explicitly the nameserver information.
Definition Network.cpp:2031
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:1608
static Contact queryName(const std::string &name)
Find out information about a registered name.
Definition Network.cpp:1083
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:848
static void setVerbosity(int verbosity)
Set level of verbosity of YARP messages.
Definition Network.cpp:1491
static void initMinimum()
Basic system initialization, not including plugins.
Definition Network.cpp:959
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:1532
static void autoInitMinimum()
Basic system initialization, not including plugins.
Definition Network.cpp:945
static void finiMinimum()
Deinitialization, excluding plugins.
Definition Network.cpp:1027
static Contact detectNameServer(bool useDetectedServer, bool &scanNeeded, bool &serverUsed)
Scan for an available name server.
Definition Network.cpp:2022
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:1123
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:2064
static void lock()
Call wait() on a global mutual-exclusion semaphore allocated by YARP.
Definition Network.cpp:1521
static std::string getConfigFile(const char *fname)
Search for a configuration file in YARP's standard config file path.
Definition Network.cpp:2058
static Contact registerName(const std::string &name)
Register a name with the name server.
Definition Network.cpp:1098
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:1614
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:891
static void assertion(bool shouldBeTrue)
An assertion.
Definition Network.cpp:1148
static bool checkNetwork()
Check if the YARP Network is up and running.
Definition Network.cpp:1473
static bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style)
Variant write method specialized to name server.
Definition Network.cpp:2045
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:802
static bool localNetworkAllocation()
Check where the name server in use expects processes to allocate their own network resources.
Definition Network.cpp:2015
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:1131
static bool isValidPortName(const std::string &portName)
Checks that the port has a valid name.
Definition Network.cpp:1296
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:1189
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:1322
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:829
static bool cleanUnresponsivePorts(double timeout=-1)
Clean up unresponsive ports from the name server.
Definition Network.cpp:1200
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1137
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.
virtual return_getConnectionInfo getConnectionInfoOut(const std::string &portname)
Give details about the output connection going from this port to another port.
virtual return_getAdminProtocolVersion getAdminProtocolVersion()
Report the version of the administrative protocol of this port (it is distinct from the version of th...
virtual return_getConnectionQos getConnectionQosOut(const std::string &portname)
Get the quality of service of the output connection going from this port to another port.
virtual return_setConnectionQos setConnectionQosOut(const std::string &portname, const std::int32_t scheduler_priority, const std::int32_t scheduler_policy, const std::int32_t qos_tos)
Set the quality of service of the output connection going from this port to another port.
virtual return_getConnectionQos getConnectionQosIn(const std::string &portname)
Get the quality of service of the input connection coming from another port to this port.
virtual return_setConnectionQos setConnectionQosIn(const std::string &portname, const std::int32_t scheduler_priority, const std::int32_t scheduler_policy, const std::int32_t qos_tos)
Set the quality of service of the input connection coming from another port to this port.
virtual return_getConnectionInfo getConnectionInfoIn(const std::string &portname)
Give details about the input connection coming from another port to this port.
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:395
void setAdminMode(bool adminMode=true)
Turn on/off "admin" mode.
Definition Port.cpp:554
bool addOutput(const std::string &name) override
Add an output connection to the specified port.
Definition Port.cpp:320
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:32
Preferences for the port's Quality of Service.
Definition QosStyle.h:23
int getThreadPolicy() const
returns the communication thread scheduling policy
Definition QosStyle.h:181
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
int getPacketPriorityAsTOS() const
returns the packet TOS value
Definition QosStyle.h:147
int getThreadPriority() const
returns the communication thread priority level
Definition QosStyle.h:171
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:44
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:246
Pick out a set of relevant plugins.
void scan()
Find plugin configuration files, and run [plugin] sections through the select method.
static bool checkPlugin(const std::string &name, const std::string &type={})
Checks if a pluigin of the given type is available.
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
static std::string expandFilename(const char *fname)
Simple Readable and Writable object representing a command to a YARP port.
Definition PortCommand.h:24
Client side of the administrative commands defined in PortCoreMsgs.thrift and handled by PortCore::ad...
Reply of PortCoreMsgs::addConnection().
Reply of PortCoreMsgs::delConnection().
Reply of PortCoreMsgs::getConnectionInfoIn() and PortCoreMsgs::getConnectionInfoOut().
Reply of PortCoreMsgs::getConnectionQosIn() and PortCoreMsgs::getConnectionQosOut().
Reply of PortCoreMsgs::setConnectionQosIn() and PortCoreMsgs::setConnectionQosOut().
DumpObj * factory(Bottle &obj)
Definition main.cpp:81
#define yCInfo(component,...)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCTrace(component,...)
#define yCWarning(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:65
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
#define YARP_UNUSED(var)
Definition api.h:162