libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BaseLib::ProcessManager Class Reference

#include <ProcessManager.h>

Classes

class  OpaquePointer
 

Public Member Functions

 ProcessManager ()=delete
 

Static Public Member Functions

static void startSignalHandler ()
 Starts the signal handler thread. More...
 
static void startSignalHandler (BaseLib::ThreadManager &threadManager)
 Starts the signal handler thread. More...
 
static void stopSignalHandler ()
 
static void stopSignalHandler (BaseLib::ThreadManager &threadManager)
 
static int32_t registerCallbackHandler (std::function< void(pid_t pid, int exitCode, int signal, bool coreDumped)> callbackHandler)
 
static void unregisterCallbackHandler (int32_t id)
 
static std::vector< std::string > splitArguments (const std::string &arguments)
 
static std::string findProgramInPath (const std::string &relativePath)
 
static pid_t system (const std::string &path, const std::vector< std::string > &arguments, int maxFd)
 Starts a program and returns the process id. More...
 
static pid_t systemp (const std::string &path, const std::vector< std::string > &arguments, int maxFd, int &stdIn, int &stdOut, int &stdErr)
 Starts a program with redirected pipe and returns the process id. More...
 
static int32_t exec (const std::string &command, int maxFd, std::string &output)
 Starts a program and returns the output. More...
 
static bool exec (const std::string &command, int maxFd)
 Starts a program and detaches it, so it continues to run when the parent process finishes. More...
 
static FILE * popen2 (const std::string &command, const std::string &type, int maxFd, pid_t &pid)
 Custom implementation of popen that returns the pid. More...
 

Constructor & Destructor Documentation

§ ProcessManager()

BaseLib::ProcessManager::ProcessManager ( )
delete

Member Function Documentation

§ exec() [1/2]

int32_t BaseLib::ProcessManager::exec ( const std::string &  command,
int  maxFd,
std::string &  output 
)
static

Starts a program and returns the output.

Parameters
commandThe command to execute.
maxFdThe maximum number of file descriptors.
[out]outputThe program output.
Returns
Returns the programs exit code.

§ exec() [2/2]

bool BaseLib::ProcessManager::exec ( const std::string &  command,
int  maxFd 
)
static

Starts a program and detaches it, so it continues to run when the parent process finishes.

Parameters
commandThe command to execute.
maxFdThe maximum number of file descriptors.
Returns
Returns true when the process started successfully.

§ findProgramInPath()

std::string BaseLib::ProcessManager::findProgramInPath ( const std::string &  relativePath)
static

§ popen2()

FILE * BaseLib::ProcessManager::popen2 ( const std::string &  command,
const std::string &  type,
int  maxFd,
pid_t &  pid 
)
static

Custom implementation of popen that returns the pid.

Parameters
command
type
pid
Returns

§ registerCallbackHandler()

int32_t BaseLib::ProcessManager::registerCallbackHandler ( std::function< void(pid_t pid, int exitCode, int signal, bool coreDumped)>  callbackHandler)
static

§ splitArguments()

std::vector< std::string > BaseLib::ProcessManager::splitArguments ( const std::string &  arguments)
static

§ startSignalHandler() [1/2]

void BaseLib::ProcessManager::startSignalHandler ( )
static

Starts the signal handler thread.

Must be called from main thread. You need to call stopSignalHandler() before exiting the program. When using ThreadManager, pass it to this method.

§ startSignalHandler() [2/2]

void BaseLib::ProcessManager::startSignalHandler ( BaseLib::ThreadManager threadManager)
static

Starts the signal handler thread.

Must be called from main thread. You need to call stopSignalHandler() before exiting the program. When using ThreadManager, pass it to this method.

§ stopSignalHandler() [1/2]

void BaseLib::ProcessManager::stopSignalHandler ( )
static

§ stopSignalHandler() [2/2]

void BaseLib::ProcessManager::stopSignalHandler ( BaseLib::ThreadManager threadManager)
static

§ system()

pid_t BaseLib::ProcessManager::system ( const std::string &  path,
const std::vector< std::string > &  arguments,
int  maxFd 
)
static

Starts a program and returns the process id.

Parameters
pathThe program to start. If path is relative, PATH is searched.
argumentsThe arguments to pass.
maxFdThe maximum possible file descriptor. Needed to close all open file descriptors in the child process.
Exceptions
Exception
Returns
Returns the PID on success and "-1" on error.

§ systemp()

pid_t BaseLib::ProcessManager::systemp ( const std::string &  path,
const std::vector< std::string > &  arguments,
int  maxFd,
int &  stdIn,
int &  stdOut,
int &  stdErr 
)
static

Starts a program with redirected pipe and returns the process id.

Parameters
pathThe program to start. If path is relative, PATH is searched.
argumentsThe arguments to pass.
[out]stdInWill be filled with the input file descriptor. Close it when the process finishes.
[out]stdOutWill be filled with the output file descriptor. Close it when the process finishes.
[out]stdErrWill be filled with the error file descriptor. Close it when the process finishes.
Exceptions
Exception
Returns
Returns the PID on success and "-1" on error.

§ unregisterCallbackHandler()

void BaseLib::ProcessManager::unregisterCallbackHandler ( int32_t  id)
static

The documentation for this class was generated from the following files: