#include <wefts_coffee_base.h>
Inheritance diagram for Wefts::OSProcessBase:
This class encapsulates threadsafe subprocess handling on the current platform. It provides support to spawn a child of the process, access its stdin, stdout and stderr file handle, test it's status and eventually wait for its termination.
The encapsulation is made so that the child process can be referenced to the thread that spawned it; if the father thread is cancelled, so the child process is cancelled too.
For this reason, the subprocess should be handled only by the calling thread, but it's possible for threads to exchange ownership among them with the takeOwnership() method. This removes the cancellation cleanup routine from the previous thread and adds it to the one that called takeOwnership.
Public Member Functions | |
virtual bool | running ()=0 |
Return true if the child process is currently running. | |
virtual bool | wait (const double seconds=-1.0)=0 |
Wait for the process to finish. | |
virtual bool | start (const std::string process, bool useShell=false, bool usePath=true)=0 |
Starts the subprocess. | |
virtual bool | stop ()=0 |
Stop the subprocess. | |
virtual bool | getProcessValue (int &retvalue) const =0 |
Get the return value of the process. | |
int | osError () const |
Return system dependend error occured on last operation. | |
virtual file_size_t | getProcessId () const =0 |
Return OS dependent process id. | |
virtual int | write (const void *data, const int size, const double seconds=-1.0)=0 |
Write to child standard input. | |
virtual int | read (void *data, const int size, const double seconds=-1.0)=0 |
Read from child standard output. | |
virtual int | readStdErr (void *data, const int size, const double seconds=-1.0)=0 |
Read from child standard error. | |
virtual void | mergeStdErr ()=0 |
Merge data incoming from Standard Output and Standard error child process streams. | |
virtual void | detach ()=0 |
Detaches the process. | |
virtual void | sinkInput ()=0 |
Tells that this process object won't read standard input. | |
virtual void | sinkOutput ()=0 |
Tells that this process object won't read standard input. | |
virtual void | sinkError ()=0 |
Tells that this process object won't read standard input. | |
virtual bool | closeRead ()=0 |
virtual bool | closeWrite ()=0 |
virtual bool | closeStdErr ()=0 |
virtual void | handleCleanup (int code, void *caller=0)=0 |
Protected Member Functions | |
OSProcessBase () | |
Initializes the process object. | |
Protected Attributes | |
int | m_osError |
Search for the child process to be spawned in the path. | |
bool | m_started |
bool | m_ended |
bool | m_mergeStdErr |
int | m_retval |
bool | m_detached |
Private Member Functions | |
void | internal_init () |
|
Initializes the process object.
|
|
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Detaches the process. Instead of listening for the sub process to terminate, the thread may detach it. If it does so, the child process is not tied anymore to the calling thread; on child termination, its system resources are cleaned (a low-level thread is started and puts itself in wait for the child). If the calling process terminates, the child process continues it execution, but if the parent is killed, the child may or may not remain active, depending on the OS implementation. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Return OS dependent process id. This function can be called to retreive the system id and do system specific operations on that; i.e. UNIX systems supports signals, while Windows systems supports process accounting informations (different ones based on Windows version). If some of this advanced features are needed by the application, it can use this method to retreive the low level process ID and work directly on that. Of course, doing this unsafely (i.e. calling directly waitpid) will strip the application from the ability to use Wefts Independence layers (that means, do this at your own risk). This function will return an impossible id if the process is not opened or is already closed (-1).
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Get the return value of the process.
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Implements Wefts::CleanupHandler. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
|
|
Merge data incoming from Standard Output and Standard error child process streams. Sometimes it is desiderable to have both the error stream and the standard output stream readable in only one call. After calling this method, read() will return both data coming from stdout and stderr of the child process, while readStdErr() will always return -1 (without setting osError). The method can be called both before and after the child process is started. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Return system dependend error occured on last operation.
|
|
Read from child standard output. This is a cancellation point; if the thread is cancelled in this call, the child is killed too.
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Read from child standard error. This is a cancellation point; if the thread is cancelled in this call, the child is killed too. Remember that if the child writes on standard error, the father MUST periodically read it, or the child writes will block it waiting for father to read.
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Return true if the child process is currently running. False is returned both if the process is not yet started or is already terminated. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Tells that this process object won't read standard input. For this reason, child standard error must be ignored. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Tells that this process object won't read standard input. For this reason, child standard input must be ignored. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Tells that this process object won't read standard input. For this reason, child standard output must be ignored. Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Starts the subprocess. If an error occurs, the method returns false and osError() method can be used to determine what happend. The calling thread may also chose to
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Stop the subprocess. If running, the subprocess is terminated; if not running this function returns false. This function is not a cancellation point.
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Wait for the process to finish. This is a cancellation point; if the thread is cancelled while waiting in this function, the subprocess is destroyed. Disable cancellation before entering if you don't want this behavior. In example, a thread run() code slice where the cancellation of subprocess on thread cancllation is not wanted may look like this: In this way, the thread may still be cancelled but the child process will survive. When the function returns true, the application can check for getProcessValue;
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
Write to child standard input. This is a cancellation point; if the thread is cancelled in this call, the child is killed too. A timeout in seconds may also be given. On error, osError() will return the OS dependent error value.
Implemented in Wefts::OSProcessPthread, and Wefts::OSProcessWin. |
|
|
|
|
|
|
|
Search for the child process to be spawned in the path.
|
|
|
|
|