YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
localbroker.h
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
6#ifndef YARP_MANAGER_LOCALBROKER
7#define YARP_MANAGER_LOCALBROKER
8
9#include <cstdio>
10#include <string>
11#include <iostream>
12
13#include <yarp/os/Time.h>
14#include <yarp/os/Port.h>
16#include <yarp/os/Network.h>
17#include <yarp/os/Property.h>
18#include <string>
20#include <yarp/os/Thread.h>
21
22#include <yarp/manager/broker.h>
23
24#if defined(_WIN32)
25 #include<Windows.h>
26#endif
27
28namespace yarp::manager {
29
33class LocalBroker: public Broker, public yarp::os::Thread {
34
35public:
36
37 typedef enum { WINDOW_HIDDEN=0, //window is hidden, catch stdout
38 WINDOW_VISIBLE=1, //window is visible
39 WINDOW_MINIMIZED=2 //window is started minimized
41
42
44 virtual ~LocalBroker();
45 bool init() override;
46 bool init(const char* szcmd, const char* szparam,
47 const char* szhost, const char* szstdio,
48 const char* szworkdir, const char* szenv) override;
49 void fini() override;
50 bool start() override;
51 bool stop() override;
52 bool kill() override;
53 bool connect(const std::string& from, const std::string& to, const std::string& carrier, bool persist = false) override;
54 bool disconnect(const std::string& from, const std::string& to, const std::string& carrier) override;
55 int running() override;
56 bool exists(const std::string& port) override;
57 std::string requestRpc(const std::string& szport, const std::string& request, double timeout) override;
58 bool connected(const std::string& from, const std::string& to, const std::string& carrier) override;
59 std::string error() override;
60 bool initialized() override { return bInitialized;}
61 bool attachStdout() override;
62 void detachStdout() override;
63
66
67public: // for rate thread
68 void run() override;
69 bool threadInit() override;
70 void threadRelease() override;
71
72protected:
73
74private:
75 std::string strCmd;
76 std::string strParam;
77 std::string strHost;
78 std::string strStdio;
79 std::string strWorkdir;
80 std::string strTag;
81 std::string strEnv;
82 int ID;
83 std::string strError;
84 bool bOnlyConnector;
85 bool bInitialized;
86 int pipe_to_stdout[2];
87 FILE* fd_stdout;
88 WindowMode windowMode;
89
90 bool timeout(double base, double timeout);
91 int ExecuteCmd();
92 bool psCmd(int pid);
93 bool killCmd(int pid);
94 bool stopCmd(int pid);
95#if defined(_WIN32)
96 HANDLE read_from_pipe_cmd_to_stdout;
97 HANDLE write_to_pipe_cmd_to_stdout;
98 std::string lastError2String();
99#else
100 int waitPipe(int pipe_fd);
101 int waitPipeSignal(int pipe_fd);
102 void splitLine(char *pLine, char **pArgs);
103 void parseArguments(char *io_pLine, int *o_pArgc, char **o_pArgv);
104#endif
105 bool startStdout();
106 void stopStdout();
107
108 inline bool IS_PARENT_OF(int pid){ return pid>0; }
109 inline bool IS_NEW_PROCESS(int pid){ return !pid; }
110 inline bool IS_INVALID(int pid){ return pid<0; }
111};
112
113} // namespace yarp::manager
114
115
116#endif // __YARP_MANAGER_LOCALBROKER__
Class Broker.
Definition broker.h:30
Class LocalBroker.
Definition localbroker.h:33
std::string requestRpc(const std::string &szport, const std::string &request, double timeout) override
void run() override
Main body of the new thread.
void setWindowMode(WindowMode m)
Define if the application will be visible or not.
bool exists(const std::string &port) override
bool initialized() override
Definition localbroker.h:60
bool threadInit() override
Initialization method.
bool disconnect(const std::string &from, const std::string &to, const std::string &carrier) override
void threadRelease() override
Release method.
bool connected(const std::string &from, const std::string &to, const std::string &carrier) override
std::string error() override
bool connect(const std::string &from, const std::string &to, const std::string &carrier, bool persist=false) override
connection broker
A mini-server for performing network communication in the background.
An abstraction for a thread of execution.
Definition Thread.h:21