YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RunServer.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/run/Run.h>
14
17
18#include <yarp/os/Network.h>
19#include <yarp/os/Os.h>
20#include <yarp/os/LogStream.h>
21#include <yarp/os/RpcClient.h>
22#include <yarp/os/RpcServer.h>
23#include <yarp/os/Semaphore.h>
24#include <yarp/os/SystemInfo.h>
25#include <yarp/os/Time.h>
26
30
31#include <cstdio>
32#include <string>
33#include <cstring>
34#include <random>
35
37namespace fs = yarp::conf::filesystem;
40
41//This anonymous namespace make this symbol visible only
42//inside this translation unit.
43namespace
44{
45 void sigint_handler(int sig)
46 {
47 YARP_UNUSED(sig);
48 yarp::run::Run::mStresstest=false;
49
50 if (yarp::run::Run::pServerPort)
51 {
52 yarp::os::RpcServer *pClose=yarp::run::Run::pServerPort;
53 yarp::run::Run::pServerPort = nullptr;
54 pClose->close();
55 }
56 //else
57 //{
58 //}
59 }
60}
61
62static yarp::os::Bottle parsePaths(const std::string& txt)
63{
64 yarp::os::Bottle result;
65 const char *at = txt.c_str();
66 int slash_tweak = 0;
67 int len = 0;
68 for (char ch : txt) {
69 if (ch==sep) {
70 result.addString(std::string(at, len-slash_tweak));
71 at += len+1;
72 len = 0;
73 slash_tweak = 0;
74 continue;
75 }
76 slash_tweak = (ch==slash && len>0)?1:0;
77 len++;
78 }
79 if (len>0) {
80 result.addString(std::string(at, len-slash_tweak));
81 }
82 return result;
83}
84
85static bool fileExists(const char *fname)
86{
87 FILE *fp = nullptr;
88 fp = fopen(fname, "r");
89 if (!fp) {
90 return false;
91 } else {
92 fclose(fp);
93 return true;
94 }
95}
96
98// WINDOWS SERVER
99#if defined(_WIN32)
100int yarp::run::Run::server()
101{
102 //yarp::os::Semaphore serializer(1); ///?????unused
103
105
106 if (!port.open(mPortName.c_str()))
107 {
108 yError() << "Yarprun failed to open port: " << mPortName.c_str();
109 return YARPRUN_ERROR;
110 }
111
112 yarp::os::Bottle cmd, reply;
113 cmd.addString("set");
114 cmd.addString(port.getName());
115 cmd.addString("yarprun");
116 cmd.addString("true");
118
119 yInfo() << "Yarprun successfully started on port: " << mPortName.c_str();
120
121 pServerPort=&port;
122
123 yarp::os::impl::signal(SIGINT, sigint_handler);
124 yarp::os::impl::signal(SIGTERM, sigint_handler);
125
126 // Enabling cpu load collector on windows
127 //yarp::os::impl::SystemInfo::enableCpuLoadCollector();
128
129 while (pServerPort)
130 {
132
133 RUNLOG("<<<port.read(msg, true)")
134 if (!port.read(msg, true)) break;
135 RUNLOG(">>>port.read(msg, true)")
136
137 if (!pServerPort) break;
138
139 //printf("<<< %s >>>\n", msg.toString().c_str());
140 //fflush(stdout);
141
143
144 // command with stdio management
145 if (msg.check("stdio"))
146 {
147 std::string strOnPort=msg.find("on").asString();
148 std::string strStdioPort=msg.find("stdio").asString();
149
150 if (strOnPort==mPortName)
151 {
152 std::string strUUID=mPortName+"/"+int2String(getpid())+"/"+msg.find("as").asString()+"-"+int2String(mProcCNT++);
153 yarp::os::Bottle botUUID;
154 botUUID.addString("stdiouuid");
155 botUUID.addString(strUUID.c_str());
156 msg.addList()=botUUID;
157
158 if (mLogged || msg.check("log"))
159 {
160 std::string strAlias=msg.find("as").asString();
161 std::string portName="/log";
162 portName+=mPortName+"/";
163 std::string command = msg.findGroup("cmd").get(1).asString();
164 command = command.substr(0, command.find(' '));
165 command = command.substr(command.find_last_of("\\/") + 1);
166 portName+=command;
167
168 yarp::os::Bottle botFwd;
169 botFwd.addString("forward");
170 botFwd.addString(portName.c_str());
171 if (msg.check("log"))
172 {
173 yarp::os::Bottle botLogger=msg.findGroup("log");
174
175 if (botLogger.size()>1)
176 {
177 botFwd.addString(botLogger.get(1).asString());
178 }
179 else
180 {
181 botFwd.addString(mLoggerPort);
182 }
183 }
184 else
185 {
186 botFwd.addString(mLoggerPort);
187 }
188 msg.addList()=botFwd;
189 }
190
191 yarp::os::Bottle cmdResult;
192 if (executeCmdAndStdio(msg, cmdResult)>0)
193 {
194 if (strStdioPort==mPortName)
195 {
196 yarp::os::Bottle stdioResult;
197 userStdio(msg, stdioResult);
198 cmdResult.append(stdioResult);
199 }
200 else
201 {
202 cmdResult.append(sendMsg(msg, strStdioPort));
203 }
204 }
205
206 port.reply(cmdResult);
207 }
208 else
209 {
210 yarp::os::Bottle stdioResult;
211 userStdio(msg, stdioResult);
212 port.reply(stdioResult);
213 }
214
215 continue;
216 }
217
218 // without stdio
219 if (msg.check("cmd"))
220 {
221 yarp::os::Bottle cmdResult;
222
223 if (msg.check("log"))
224 {
225 yarp::os::Bottle botLogger=msg.findGroup("log");
226
227 if (botLogger.size()>1)
228 {
229 std::string loggerName=botLogger.get(1).asString();
230 executeCmdStdout(msg, cmdResult, loggerName);
231 }
232 else
233 {
234 executeCmdStdout(msg, cmdResult, mLoggerPort);
235 }
236 }
237 else if (mLogged)
238 {
239 executeCmdStdout(msg, cmdResult, mLoggerPort);
240 }
241 else
242 {
243 executeCmd(msg, cmdResult);
244 }
245 port.reply(cmdResult);
246 continue;
247 }
248
249 if (msg.check("kill"))
250 {
251 std::string alias(msg.findGroup("kill").get(1).asString());
252 int sig=msg.findGroup("kill").get(2).asInt32();
253 yarp::os::Bottle result;
254 result.addString(mProcessVector.Signal(alias, sig)?"kill OK":"kill FAILED");
255 port.reply(result);
256 continue;
257 }
258
259 if (msg.check("sigterm"))
260 {
261 std::string alias(msg.find("sigterm").asString());
262 yarp::os::Bottle result;
263 result.addString(mProcessVector.Signal(alias, SIGTERM)?"sigterm OK":"sigterm FAILED");
264 port.reply(result);
265 continue;
266 }
267
268 if (msg.check("sigtermall"))
269 {
270 mProcessVector.Killall(SIGTERM);
271 yarp::os::Bottle result;
272 result.addString("sigtermall OK");
273 port.reply(result);
274 continue;
275 }
276
277 if (msg.check("ps"))
278 {
279 yarp::os::Bottle result;
280 result.append(mProcessVector.PS());
281 port.reply(result);
282 continue;
283 }
284
285 if (msg.check("isrunning"))
286 {
287 std::string alias(msg.find("isrunning").asString());
288 yarp::os::Bottle result;
289 result.addString(mProcessVector.IsRunning(alias)?"running":"not running");
290 port.reply(result);
291 continue;
292 }
293
294 if (msg.check("killstdio"))
295 {
296 std::string alias(msg.find("killstdio").asString());
297 mStdioVector.Signal(alias, SIGTERM);
298 yarp::os::Bottle result;
299 result.addString("killstdio OK");
300 port.reply(result);
301 continue;
302 }
303
305
306 if (msg.check("sysinfo"))
307 {
310 port.reply(sysinfo);
311 continue;
312 }
313
314 if (msg.check("which"))
315 {
316 std::string fileName=msg.find("which").asString();
317 if (fileName!="")
318 {
320 for (int i=0; i<possiblePaths.size(); ++i)
321 {
322 std::string guessString=possiblePaths.get(i).asString() +
323 std::string{slash} + fileName;
324 const char* guess=guessString.c_str();
325 if (fileExists (guess))
326 {
327 fileName= "\"" + std::string(guess) + "\"";
328 break;
329 }
330 }
331 }
332 yarp::os::Value fileNameWriter(fileName);
333 port.reply(fileNameWriter);
334 continue;
335 }
336
337 if (msg.check("exit"))
338 {
339 yInfo() << "Yarprun server closing...";
340 pServerPort=0;
341 yarp::os::Bottle result;
342 result.addString("exit OK");
343 port.reply(result);
344 port.close();
345 }
346 }
347
348
349 Run::mStdioVector.Killall(SIGTERM);
350
351 Run::mProcessVector.Killall(SIGTERM);
352
353 yInfo() << "Yarprun server closed";
354 return 0;
355}
356
358#else // LINUX SERVER
360
361void yarp::run::Run::cleanBeforeExec()
362{
363 // zombie hunter stop
364
365 //yarp::os::impl::signal(SIGPIPE, SIG_IGN);
366 //yarp::os::impl::signal(SIGCHLD, SIG_DFL);
367 //yarp::os::impl::signal(SIGINT, SIG_DFL);
368 //yarp::os::impl::signal(SIGTERM, SIG_DFL);
369
370 if (mProcessVector)
371 {
372 YarpRunInfoVector *p=mProcessVector;
373 mProcessVector = nullptr;
374 delete p;
375 }
376 if (mStdioVector)
377 {
378 YarpRunInfoVector *p=mStdioVector;
379 mStdioVector = nullptr;
380 delete p;
381 }
382 if (mBraveZombieHunter)
383 {
384 ZombieHunterThread *p=mBraveZombieHunter;
385 mBraveZombieHunter = nullptr;
386 p->stop();
387 delete p;
388 }
389
390 //yarp::os::Network::fini();
391}
392
393void yarp::run::Run::writeToPipe(int fd, std::string str)
394{
395 int len = str.length() + 1;
396 int ret;
397 ret = write(fd, &len, sizeof(len));
398 if (ret != sizeof(len)) {
399 fprintf(stderr, "Warning: could not write string length to pipe.\n");
400 }
401 ret = write(fd, str.c_str(), len);
402 if (ret != len) {
403 fprintf(stderr, "Warning: could not write string to pipe.\n");
404 }
405}
406
407int yarp::run::Run::readFromPipe(int fd, char* &data, int& buffsize)
408{
409 int len=0;
410 char* buff=(char*)&len;
411
412 for (int c=4, r=0; c>0; c-=r)
413 {
414 r=read(fd, buff, c);
415
416 if (r < 1) {
417 return -1;
418 }
419
420 buff+=r;
421 }
422
423 if (len <= 0) {
424 return 0;
425 }
426
427 if (len>buffsize)
428 {
429 delete [] data;
430 data=new char[buffsize=1024+(len/1024)*1024];
431 }
432
433 buff=data;
434
435 for (int c=len, r=0; c>0; c-=r)
436 {
437 r=read(fd, buff, c);
438
439 if (r < 1) {
440 return -1;
441 }
442
443 buff+=r;
444 }
445
446 return len;
447}
448
449static void sigchld_handler(int sig)
450{
451 YARP_UNUSED(sig);
452 if (yarp::run::Run::mBraveZombieHunter)
453 {
454 yarp::run::Run::mBraveZombieHunter->sigchldHandler();
455 }
456}
457
458int yarp::run::Run::server()
459{
460 int pipe_server2manager[2];
461 int pipe_manager2server[2];
462
463 if (yarp::run::impl::pipe(pipe_server2manager))
464 {
465 fprintf(stderr, "Can't open pipe because %s\n", strerror(errno));
466 fflush(stderr);
467
468 return YARPRUN_ERROR;
469 }
470
471 if (yarp::run::impl::pipe(pipe_manager2server))
472 {
473 fprintf(stderr, "Can't open pipe because %s\n", strerror(errno));
474 fflush(stderr);
475
476 return YARPRUN_ERROR;
477 }
478
479 int pid_process_manager=yarp::run::impl::fork();
480
481 if (IS_INVALID(pid_process_manager))
482 {
483 int error=errno;
484
485 CLOSE(pipe_server2manager[WRITE_TO_PIPE]);
486 CLOSE(pipe_server2manager[READ_FROM_PIPE]);
487 CLOSE(pipe_manager2server[WRITE_TO_PIPE]);
488 CLOSE(pipe_manager2server[READ_FROM_PIPE]);
489
490 fprintf(stderr, "Can't fork process manager because %s\n", strerror(error));
491 fflush(stderr);
492
493 return YARPRUN_ERROR;
494 }
495
496 if (IS_PARENT_OF(pid_process_manager))
497 {
498 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
499
500 CLOSE(pipe_server2manager[READ_FROM_PIPE]);
501 CLOSE(pipe_manager2server[WRITE_TO_PIPE]);
502
504
505 if (!port.open(mPortName))
506 {
507 yError() << "Yarprun failed to open port: " << mPortName.c_str();
508
509 if (mPortName[0] != '/') {
510 yError("Invalid port name '%s', it should start with '/'\n", mPortName.c_str());
511 }
512 return YARPRUN_ERROR;
513 }
514 yarp::os::Bottle cmd, reply;
515 cmd.addString("set");
516 cmd.addString(port.getName());
517 cmd.addString("yarprun");
518 cmd.addString("true");
519
521
522 yInfo() << "Yarprun successfully started on port: " << mPortName.c_str();
523
524 pServerPort=&port;
525
526 yarp::os::impl::signal(SIGINT, sigint_handler);
527 yarp::os::impl::signal(SIGTERM, sigint_handler);
528
529 int rsp_size=1024;
530 char *rsp_str=new char[rsp_size];
531
532 yarp::os::Bottle msg, response;
533
534 while (pServerPort)
535 {
536 RUNLOG("<<<port.read(msg, true)")
537 if (!port.read(msg, true)) {
538 break;
539 }
540 RUNLOG(">>>port.read(msg, true)")
541
542 if (!pServerPort) {
543 break;
544 }
545
546 if (msg.check("sysinfo"))
547 {
548 yarp::os::SystemInfo sysinfo;
549 sysinfo.updateSystemInfo();
550 port.reply(sysinfo);
551 continue;
552 }
553
554 if (msg.check("which"))
555 {
556 std::string fileName=msg.find("which").asString();
557 if (fileName!="")
558 {
560 for (size_t i=0; i<possiblePaths.size(); ++i)
561 {
562 std::string guessString=possiblePaths.get(i).asString() + slash + fileName;
563 const char* guess=guessString.c_str();
564 if (fileExists (guess))
565 {
566 fileName = guess;
567 break;
568 }
569 }
570 }
571 yarp::os::Value fileNameWriter(fileName);
572 port.reply(fileNameWriter);
573 continue;
574 }
575
576 if (msg.check("exit"))
577 {
578 pServerPort = nullptr;
579 yarp::os::Bottle result;
580 result.addString("exit OK");
581 port.reply(result);
582 port.close();
583 break;
584 }
585
586 RUNLOG("<<<writeToPipe")
587 writeToPipe(pipe_server2manager[WRITE_TO_PIPE], msg.toString());
588 RUNLOG(">>>writeToPipe")
589
590 RUNLOG("<<<readFromPipe")
591 int nread=readFromPipe(pipe_manager2server[READ_FROM_PIPE], rsp_str, rsp_size);
592 RUNLOG(">>>readFromPipe")
593
594 if (nread<0)
595 {
596 fprintf(stderr, "ERROR: broken pipe between server and manager\n");
597 fflush(stderr);
598 break;
599 }
600
601 if (nread)
602 {
603 response.fromString(rsp_str);
604 port.reply(response);
605 }
606 }
607
608 //yarp::os::Network::fini();
609
610 CLOSE(pipe_server2manager[WRITE_TO_PIPE]);
611 CLOSE(pipe_manager2server[READ_FROM_PIPE]);
612
613 delete [] rsp_str;
614
615 return 0;
616 }
617
618 if (IS_NEW_PROCESS(pid_process_manager))
619 {
620 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
621
622 CLOSE(pipe_server2manager[WRITE_TO_PIPE]);
623 CLOSE(pipe_manager2server[READ_FROM_PIPE]);
624
625 //yarp::os::Network::init();
626
627 mProcessVector=new YarpRunInfoVector;
628 mStdioVector=new YarpRunInfoVector;
629
630 mBraveZombieHunter=new ZombieHunterThread;
631 mBraveZombieHunter->start();
632
633 yarp::os::impl::signal(SIGCHLD, sigchld_handler);
634 //yarp::os::impl::signal(SIGINT, SIG_IGN);
635 //yarp::os::impl::signal(SIGTERM, SIG_IGN);
636
637 int msg_size=1024;
638 char *msg_str=new char[msg_size];
639
641
642 //while(readFromPipe(pipe_server2manager[READ_FROM_PIPE], msg_str, msg_size)>0)
643 while (true)
644 {
645 RUNLOG("<<<readFromPipe")
646 if (readFromPipe(pipe_server2manager[READ_FROM_PIPE], msg_str, msg_size) <= 0) {
647 break;
648 }
649 RUNLOG(">>>readFromPipe")
650
651 //printf("<<< %s >>>\n", msg_str);
652 //fflush(stdout);
653
654 msg.fromString(msg_str);
655
656 // command with stdio management
657 if (msg.check("stdio"))
658 {
659 std::string strOnPort=msg.find("on").asString();
660 std::string strStdioPort=msg.find("stdio").asString();
661
662 if (strOnPort==mPortName)
663 {
664 std::string strUUID=mPortName+"/"+int2String(getpid())+"/"+msg.find("as").asString()+"-"+int2String(mProcCNT++);
665 yarp::os::Bottle botUUID;
666 botUUID.addString("stdiouuid");
667 botUUID.addString(strUUID.c_str());
668 msg.addList()=botUUID;
669
670 if (mLogged || msg.check("log"))
671 {
672 std::string strAlias=msg.find("as").asString();
673 std::string portName="/log";
674 portName+=mPortName+"/";
675 std::string command = msg.findGroup("cmd").get(1).asString();
676 command = command.substr(0, command.find(' '));
677 command = command.substr(command.find_last_of("\\/") + 1);
678 portName+=command;
679
680 yarp::os::Bottle botFwd;
681 botFwd.addString("forward");
682 botFwd.addString(portName.c_str());
683 if (msg.check("log"))
684 {
685 yarp::os::Bottle botLogger=msg.findGroup("log");
686
687 if (botLogger.size()>1)
688 {
689 botFwd.addString(botLogger.get(1).asString());
690 }
691 else
692 {
693 botFwd.addString(mLoggerPort);
694 }
695 }
696 else
697 {
698 botFwd.addString(mLoggerPort);
699 }
700 msg.addList()=botFwd;
701
703 style.persistent=true;
704 yarp::os::Network::connect(portName, mLoggerPort, style);
705 }
706
707 yarp::os::Bottle cmdResult;
708 if (executeCmdAndStdio(msg, cmdResult)>0)
709 {
710 if (strStdioPort==mPortName)
711 {
712 yarp::os::Bottle stdioResult;
713 userStdio(msg, stdioResult);
714 cmdResult.append(stdioResult);
715 }
716 else
717 {
718 cmdResult.append(sendMsg(msg, strStdioPort));
719 }
720 }
721
722 RUNLOG("<<<writeToPipe")
723 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], cmdResult.toString());
724 RUNLOG(">>>writeToPipe")
725 }
726 else
727 {
728 yarp::os::Bottle stdioResult;
729 userStdio(msg, stdioResult);
730 RUNLOG("<<<writeToPipe")
731 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], stdioResult.toString());
732 RUNLOG(">>>writeToPipe")
733 }
734
735 continue;
736 }
737
738 // without stdio
739 if (msg.check("cmd"))
740 {
741 yarp::os::Bottle cmdResult;
742
743 if (msg.check("log"))
744 {
745 yarp::os::Bottle botLogger=msg.findGroup("log");
746
747 if (botLogger.size()>1)
748 {
749 std::string loggerName=botLogger.get(1).asString();
750 executeCmdStdout(msg, cmdResult, loggerName);
751 }
752 else
753 {
754 executeCmdStdout(msg, cmdResult, mLoggerPort);
755 }
756 }
757 else if (mLogged)
758 {
759 executeCmdStdout(msg, cmdResult, mLoggerPort);
760 }
761 else
762 {
763 executeCmd(msg, cmdResult);
764 }
765
766 RUNLOG("<<<writeToPipe")
767 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], cmdResult.toString());
768 RUNLOG(">>>writeToPipe")
769 continue;
770 }
771
772 if (msg.check("kill"))
773 {
774 std::string alias(msg.findGroup("kill").get(1).asString());
775 int sig=msg.findGroup("kill").get(2).asInt32();
776 yarp::os::Bottle result;
777 result.addString(mProcessVector->Signal(alias, sig)?"kill OK":"kill FAILED");
778 RUNLOG("<<<writeToPipe")
779 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
780 RUNLOG(">>>writeToPipe")
781 continue;
782 }
783
784 if (msg.check("sigterm"))
785 {
786 std::string alias(msg.find("sigterm").asString());
787 yarp::os::Bottle result;
788 result.addString(mProcessVector->Signal(alias, SIGTERM)?"sigterm OK":"sigterm FAILED");
789 RUNLOG("<<<writeToPipe")
790 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
791 RUNLOG(">>>writeToPipe")
792 continue;
793 }
794
795 if (msg.check("sigtermall"))
796 {
797 mProcessVector->Killall(SIGTERM);
798 yarp::os::Bottle result;
799 result.addString("sigtermall OK");
800
801 RUNLOG("<<<writeToPipe")
802 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
803 RUNLOG(">>>writeToPipe")
804 continue;
805 }
806
807 if (msg.check("ps"))
808 {
809 yarp::os::Bottle result;
810 result.append(mProcessVector->PS());
811 RUNLOG("<<<writeToPipe")
812 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
813 RUNLOG(">>>writeToPipe")
814 continue;
815 }
816
817 if (msg.check("isrunning"))
818 {
819 std::string alias(msg.find("isrunning").asString());
820 yarp::os::Bottle result;
821 result.addString(mProcessVector->IsRunning(alias)?"running":"not running");
822 RUNLOG("<<<writeToPipe")
823 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
824 RUNLOG(">>>writeToPipe")
825 continue;
826 }
827
828 if (msg.check("killstdio"))
829 {
830 std::string alias(msg.find("killstdio").asString());
831 mStdioVector->Signal(alias, SIGTERM);
832 yarp::os::Bottle result;
833 result.addString("killstdio OK");
834 RUNLOG("<<<writeToPipe")
835 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
836 RUNLOG(">>>writeToPipe")
837 continue;
838 }
839 }
840
841 mStdioVector->Killall(SIGTERM);
842
843 mProcessVector->Killall(SIGTERM);
844
845 if (mBraveZombieHunter)
846 {
847 mBraveZombieHunter->stop();
848 delete mBraveZombieHunter;
849 mBraveZombieHunter = nullptr;
850 }
851
852 delete mProcessVector;
853
854 delete mStdioVector;
855
856 //yarp::os::Network::fini();
857
858 CLOSE(pipe_server2manager[READ_FROM_PIPE]);
859 CLOSE(pipe_manager2server[WRITE_TO_PIPE]);
860
861 delete [] msg_str;
862 }
863
864 return 0;
865} // LINUX SERVER
866#endif
std::string toString(const T &value)
convert an arbitrary type to string.
#define yInfo(...)
Definition Log.h:319
#define yError(...)
Definition Log.h:361
#define RUNLOG(msg)
int CLOSE(int h)
#define YARPRUN_ERROR
std::string int2String(int x)
static yarp::os::Bottle parsePaths(const std::string &txt)
Definition RunServer.cpp:62
constexpr fs::value_type slash
Definition RunServer.cpp:39
constexpr auto sep
Definition RunServer.cpp:38
static bool fileExists(const char *fname)
Definition RunServer.cpp:85
static void sigchld_handler(int sig)
Definition Run.cpp:457
bool reply(PortWriter &writer) override
Send an object as a reply to an object read from the port.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
std::string getName() const override
Get name of port.
void close() override
Stop port activity.
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:205
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Definition Bottle.cpp:354
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition Bottle.cpp:188
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
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
Definition Bottle.cpp:294
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:278
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:176
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition Bottle.cpp:288
A mini-server for performing network communication in the background.
Preferences for how to communicate with a contact.
bool persistent
Specify whether a requested connection should be persistent.
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
A port that is specialized as an RPC server.
Definition RpcServer.h:23
A class to get the system (platform) status such as available memory, storage, CPU load and etc.
Definition SystemInfo.h:25
void updateSystemInfo()
updates the system information by calling the static methods to retrieve the latest data.
bool stop()
Stop the thread.
Definition Thread.cpp:81
bool start()
Start the new thread running.
Definition Thread.cpp:93
A single value (typically within a Bottle).
Definition Value.h:44
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
virtual std::string asString() const
Get string value.
Definition Value.cpp:240
static NameClient & getNameClient()
Get an instance of the name client.
static bool sysinfo(const std::string &node, yarp::os::SystemInfo &info)
Get a report of system information of a yarprun server.
#define WRITE_TO_PIPE
#define READ_FROM_PIPE
static constexpr char path_separator
Definition environment.h:27
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
Definition environment.h:65
static constexpr value_type preferred_separator
Definition filesystem.h:21
int getpid()
Portable wrapper for the getppid() function.
Definition Os.cpp:84
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
#define YARP_UNUSED(var)
Definition api.h:162