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;
38
39
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];
203 if (ret == YARPRUN_SEMAPHORE_PARAM) {
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];
260 if (ret == YARPRUN_SEMAPHORE_PARAM) {
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];
313 if (ret == YARPRUN_SEMAPHORE_PARAM) {
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];
368 if (ret == YARPRUN_SEMAPHORE_PARAM) {
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 std::string targetServer = server;
699 if (targetServer[0] != '/') {
700 targetServer = std::string("/") + targetServer;
701 }
702
703 int ret = SendMsg(msg, targetServer, response, 3.0);
704 if((ret == YARPRUN_OK) || (ret == YARPRUN_NORESPONSE))
705 {
706 for(size_t i=0; i<response.size(); i++)
707 {
708 Process proc;
709 if (response.get(i).check("pid")) {
710 proc.pid = response.get(i).find("pid").asInt32();
711 }
712 if (response.get(i).check("tag")) {
713 proc.tag = response.get(i).find("tag").asString();
714 }
715 if (response.get(i).check("status")) {
716 proc.status = response.get(i).find("status").asString();
717 }
718 if (response.get(i).check("cmd")) {
719 proc.command = response.get(i).find("cmd").asString();
720 }
721 if (response.get(i).check("env")) {
722 proc.env = response.get(i).find("env").asString();
723 }
724 processes.push_back(proc);
725 }
726 return true;
727 }
728
729 strError = "cannot ask ";
730 strError += server;
731 strError += " to give the list of running processes.";
732 strError += yarprun_err_msg[ret];
733 if (ret == YARPRUN_SEMAPHORE_PARAM) {
734 strError += std::string(" due to " + __trace_message);
735 }
736 return false;
737}
738
739
740bool YarpBroker::rmconnect(const std::string& from, const std::string& to)
741{
742 std::string topic = from + to;
743 Bottle cmd, reply;
744 cmd.addString("untopic");
745 cmd.addString(topic.c_str());
747 cmd,
748 reply,
749 false,
750 true,
752}
753
754bool YarpBroker::setQos(const std::string& from, const std::string& to, const std::string& qosFrom, const std::string& qosTo)
755{
756 strError.clear();
757
758 if (qosFrom.empty() && qosTo.empty()) {
759 return true;
760 }
761
764 if (qosFrom.empty() == false) {
765 if(!getQosFromString(qosFrom, styleFrom)) {
766 strError = "Error in parsing Qos properties of " + std::string(from);
767 return false;
768 }
769 }
770 if (qosTo.empty() == false) {
771 if(!getQosFromString(qosTo, styleTo)) {
772 strError = "Error in parsing Qos properties of " + std::string(to);
773 return false;
774 }
775 }
776 return NetworkBase::setConnectionQos(from, to, styleFrom, styleTo, true);
777}
778
779bool YarpBroker::getQosFromString(const std::string& qos, yarp::os::QosStyle& style)
780{
781 std::string strQos(qos);
782 transform(strQos.begin(), strQos.end(), strQos.begin(),
783 (int(*)(int))toupper);
784 strQos.erase( std::remove_if( strQos.begin(), strQos.end(), ::isspace ), strQos.end() );
785
786 //level:high; priority:10; policy:1
787 std::stringstream ss(strQos); // Turn the string into a stream.
788 std::string prop;
789 while(getline(ss, prop, ';')) {
790 size_t p = prop.find(':');
791 if (p != prop.npos) {
792 std::string key = prop.substr(0, p);
793 std::string value = prop.substr(p+1);
794 if (key.length() > 0 && value.length() > 0) {
795 if (key == "LEVEL" || key=="DSCP" || key == "TOS") {
796 if (!style.setPacketPriority(prop)) {
797 return false;
798 }
799 }
800 else if (key == "PRIORITY") {
801 char* p;
802 int prio = strtol(value.c_str(), &p, 10);
803 style.setThreadPriority(prio);
804 }
805 else if (key == "POLICY") {
806 char* p;
807 int policy = strtol(value.c_str(), &p, 10);
808 style.setThreadPolicy(policy);
809 }
810 }
811 }
812 }
813 return true;
814}
815
816std::string YarpBroker::error()
817{
818 return strError;
819}
820
821
822bool YarpBroker::timeout(double base, double timeout)
823{
825 if ((SystemClock::nowSystem() - base) > timeout) {
826 return true;
827 }
828 return false;
829}
830
832{
833 if (!strStdioUUID.size()) {
834 return false;
835 }
836
837 std::string strStdioPort = strStdioUUID + "/stdout";
838 stdioPort.open("...");
839
840 double base = SystemClock::nowSystem();
841 ContactStyle style;
842 style.quiet = true;
844 while(!timeout(base, 5.0))
845 {
846 if (NetworkBase::connect(strStdioPort, stdioPort.getName(), style)) {
847 return true;
848 }
849 }
850
851 strError = "Cannot connect to stdio port ";
852 strError += strStdioPort;
853 stdioPort.close();
854 return false;
855}
856
857
859{
860 Bottle *input;
861 if( (input=stdioPort.read(false)) && eventSink)
862 {
863 for (size_t i = 0; i < input->size(); i++) {
864 eventSink->onBrokerStdout(input->get(i).asString().c_str());
865 }
866 }
867}
868
869
871{
872 NetworkBase::disconnect(stdioPort.getName(), strStdioUUID);
873 stdioPort.close();
874}
875
876
877int YarpBroker::SendMsg(Bottle& msg, std::string target, Bottle& response, float fTimeout)
878{
879 if (!exists(target.c_str())) {
881 }
882
883 if (!semParam.check()) {
885 }
886
887 // opening the port
888 yarp::os::Port port;
889 port.setTimeout(fTimeout);
890 if(!port.open("..."))
891 {
892 __trace_message.clear();
893 semParam.post();
895 }
896
897 ContactStyle style;
898 style.quiet = true;
900
901 bool ret;
902 __trace_message = "(SendMsg) connecting to " + std::string(target);
903 for(int i=0; i<10; i++)
904 {
905 ret = NetworkBase::connect(port.getName(), target, style);
906 if (ret) {
907 break;
908 }
910 }
911
912 if(!ret)
913 {
914 port.close();
915 __trace_message.clear();
916 semParam.post();
918 }
919
920 __trace_message = "(SendMsg) writing to " + std::string(target);
921 ret = port.write(msg, response);
922 __trace_message = "(SendMsg) disconnecting from " + std::string(target);
923 NetworkBase::disconnect(port.getName(),target);
924 __trace_message.clear();
925 semParam.post();
926
927 if(!response.size() || !ret) {
928 port.close();
929 return YARPRUN_NORESPONSE;
930 }
931
932 port.close();
933
934 return YARPRUN_OK;
935}
936
937
938int YarpBroker::requestServer(Property& config)
939{
941
942 // USE A YARP RUN SERVER TO MANAGE STDIO
943 //
944 // client -> stdio server -> cmd server
945 //
946 if (config.check("cmd") && config.check("stdio"))
947 {
948 if (config.find("stdio").asString()=="") {return YARPRUN_UNDEF; }
949 if (config.find("cmd").asString()=="") {return YARPRUN_UNDEF; }
950 if (!config.check("as") || config.find("as").asString()=="") { return YARPRUN_UNDEF; }
951 if (!config.check("on") || config.find("on").asString()=="") { return YARPRUN_UNDEF; }
952
953 msg.addList()=config.findGroup("stdio");
954 msg.addList()=config.findGroup("cmd");
955 msg.addList()=config.findGroup("as");
956 msg.addList()=config.findGroup("on");
957
958 if (config.check("workdir")) {
959 msg.addList() = config.findGroup("workdir");
960 }
961 if (config.check("geometry")) {
962 msg.addList() = config.findGroup("geometry");
963 }
964 if (config.check("hold")) {
965 msg.addList() = config.findGroup("hold");
966 }
967 if (config.check("env")) {
968 msg.addList() = config.findGroup("env");
969 }
970
971 Bottle response;
972 int ret = SendMsg(msg, config.find("stdio").asString(),
973 response, CONNECTION_TIMEOUT);
974 if (ret != YARPRUN_OK) {
975 return ret;
976 }
977
978 if (response.size() > 2) {
979 strStdioUUID = response.get(2).asString();
980 }
981
982 return ((response.get(0).asInt32()>0)?YARPRUN_OK:YARPRUN_UNDEF);
983 }
984
985 // DON'T USE A RUN SERVER TO MANAGE STDIO
986 //
987 // client -> cmd server
988 //
989 if (config.check("cmd"))
990 {
991 if (config.find("cmd").asString()=="") { return YARPRUN_UNDEF; }
992 if (!config.check("as") || config.find("as").asString()=="") {return YARPRUN_UNDEF; }
993 if (!config.check("on") || config.find("on").asString()=="") {return YARPRUN_UNDEF; }
994
995 msg.addList()=config.findGroup("cmd");
996 msg.addList()=config.findGroup("as");
997
998 if (config.check("workdir")) {
999 msg.addList() = config.findGroup("workdir");
1000 }
1001 if (config.check("env")) {
1002 msg.addList() = config.findGroup("env");
1003 }
1004
1005 Bottle response;
1006 int ret = SendMsg(msg, config.find("on").asString(),
1007 response, CONNECTION_TIMEOUT);
1008 if (ret != YARPRUN_OK) {
1009 return ret;
1010 }
1011
1012 return ((response.get(0).asInt32()>0)?YARPRUN_OK:YARPRUN_UNDEF);
1013 }
1014
1015 return YARPRUN_UNDEF;
1016}
size_t size_t
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::SystemInfo &info)
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
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:247
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.
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:1456
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 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 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 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
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:395
bool setTimeout(float timeout)
Set a timeout on network operations.
Definition Port.cpp:593
void close() override
Stop port activity.
Definition Port.cpp:330
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:32
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:980
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 class to get the system (platform) status such as available memory, storage, CPU load and etc.
Definition SystemInfo.h:25
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:318
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Value.cpp:312
virtual std::string asString() const
Get string value.
Definition Value.cpp:240
#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