32 #ifndef ASYNC_EXEC_INCLUDED 33 #define ASYNC_EXEC_INCLUDED 44 #include <sigc++/sigc++.h> 131 class Exec :
public sigc::trackable
137 explicit Exec(
const std::string &cmdline=
"");
159 const std::string &
command(
void)
const {
return args[0]; }
177 bool nice(
int inc=10);
223 bool kill(
int sig=SIGTERM);
317 typedef std::map<pid_t, Exec*> ExecMap;
319 static ExecMap execs;
320 static int sigchld_pipe[2];
322 static struct sigaction old_sigact;
324 std::vector<std::string> args;
334 static void handleSigChld(
int signal_number, siginfo_t *info,
336 static void sigchldReceived(
void);
342 void subprocessExited(
void);
343 void handleTimeout(
void);
sigc::signal< void > stdoutClosed
A signal that is emitted when the subprocess close its stdout.
Execute external commands.
sigc::signal< void > stderrClosed
A signal that is emitted when the subprocess close its stderr.
sigc::signal< void > exited
A signal that is emitted when the subprocess exits.
sigc::signal< void, const char *, int > stdoutData
A signal that is emitted when the subprocess write to stdout.
void appendArgument(const std::string &arg)
Append a command line argument to a command.
bool closeStdin(void)
Close the stdin pipe to the subprocess.
A class that produces timer events.
A class for watching file descriptors.
bool ifExited(void) const
Check if the subprocess exited in a normal way.
bool writeStdin(const char *buf, int cnt)
Write data to stdin on the subprocess.
bool kill(int sig=SIGTERM)
Send a UNIX signal to the subprocess.
Namespace for the asynchronous programming classes.
Exec(const std::string &cmdline="")
Default constructor.
int termSig(void) const
Read the UNIX signal number that caused the subprocess to stop.
bool nice(int inc=10)
Modify the nice value for the child subprocess.
const std::string & command(void) const
Get the command name for the command.
int exitStatus(void) const
Read the exit code of the subprocess.
void setCommandLine(const std::string &cmdline)
Set the command line to use.
void setTimeout(int time_s)
Set a timeout on the allowed runtime for the subprocess.
bool run(void)
Run the command.
Contains a watch for file descriptors.
bool ifSignaled(void) const
Check if the subprocess exited due to receiving a UNIX signal.
sigc::signal< void, const char *, int > stderrData
A signal that is emitted when the subprocess write to stderr.