YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarpbroker.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
8#include <csignal>
9#include <cstring>
10
11#define YARPRUN_OK 0
12#define YARPRUN_NORESPONSE 1
13#define YARPRUN_NOCONNECTION 2
14#define YARPRUN_CONNECTION_TIMOUT 3
15#define YARPRUN_SEMAPHORE_PARAM 4
16#define YARPRUN_UNDEF 5
17
18#define CONNECTION_TIMEOUT 2.0 //seconds
19#define RUN_TIMEOUT 10.0 //seconds
20#define STOP_TIMEOUT 15.0
21#define KILL_TIMEOUT 10.0
22#define EVENT_THREAD_PERIOD 0.5 //seconds
23
24#if defined(_WIN32)
25 #define SIGKILL 9
26#endif
27
28const char* yarprun_err_msg[] = { " (Ok) ",
29 " (Remote host does not respond) ",
30 " (Remote host does no exist) ",
31 " (Timeout while connecting to the remote host) ",
32 " (Blocked in broker semaphor) ",
33 " (Undefined message) " };
34
35using namespace yarp::os;
36using namespace yarp::os::impl;
37using namespace yarp::manager;
41{
42 bOnlyConnector = bInitialized = false;
43 ID = generateID();
44 strStdioUUID.clear();
45}
46
47
52
54{
57 }
58 //port.close();
59}
60
62{
63 //if(bInitialized)
64 // return true;
65
67 {
68 strError = "YARP network server is not up.";
69 return false;
70 }
71 bInitialized = true;
72 bOnlyConnector = true;
73
74 /*
75 semParam.wait();
76 __trace_message = "(init) opening port ...";
77 port.setTimeout(CONNECTION_TIMEOUT);
78 port.open("...");
79 __trace_message.clear();
80 semParam.post();
81 */
82 return true;
83}
84
85bool YarpBroker::init(const char* szcmd, const char* szparam,
86 const char* szhost, const char* szstdio,
87 const char* szworkdir, const char* szenv )
88{
89 //if(bInitialized)
90 // return true;
91
92 semParam.wait();
93
94 strCmd.clear();
95 strParam.clear();
96 strHost.clear();
97 strStdio.clear();
98 strWorkdir.clear();
99 strTag.clear();
100 strEnv.clear();
101
102 if(!szcmd)
103 {
104 strError = "command is not specified.";
105 semParam.post();
106 return false;
107 }
108
109 if(!szhost)
110 {
111 strError = "remote host port is not specified.";
112 semParam.post();
113 return false;
114 }
115
116 if (szhost[0] != '/') {
117 strHost = std::string("/") + std::string(szhost);
118 } else {
119 strHost = szhost;
120 }
121
122 strCmd = szcmd;
123 if (strlen(szparam)) {
124 strParam = szparam;
125 }
126 if (strlen(szworkdir)) {
127 strWorkdir = szworkdir;
128 }
129
130 if(strlen(szstdio))
131 {
132 if (szstdio[0] != '/') {
133 strStdio = std::string("/") + std::string(szstdio);
134 } else {
135 strStdio = szstdio;
136 }
137 }
138
139 if (strlen(szenv)) {
140 strEnv = szenv;
141 }
142
144 sstrID<<(int)ID;
145 strTag = strHost + strCmd + strParam + strEnv + sstrID.str();
146 std::string::iterator itr;
147 for (itr = strTag.begin(); itr != strTag.end(); itr++) {
148 if (((*itr) == ' ') || ((*itr) == '/')) {
149 (*itr) = ':';
150 }
151 }
152
153 __trace_message = "(init) checking yarp network";
155 {
156 strError = "YARP network server is not up.";
157 __trace_message.clear();
158 semParam.post();
159 return false;
160 }
161 __trace_message = std::string("(init) checking existence of ") + strHost;
162 if(!exists(strHost.c_str()))
163 {
164 strError = szhost;
165 strError += " does not exist. check yarprun is running as server.";
166 __trace_message.clear();
167 semParam.post();
168 return false;
169 }
170
171 /*
172 port.setTimeout(CONNECTION_TIMEOUT);
173 __trace_message = "(init) opening port ...";
174 port.open("...");
175 __trace_message.clear();
176 */
177
178 bInitialized = true;
179 semParam.post();
180
181 return true;
182}
183
184
186{
187 if (!bInitialized) {
188 return false;
189 }
190 if (bOnlyConnector) {
191 return false;
192 }
193
194 strError.clear();
195 int ret = requestServer(runProperty());
196 if(ret != YARPRUN_OK)
197 {
198 strError = "cannot ask ";
199 strError += strHost;
200 strError += " to run ";
201 strError += strCmd;
202 strError += yarprun_err_msg[ret];
204 strError += std::string(" due to " + __trace_message);
205 }
206 return false;
207 }
208
209 double base = SystemClock::nowSystem();
210 while(!timeout(base, RUN_TIMEOUT))
211 {
212 if(running() == 1)
213 {
214 if(strStdioUUID.size())
215 {
218 }
220 }
221 return true;
222 }
223 }
224
225 strError = "cannot run ";
226 strError += strCmd;
227 strError += " on ";
228 strError += strHost;
229 return false;
230}
231
233{
234 if (!bInitialized) {
235 return true;
236 }
237 if (bOnlyConnector) {
238 return false;
239 }
240
241 strError.clear();
242 yarp::os::Bottle msg,grp,response;
243
244 grp.clear();
245 grp.addString("on");
246 grp.addString(strHost.c_str());
247 msg.addList()=grp;
248 grp.clear();
249 grp.addString("sigterm");
250 grp.addString(strTag.c_str());
251 msg.addList()=grp;
252 int ret = SendMsg(msg, strHost, response, CONNECTION_TIMEOUT);
253 if(ret != YARPRUN_OK)
254 {
255 strError = "cannot ask ";
256 strError += strHost;
257 strError += " to stop ";
258 strError += strCmd;
259 strError += yarprun_err_msg[ret];
261 strError += std::string(" due to " + __trace_message);
262 }
263 return false;
264 }
265
266 double base = SystemClock::nowSystem();
267 while(!timeout(base, STOP_TIMEOUT))
268 {
269 if(running() == 0)
270 {
272 return true;
273 }
274 }
275
276 strError = "Timeout! Cannot stop ";
277 strError += strCmd;
278 strError += " on ";
279 strError += strHost;
281 return false;
282}
283
285{
286 if (!bInitialized) {
287 return true;
288 }
289 if (bOnlyConnector) {
290 return false;
291 }
292
293 strError.clear();
294
295 yarp::os::Bottle msg,grp,response;
296 grp.clear();
297 grp.addString("on");
298 grp.addString(strHost.c_str());
299 msg.addList() = grp;
300 grp.clear();
301 grp.addString("kill");
302 grp.addString(strTag.c_str());
303 grp.addInt32(SIGKILL);
304 msg.addList() = grp;
305 int ret = SendMsg(msg, strHost, response, CONNECTION_TIMEOUT);
306 if(ret != YARPRUN_OK)
307 {
308 strError = "cannot ask ";
309 strError += strHost;
310 strError += " to kill ";
311 strError += strCmd;
312 strError += yarprun_err_msg[ret];
314 strError += std::string(" due to " + __trace_message);
315 }
316 return false;
317 }
318
319 double base = SystemClock::nowSystem();
320 while(!timeout(base, KILL_TIMEOUT))
321 {
322 if(running() == 0)
323 {
325 return true;
326 }
327 }
328
329 strError = "cannot kill ";
330 strError += strCmd;
331 strError += " on ";
332 strError += strHost;
334 return false;
335}
336
337
339{
340 if (!bInitialized) {
341 return -1;
342 }
343 if (bOnlyConnector) {
344 return -1;
345 }
346
347 strError.clear();
348 yarp::os::Bottle msg,grp,response;
349
350 grp.clear();
351 grp.addString("on");
352 grp.addString(strHost.c_str());
353 msg.addList()=grp;
354
355 grp.clear();
356 grp.addString("isrunning");
357 grp.addString(strTag.c_str());
358 msg.addList()=grp;
359
360 int ret = SendMsg(msg, strHost, response, 3.0);
361 if(ret != YARPRUN_OK)
362 {
363 strError = "cannot ask ";
364 strError += strHost;
365 strError += " to check for status of ";
366 strError += strCmd;
367 strError += yarprun_err_msg[ret];
369 strError += std::string(" due to " + __trace_message);
370 }
371 return -1;
372 }
373 return ((response.get(0).asString() == "running")?1:0);
374}
375
376
378{
379 return true;
380}
381
385
386
387Property& YarpBroker::runProperty()
388{
389 command.clear();
390 std::string cmd = strCmd + std::string(" ") + strParam;
391 command.put("cmd", cmd);
392 command.put("on", strHost);
393 command.put("as", strTag);
394 if (!strWorkdir.empty()) {
395 command.put("workdir", strWorkdir);
396 }
397 if (!strStdio.empty()) {
398 command.put("stdio", strStdio);
399 }
400 if (!strEnv.empty()) {
401 command.put("env", strEnv);
402 }
403 //command.put("hold", "hold");
404 return command;
405}
406
407
411bool YarpBroker::connect(const std::string& from, const std::string& to, const std::string& carrier, bool persist)
412{
413 if(from.empty())
414 {
415 strError = "no source port is introduced.";
416 return false;
417 }
418
419 if(to.empty())
420 {
421 strError = "no destination port is introduced.";
422 return false;
423 }
424
425 ContactStyle style;
426 style.quiet = true;
428 style.carrier = carrier;
429
430 if(!persist)
431 {
432 /*
433 * TODO: this check should be removed and
434 * the necessary modification should be done inside NetworkBase::isConnected!!!
435 */
436 std::string strCarrier = carrier;
437 bool needDisconnect = strCarrier.find("udp") == (size_t)0;
438 needDisconnect |= strCarrier.find("mcast") == (size_t)0;
439 if(needDisconnect == false) {
440 if (NetworkBase::isConnected(from, to, style)) {
441 return true;
442 }
443 }
444
445 NetworkBase::connect(from, to, style);
446 if(!connected(from, to, carrier))
447 {
448 strError = "cannot connect ";
449 strError +=from;
450 strError += " to " + std::string(to);
451 return false;
452 }
453 }
454 else
455 {
456 std::string topic = std::string("topic:/") + std::string(from) + std::string(to);
457 NetworkBase::connect(from, topic, style);
458 NetworkBase::connect(topic, to, style);
459 if(!connected(from, to, carrier))
460 {
461 strError = "a persistent connection from ";
462 strError +=from;
463 strError += " to " + std::string(to);
464 strError += " is created but not connected.";
465 return false;
466 }
467
468 }
469
470 return true;
471}
472
473bool YarpBroker::disconnect(const std::string& from, const std::string& to, const std::string& carrier)
474{
475
476 if(from.empty())
477 {
478 strError = "no source port is introduced.";
479 return false;
480 }
481
482 if(to.empty())
483 {
484 strError = "no destination port is introduced.";
485 return false;
486 }
487
488 /*
489 if(!exists(from))
490 {
491 strError = from;
492 strError += " does not exist.";
493 return true;
494 }
495
496 if(!exists(to))
497 {
498 strError = to;
499 strError += " does not exist.";
500 return true;
501 }
502 */
503
504 if (!connected(from, to, carrier)) {
505 return true;
506 }
507
508 ContactStyle style;
509 style.quiet = true;
511 style.carrier = carrier;
512 if(!NetworkBase::disconnect(from, to, style))
513 {
514 strError = "cannot disconnect ";
515 strError +=from;
516 strError += " from " + std::string(to);
517 return false;
518 }
519 return true;
520
521}
522
523bool YarpBroker::exists(const std::string& szport)
524{
525 ContactStyle style;
526 style.quiet = true;
528 return NetworkBase::exists(szport, style);
529}
530
531std::string YarpBroker::requestRpc(const std::string& szport, const std::string& request, double timeout)
532{
533 if (szport.empty() || request.empty()) {
534 return {};
535 }
536
537 if (!exists(szport)) {
538 return {};
539 }
540
541 // opening the port
542 yarp::os::Port port;
543 port.setTimeout((float)((timeout>0.0) ? timeout : CONNECTION_TIMEOUT));
544 if (!port.open("...")) {
545 return {};
546 }
547
548 ContactStyle style;
549 style.quiet = true;
550 style.timeout = (timeout>0.0) ? timeout : CONNECTION_TIMEOUT;
551 bool ret;
552 for(int i=0; i<10; i++) {
553 ret = NetworkBase::connect(port.getName(), szport, style);
554 if (ret) {
555 break;
556 }
558 }
559
560 if(!ret) {
561 port.close();
562 return {};
563 }
564
565 Bottle msg, response;
566 msg.fromString(request);
567 ret = port.write(msg, response);
569 if(!response.size() || !ret) {
570 port.close();
571 return {};
572 }
573
574 port.close();
575 return response.toString().c_str();
576}
577
578bool YarpBroker::connected(const std::string& from, const std::string& to, const std::string& carrier)
579{
580 if (!exists(from) || !exists(to)) {
581 return false;
582 }
583 ContactStyle style;
584 style.quiet = true;
586 style.carrier = carrier;
587 return NetworkBase::isConnected(from, to, style);
588}
589
591{
592 if (server.empty()) {
593 return false;
594 }
595 if (!semParam.check()) {
596 return false;
597 }
598
599 yarp::os::Port port;
600 // opening the port
602 if(!port.open("...")) {
603 __trace_message.clear();
604 semParam.post();
605 return false;
606 }
607
609 grp.clear();
610 grp.addString("sysinfo");
611 msg.addList() = grp;
612
613 ContactStyle style;
614 style.quiet = true;
616 //style.carrier = carrier;
617
618
619 __trace_message = "(getSystemInfo) connecting to " + std::string(port.getName());
621 if(!connected)
622 {
623 port.close();
624 strError = std::string("Cannot connect to ") + std::string(server);
625 __trace_message.clear();
626 semParam.post();
627 return false;
628 }
629
630 __trace_message = "(getSystemInfo) writing to " + std::string(port.getName());
631 bool ret = port.write(msg, info);
632 __trace_message = "(getSystemInfo) disconnecting from " + std::string(port.getName());
634
635 if(!ret)
636 {
637 port.close();
638 strError = std::string(server) + std::string(" does not respond");
639 __trace_message.clear();
640 semParam.post();
641 return false;
642 }
643
644 port.close();
645 __trace_message.clear();
646 semParam.post();
647 return true;
648}
649
650bool YarpBroker::getAllPorts(std::vector<std::string> &ports)
651{
652 ContactStyle style;
653 style.quiet = true;
655 Bottle cmd, reply;
656 cmd.addString("list");
657
658 bool ret = NetworkBase::writeToNameServer(cmd, reply, style);
659 if (!ret)
660 {
661 strError = "Failed to reach name server\n";
662 return false;
663 }
664
665 if ((reply.size() != 1) || (!reply.get(0).isString())) {
666 return false;
667 }
668
669 std::string str = reply.get(0).asString();
670 const char* delm = "registration name ";
671 size_t pos1, pos2;
672 while((pos1 = str.find(delm)) != std::string::npos)
673 {
674 str = str.substr(pos1+strlen(delm));
675 if ((pos2 = str.find(' ')) != std::string::npos) {
676 ports.push_back(str.substr(0, pos2));
677 }
678 }
679
680 return true;
681}
682
683bool YarpBroker::getAllProcesses(const std::string& server,
684 ProcessContainer& processes)
685{
686 if (server.empty()) {
687 return false;
688 }
689
690 processes.clear();
691 strError.clear();
692 yarp::os::Bottle msg,grp,response;
693
694 grp.clear();
695 grp.addString("ps");
696 msg.addList()=grp;
697
698 int ret = SendMsg(msg, server, response, 3.0);
699 if((ret == YARPRUN_OK) || (ret == YARPRUN_NORESPONSE))
700 {
701 for(size_t i=0; i<response.size(); i++)
702 {
703 Process proc;
704 std::string sprc;
705 if (response.get(i).check("pid")) {
706 proc.pid = response.get(i).find("pid").asInt32();
707 }
708 if (response.get(i).check("cmd")) {
709 sprc = response.get(i).find("cmd").asString();
710 }
711 if (response.get(i).check("env") && response.get(i).find("env").asString().length()) {
712 sprc.append("; ").append(response.get(i).find("env").asString());
713 }
714 proc.command = sprc;
715 processes.push_back(proc);
716 }
717 return true;
718 }
719
720 strError = "cannot ask ";
721 strError += server;
722 strError += " to give the list of running processes.";
723 strError += yarprun_err_msg[ret];
725 strError += std::string(" due to " + __trace_message);
726 }
727 return false;
728}
729
730
731bool YarpBroker::rmconnect(const std::string& from, const std::string& to)
732{
733 std::string topic = from + to;
734 Bottle cmd, reply;
735 cmd.addString("untopic");
736 cmd.addString(topic.c_str());
738 cmd,
739 reply,
740 false,
741 true,
743}
744
745bool YarpBroker::setQos(const std::string& from, const std::string& to, const std::string& qosFrom, const std::string& qosTo)
746{
747 strError.clear();
748
749 if (qosFrom.empty() && qosTo.empty()) {
750 return true;
751 }
752
755 if (qosFrom.empty() == false) {
756 if(!getQosFromString(qosFrom, styleFrom)) {
757 strError = "Error in parsing Qos properties of " + std::string(from);
758 return false;
759 }
760 }
761 if (qosTo.empty() == false) {
762 if(!getQosFromString(qosTo, styleTo)) {
763 strError = "Error in parsing Qos properties of " + std::string(to);
764 return false;
765 }
766 }
767 return NetworkBase::setConnectionQos(from, to, styleFrom, styleTo, true);
768}
769
770bool YarpBroker::getQosFromString(const std::string& qos, yarp::os::QosStyle& style)
771{
772 std::string strQos(qos);
773 transform(strQos.begin(), strQos.end(), strQos.begin(),
774 (int(*)(int))toupper);
775 strQos.erase( std::remove_if( strQos.begin(), strQos.end(), ::isspace ), strQos.end() );
776
777 //level:high; priority:10; policy:1
778 std::stringstream ss(strQos); // Turn the string into a stream.
779 std::string prop;
780 while(getline(ss, prop, ';')) {
781 size_t p = prop.find(':');
782 if (p != prop.npos) {
783 std::string key = prop.substr(0, p);
784 std::string value = prop.substr(p+1);
785 if (key.length() > 0 && value.length() > 0) {
786 if (key == "LEVEL" || key=="DSCP" || key == "TOS") {
787 if (!style.setPacketPriority(prop)) {
788 return false;
789 }
790 }
791 else if (key == "PRIORITY") {
792 char* p;
793 int prio = strtol(value.c_str(), &p, 10);
794 style.setThreadPriority(prio);
795 }
796 else if (key == "POLICY") {
797 char* p;
798 int policy = strtol(value.c_str(), &p, 10);
799 style.setThreadPolicy(policy);
800 }
801 }
802 }
803 }
804 return true;
805}
806
807std::string YarpBroker::error()
808{
809 return strError;
810}
811
812
813bool YarpBroker::timeout(double base, double timeout)
814{
816 if ((SystemClock::nowSystem() - base) > timeout) {
817 return true;
818 }
819 return false;
820}
821
823{
824 if (!strStdioUUID.size()) {
825 return false;
826 }
827
828 std::string strStdioPort = strStdioUUID + "/stdout";
829 stdioPort.open("...");
830
831 double base = SystemClock::nowSystem();
832 ContactStyle style;
833 style.quiet = true;
835 while(!timeout(base, 5.0))
836 {
837 if (NetworkBase::connect(strStdioPort, stdioPort.getName(), style)) {
838 return true;
839 }
840 }
841
842 strError = "Cannot connect to stdio port ";
843 strError += strStdioPort;
844 stdioPort.close();
845 return false;
846}
847
848
850{
851 Bottle *input;
852 if( (input=stdioPort.read(false)) && eventSink)
853 {
854 for (size_t i = 0; i < input->size(); i++) {
855 eventSink->onBrokerStdout(input->get(i).asString().c_str());
856 }
857 }
858}
859
860
862{
863 NetworkBase::disconnect(stdioPort.getName(), strStdioUUID);
864 stdioPort.close();
865}
866
867
868int YarpBroker::SendMsg(Bottle& msg, std::string target, Bottle& response, float fTimeout)
869{
870 if (!exists(target.c_str())) {
872 }
873
874 if (!semParam.check()) {
876 }
877
878 // opening the port
879 yarp::os::Port port;
880 port.setTimeout(fTimeout);
881 if(!port.open("..."))
882 {
883 __trace_message.clear();
884 semParam.post();
886 }
887
888 ContactStyle style;
889 style.quiet = true;
891
892 bool ret;
893 __trace_message = "(SendMsg) connecting to " + std::string(target);
894 for(int i=0; i<10; i++)
895 {
896 ret = NetworkBase::connect(port.getName(), target, style);
897 if (ret) {
898 break;
899 }
901 }
902
903 if(!ret)
904 {
905 port.close();
906 __trace_message.clear();
907 semParam.post();
909 }
910
911 __trace_message = "(SendMsg) writing to " + std::string(target);
912 ret = port.write(msg, response);
913 __trace_message = "(SendMsg) disconnecting from " + std::string(target);
914 NetworkBase::disconnect(port.getName(),target);
915 __trace_message.clear();
916 semParam.post();
917
918 if(!response.size() || !ret) {
919 port.close();
920 return YARPRUN_NORESPONSE;
921 }
922
923 port.close();
924
925 return YARPRUN_OK;
926}
927
928
929int YarpBroker::requestServer(Property& config)
930{
932
933 // USE A YARP RUN SERVER TO MANAGE STDIO
934 //
935 // client -> stdio server -> cmd server
936 //
937 if (config.check("cmd") && config.check("stdio"))
938 {
939 if (config.find("stdio").asString()=="") {return YARPRUN_UNDEF; }
940 if (config.find("cmd").asString()=="") {return YARPRUN_UNDEF; }
941 if (!config.check("as") || config.find("as").asString()=="") { return YARPRUN_UNDEF; }
942 if (!config.check("on") || config.find("on").asString()=="") { return YARPRUN_UNDEF; }
943
944 msg.addList()=config.findGroup("stdio");
945 msg.addList()=config.findGroup("cmd");
946 msg.addList()=config.findGroup("as");
947 msg.addList()=config.findGroup("on");
948
949 if (config.check("workdir")) {
950 msg.addList() = config.findGroup("workdir");
951 }
952 if (config.check("geometry")) {
953 msg.addList() = config.findGroup("geometry");
954 }
955 if (config.check("hold")) {
956 msg.addList() = config.findGroup("hold");
957 }
958 if (config.check("env")) {
959 msg.addList() = config.findGroup("env");
960 }
961
962 Bottle response;
963 int ret = SendMsg(msg, config.find("stdio").asString(),
964 response, CONNECTION_TIMEOUT);
965 if (ret != YARPRUN_OK) {
966 return ret;
967 }
968
969 if (response.size() > 2) {
970 strStdioUUID = response.get(2).asString();
971 }
972
973 return ((response.get(0).asInt32()>0)?YARPRUN_OK:YARPRUN_UNDEF);
974 }
975
976 // DON'T USE A RUN SERVER TO MANAGE STDIO
977 //
978 // client -> cmd server
979 //
980 if (config.check("cmd"))
981 {
982 if (config.find("cmd").asString()=="") { return YARPRUN_UNDEF; }
983 if (!config.check("as") || config.find("as").asString()=="") {return YARPRUN_UNDEF; }
984 if (!config.check("on") || config.find("on").asString()=="") {return YARPRUN_UNDEF; }
985
986 msg.addList()=config.findGroup("cmd");
987 msg.addList()=config.findGroup("as");
988
989 if (config.check("workdir")) {
990 msg.addList() = config.findGroup("workdir");
991 }
992 if (config.check("env")) {
993 msg.addList() = config.findGroup("env");
994 }
995
996 Bottle response;
997 int ret = SendMsg(msg, config.find("on").asString(),
998 response, CONNECTION_TIMEOUT);
999 if (ret != YARPRUN_OK) {
1000 return ret;
1001 }
1002
1003 return ((response.get(0).asInt32()>0)?YARPRUN_OK:YARPRUN_UNDEF);
1004 }
1005
1006 return YARPRUN_UNDEF;
1007}
size_t size_t
bool ret
virtual void onBrokerStdout(const char *msg)
Definition broker.h:22
BrokerEventSink * eventSink
Definition broker.h:65
unsigned int generateID()
Definition broker.cpp:26
bool rmconnect(const std::string &from, const std::string &to)
void threadRelease() override
Release method.
bool getAllPorts(std::vector< std::string > &stingList)
bool connected(const std::string &from, const std::string &to, const std::string &carrier) override
std::string requestRpc(const std::string &szport, const std::string &request, double timeout) override
void detachStdout() override
bool setQos(const std::string &from, const std::string &to, const std::string &qosFrom, const std::string &qosTo)
bool connect(const std::string &from, const std::string &to, const std::string &carrier, bool persist=false) override
connection broker
bool getAllProcesses(const std::string &server, ProcessContainer &processes)
bool threadInit() override
Initialization method.
std::string error() override
bool disconnect(const std::string &from, const std::string &to, const std::string &carrier) override
bool exists(const std::string &port) override
void run() override
Loop function.
bool attachStdout() override
bool getSystemInfo(const std::string &server, yarp::os::SystemInfoSerializer &info)
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void fromString(const std::string &text)
Initializes bottle from a string.
Definition Bottle.cpp:204
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
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
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
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.
T * read(bool shouldWait=true) override
Read an available object from the port.
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.
virtual std::string getName() const
Get name of port.
static Contact getNameServerContact()
Get the contact information for the port associated with the nameserver (usually "/root",...
Definition Network.cpp:1353
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 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 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 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
An abstraction for a periodic thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
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
bool setTimeout(float timeout)
Set a timeout on network operations.
Definition Port.cpp:634
void close() override
Stop port activity.
Definition Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void clear()
Remove all associations.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
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
bool setPacketPriority(const std::string &priority)
sets the packet priority from a string.
Definition QosStyle.cpp:39
void setThreadPolicy(int policy)
sets the communication thread scheduling policy
Definition QosStyle.h:137
void wait()
Decrement the counter, even if we must wait to do that.
Definition Semaphore.cpp:96
bool check()
Decrement the counter, unless that would require waiting.
void post()
Increment the counter.
static double nowSystem()
static void delaySystem(double seconds)
A helper class to pass the SystemInfo object around the YARP network.
virtual bool isString() const
Checks if value is a string.
Definition Value.cpp:156
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition Value.cpp:327
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Value.cpp:321
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
#define KILL_TIMEOUT
#define CONNECTION_TIMEOUT
#define RUN_TIMEOUT
#define STOP_TIMEOUT
std::stringstream OSTRINGSTREAM
Definition utility.h:50
std::vector< Process > ProcessContainer
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
#define YARPRUN_UNDEF
#define YARPRUN_CONNECTION_TIMOUT
#define YARPRUN_NORESPONSE
#define YARPRUN_NOCONNECTION
#define YARPRUN_SEMAPHORE_PARAM
const char * yarprun_err_msg[]
#define YARPRUN_OK
#define EVENT_THREAD_PERIOD