12#define RUN_TIMEOUT 10.0
13#define STOP_TIMEOUT 15.0
14#define KILL_TIMEOUT 10.0
15#define CONNECTION_TIMEOUT 2.0
17#define WRITE_TO_PIPE 1
18#define READ_FROM_PIPE 0
25 #include <sys/types.h>
32 #define PIPE_TIMEOUT 0
34 #define PIPE_SIGNALED 2
61 if (
dwID==params->dwID)
95 "\\\\.\\Pipe\\RemoteExeAnon.%08x.%08x",
142 bOnlyConnector = bInitialized =
false;
171 bOnlyConnector =
true;
190 strError =
"command is not specified.";
208 strStdio = std::string(
"/") + std::string(
szstdio);
254 if (bOnlyConnector) {
280 if (bOnlyConnector) {
301 strError =
"Timeout! cannot stop ";
313 if (bOnlyConnector) {
335 strError =
"Timeout! cannot kill ";
348 if (bOnlyConnector) {
351 return (psCmd(ID))?1:0;
358bool LocalBroker::connect(
const std::string& from,
const std::string& to,
const std::string& carrier,
bool persist)
363 strError =
"no source port is introduced.";
369 strError =
"no destination port is introduced.";
376 strError +=
" does not exist.";
383 strError +=
" does not exist.";
389 strError =
"cannot connect ";
391 strError +=
" to " + std::string(to);
402 strError =
"no source port is introduced.";
408 strError =
"no destination port is introduced.";
415 strError +=
" does not exist.";
422 strError +=
" does not exist.";
432 strError =
"cannot disconnect ";
434 strError +=
" from " + std::string(to);
449 if (
szport.empty() || request.empty()) {
460 if (!port.
open(
"...")) {
468 for(
int i=0;
i<10;
i++) {
515 strError =
"Module is not running";
518 return startStdout();
527bool LocalBroker::timeout(
double base,
double timeout)
596std::string LocalBroker::lastError2String()
601 return std::string(
buff);
604bool LocalBroker::startStdout()
612void LocalBroker::stopStdout()
617int LocalBroker::ExecuteCmd()
619 std::string
strCmdLine = strCmd + std::string(
" ") + strParam;
694 for (
const auto& s :
ss) {
739 strError = std::string(
"Can't execute command because ") +
lastError2String();
746bool LocalBroker::psCmd(
int pid)
758bool LocalBroker::killCmd(
int pid)
769bool LocalBroker::stopCmd(
int pid)
790bool LocalBroker::psCmd(
int pid)
799bool LocalBroker::killCmd(
int pid)
808bool LocalBroker::stopCmd(
int pid)
816int LocalBroker::waitPipe(
int pipe_fd)
823 timeout.tv_usec = 500000;
827 rc = select(
pipe_fd + 1, &fd,
nullptr,
nullptr, &timeout);
832int LocalBroker::waitPipeSignal(
int pipe_fd)
857 if (
pselect(
pipe_fd + 1, &fd,
nullptr,
nullptr, &timeout,
nullptr)) {
864bool LocalBroker::startStdout()
869 strError =
"cannot open pipe. " + std::string(
strerror(
errno));
877 strError =
"cannot set flag on pipe: " + std::string(
strerror(
errno));
885void LocalBroker::stopStdout()
896int LocalBroker::ExecuteCmd()
902 strError = std::string(
"Can't create child pipe because") + std::string(
strerror(
errno));
909 strError = std::string(
"Can't create stdout pipe because") + std::string(
strerror(
errno));
917 strError = std::string(
"Can't fork command because ") + std::string(
strerror(
errno));
928 strError = std::string(
"Can't set flag on stdout: ") + std::string(
strerror(
errno));
932 strError = std::string(
"Can't set flag on stderr: ") + std::string(
strerror(
errno));
939 strCmd = strCmd + std::string(
" ") + strParam;
940 char *
szcmd =
new char[strCmd.size()+1];
949 for (
const auto& s :
ss) {
950 char*
szenv =
new char[s.size()+1];
957 if(strWorkdir.size())
959 int ret =
chdir(strWorkdir.c_str());
962 strError = std::string(
"Can't set working directory because ") + std::string(
strerror(
errno));
1002 strError = std::string(
"Can't execute command because ") + std::string(
strerror(
errno));
1021 strError = std::string(
"Can't set flag on pipe: ") + std::string(
strerror(
errno));
1052void LocalBroker::splitLine(
char *
pLine,
char **
pArgs)
1059 while ((*
pTmp) && (*
pTmp ==
' ')) {
1062 if (*
pTmp ==
'\0') {
1083 for(
i = 0;
i < len;
i++) {
1111 for(
i = 0;
i < len;
i++) {
void parseArguments(char *io_pLine, int *o_pArgc, char **o_pArgv)
Breaks up a line into multiple arguments.
void splitLine(char *pLine, char **pArgs)
Split a line into separate words.
virtual void onBrokerStdout(const char *msg)
BrokerEventSink * eventSink
std::string getDisplay() const
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 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
void detachStdout() override
bool attachStdout() override
bool connect(const std::string &from, const std::string &to, const std::string &carrier, bool persist=false) override
connection broker
A simple collection of objects that can be described and transmitted in a portable way.
void fromString(const std::string &text)
Initializes bottle from a string.
size_type size() const
Gets the number of elements in the bottle.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
A mini-server for performing network communication in the background.
BufferedPort()
Constructor.
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.
static bool exists(const std::string &port, bool quiet=true, bool checkVer=true)
Check for a port to be ready and responsive.
static bool disconnect(const std::string &src, const std::string &dest, bool quiet)
Request that an output port disconnect from an input port.
static bool isConnected(const std::string &src, const std::string &dest, bool quiet)
Check if a connection with tcp carrier exists between two ports.
A mini-server for network communication.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
bool setTimeout(float timeout)
Set a timeout on network operations.
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.
static double nowSystem()
static void delaySystem(double seconds)
bool stop()
Stop the thread.
bool isStopping()
Returns true if the thread is stopping (Thread::stop has been called).
bool isRunning()
Returns true if the thread is running (Thread::start has been called successfully and the thread has ...
bool start()
Start the new thread running.
#define CONNECTION_TIMEOUT
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
An interface to the operating system, including Port based communication.
char * getcwd(char *buf, size_t size)
Portable wrapper for the getcwd() function.
int fork()
Portable wrapper for the fork() function.