#include <CeylanProcess.h>
Public Types | |
enum | ExitReason { ExitedNormally, Signaled, Stopped, BadChildPid } |
Describes how a child process terminated. More... | |
Public Member Functions | |
Process () | |
Creates an anonymous Process object. | |
Process (const std::string &name) | |
Creates a named Process object. | |
virtual | ~Process () throw () |
Basic virtual destructor. | |
virtual void | run () |
To be called in order to launch the process after its creation. | |
virtual void | start ()=0 |
Start point of the process: defines what it actually does. | |
virtual void | kill () |
Kills the process. | |
bool | isRunning () const |
Tells whether the child process is running. | |
ErrorCode | getError () const |
Returns the error number. | |
Pid | getPID () const |
Returns the process identifier, the PID, of corresponding process. | |
virtual const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const |
Returns a user-friendly description of the state of this object. | |
const std::string & | getName () const |
Returns the name string. | |
Static Public Member Functions | |
static Pid | GetHostingPID () |
Returns the identifier (PID) of the hosting process. | |
static Pid | GetParentID () |
Returns the parent process identifier of the hosting process, the PPID. | |
static ExitReason | WaitChildProcess (const Process &childProcess, ErrorCode *executionInfo=0) |
Waits for the child process to terminate. | |
static std::string | GetOwner () |
Returns the user name of the process owner. | |
static void | RunExecutable (const std::string &filename, const std::list< std::string > &arguments, const std::string &stdoutFilename=0, const std::string &stderrFilename=0, const std::string &stdinFilename=0) |
Replaces the current process by the one obtained by executing filename. | |
static bool | RedirectStdout (const std::string &filename) |
Redirects the stdout to the file filename. | |
static bool | RedirectStdout (OutputStream &os) |
Redirects the stdout to the output stream os. | |
static bool | RedirectStderr (const std::string &filename) |
Redirects the stderr to the file filename. | |
static bool | RedirectStderr (OutputStream &os) |
Redirects the stderr to the output stream os. | |
static bool | RedirectStdin (const std::string &filename) |
Redirects the stdin from the file filename. | |
static bool | RedirectStdin (InputStream &is) |
Redirects the stdin from the input stream is. | |
static Ceylan::Uint32 | GetTime () |
Returns the number of seconds consumed by the process. | |
static void | SaveState (int argc, char **argv) |
Saves the command line of the corresponding process, line which is to be used in the restart mehod. | |
static void | Restart () |
Restarts the corresponding processs with command line options as saved previously by calling saveState. | |
static const std::string | ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high) |
Returns a user-friendly description of this list of pointers to text displayable instances. | |
static TextOutputFormat | GetOutputFormat () |
Returns the current overall text format to be used by TextDisplayable instances. | |
static void | SetOutputFormat (TextOutputFormat newOutputFormat) |
Sets the current overall text format to be used by TextDisplayable instances. | |
Protected Member Functions | |
virtual void | processCreationFailed () |
Called whenever new process creation fails. | |
Static Protected Attributes | |
static TextOutputFormat | _OutputFormat = rawText |
The text format to be used currently by TextDisplayable instances. | |
Private Member Functions | |
Process (const Process &source) | |
Copy constructor made private to ensure that it will never be called. | |
Process & | operator= (const Process &source) |
Assignment operator made private to ensure that it will be never called. | |
Static Private Member Functions | |
static bool | DuplicateStream (FileDescriptor FDOld, FileDescriptor FDNew) |
Duplicates a file descriptor. | |
Private Attributes | |
Pid | _id |
The PID of this process. | |
ErrorCode | _error |
The error code returned by this process, if any. | |
Static Private Attributes | |
static std::string | _Owner |
The owner of this process. | |
static bool | _Saved = false |
Tells whether the process state has already been saved. | |
static std::string | _Path |
The path where the executable of this process should be run. | |
static std::string | _Executable |
The name of the executable corresponding to this process. | |
static std::list< std::string > | _ArgumentList |
The argument list given to this process. |
Definition at line 103 of file CeylanProcess.h.
Describes how a child process terminated.
ExitedNormally | Child exited normally:. |
Signaled | Child exited after having received a signal:. |
Stopped | Child exited after having been stopped:. |
BadChildPid | Child PID was abnormal:. |
Definition at line 112 of file CeylanProcess.h.
enum Ceylan::TextDisplayable::TextOutputFormat [inherited] |
Defines what text output formats for TextDisplayable instances are available.
Definition at line 124 of file CeylanTextDisplayable.h.
Process::Process | ( | ) |
Process::Process | ( | const std::string & | name | ) | [explicit] |
Process::~Process | ( | ) | throw () [virtual] |
Ceylan::System::Process::Process | ( | const Process & | source | ) | [private] |
Copy constructor made private to ensure that it will never be called.
The compiler should complain whenever this undefined constructor is called, implicitly or not.
bool Process::DuplicateStream | ( | FileDescriptor | FDOld, | |
FileDescriptor | FDNew | |||
) | [static, private] |
Duplicates a file descriptor.
FeatureNotAvailableException | if the file descriptor feature is not available. |
Definition at line 814 of file CeylanProcess.cc.
Referenced by RedirectStderr(), RedirectStdin(), and RedirectStdout().
ErrorCode Ceylan::System::Process::getError | ( | ) | const [inline] |
Pid Process::GetHostingPID | ( | ) | [static] |
Returns the identifier (PID) of the hosting process.
ProcessException | if the operation failed or is not supported. |
Definition at line 275 of file CeylanProcess.cc.
Referenced by Ceylan::Log::ObjectIdentifier::ObjectIdentifier().
const string & Runnable::getName | ( | ) | const [inherited] |
Returns the name string.
Definition at line 75 of file CeylanRunnable.cc.
References Ceylan::System::Runnable::_name.
Referenced by Ceylan::System::Thread::askToStop(), Ceylan::System::Thread::cancel(), Ceylan::System::Thread::Run(), Ceylan::System::Thread::run(), Ceylan::System::Thread::waitUntilOver(), and Ceylan::System::Thread::~Thread().
TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat | ( | ) | [static, inherited] |
Returns the current overall text format to be used by TextDisplayable instances.
Definition at line 63 of file CeylanTextDisplayable.cc.
References Ceylan::TextDisplayable::_OutputFormat.
Referenced by Ceylan::formatStringList(), Ceylan::formatStringMap(), Ceylan::XML::XMLMarkup::toString(), Ceylan::Maths::Linear::Vector3::toString(), Ceylan::Maths::Linear::Vector2::toString(), Ceylan::Maths::Linear::Tripoint::toString(), Ceylan::Module::toString(), Ceylan::Maths::Linear::Matrix3::toString(), Ceylan::Maths::Linear::Matrix2::toString(), Ceylan::Maths::Linear::HomogeneousMatrix3::toString(), and Ceylan::Maths::Linear::Bipoint::toString().
string Process::GetOwner | ( | ) | [static] |
Returns the user name of the process owner.
ProcessException | on failure. |
Definition at line 384 of file CeylanProcess.cc.
References _Owner.
Pid Process::GetParentID | ( | ) | [static] |
Returns the parent process identifier of the hosting process, the PPID.
ProcessException | if the operation failed or is not supported. |
Definition at line 310 of file CeylanProcess.cc.
Pid Ceylan::System::Process::getPID | ( | ) | const [inline] |
Returns the process identifier, the PID, of corresponding process.
Definition at line 525 of file CeylanProcess.h.
References _id.
Referenced by WaitChildProcess().
Ceylan::Uint32 Process::GetTime | ( | ) | [static] |
Returns the number of seconds consumed by the process.
ProcessException | if this value could not be determined. |
Definition at line 724 of file CeylanProcess.cc.
References Ceylan::System::explainError().
bool Process::isRunning | ( | ) | const |
Tells whether the child process is running.
ProcessException | if the process state could not be known. |
Definition at line 232 of file CeylanProcess.cc.
References _id, and generalUtils::true.
void Process::kill | ( | ) | [virtual] |
Kills the process.
ProcessException | if the process could not be killed. |
Definition at line 198 of file CeylanProcess.cc.
References _error, _id, Ceylan::System::explainError(), Ceylan::toString(), and WaitChildProcess().
Assignment operator made private to ensure that it will be never called.
The compiler should complain whenever this undefined operator is called, implicitly or not.
void Process::processCreationFailed | ( | ) | [protected, virtual] |
Called whenever new process creation fails.
ProcessException | if needed. |
Definition at line 714 of file CeylanProcess.cc.
References _error, and Ceylan::System::explainError().
Referenced by run().
bool Process::RedirectStderr | ( | OutputStream & | os | ) | [static] |
Redirects the stderr to the output stream os.
ProcessException | if the redirection failed, for example if the file descriptor feature is not available. |
Definition at line 612 of file CeylanProcess.cc.
References DuplicateStream(), and Ceylan::System::OutputStream::getOutputStreamID().
bool Process::RedirectStderr | ( | const std::string & | filename | ) | [static] |
Redirects the stderr to the file filename.
ProcessException | if the redirection failed, for example if the file descriptor feature is not available. |
Definition at line 565 of file CeylanProcess.cc.
References Ceylan::System::StandardFile::close(), Ceylan::System::StandardFile::Create(), DuplicateStream(), dataUtils::e, dataUtils::f, generalUtils::false, Ceylan::System::StandardFile::getFileDescriptor(), and Ceylan::Exception::toString().
Referenced by RunExecutable().
bool Process::RedirectStdin | ( | InputStream & | is | ) | [static] |
Redirects the stdin from the input stream is.
ProcessException | if the redirection failed, for example if the file descriptor feature is not available. |
Definition at line 687 of file CeylanProcess.cc.
References DuplicateStream(), and Ceylan::System::InputStream::getInputStreamID().
bool Process::RedirectStdin | ( | const std::string & | filename | ) | [static] |
Redirects the stdin from the file filename.
ProcessException | if the redirection failed, for example if the file descriptor feature is not available. |
Definition at line 639 of file CeylanProcess.cc.
References Ceylan::System::StandardFile::close(), Ceylan::System::StandardFile::Create(), DuplicateStream(), dataUtils::e, dataUtils::f, generalUtils::false, Ceylan::System::StandardFile::getFileDescriptor(), and Ceylan::Exception::toString().
Referenced by RunExecutable().
bool Process::RedirectStdout | ( | OutputStream & | os | ) | [static] |
Redirects the stdout to the output stream os.
ProcessException | if the redirection failed, for example if the file descriptor feature is not available. |
Definition at line 538 of file CeylanProcess.cc.
References DuplicateStream(), and Ceylan::System::OutputStream::getOutputStreamID().
bool Process::RedirectStdout | ( | const std::string & | filename | ) | [static] |
Redirects the stdout to the file filename.
ProcessException | if the redirection failed, for example if the file descriptor feature is not available. |
Definition at line 491 of file CeylanProcess.cc.
References Ceylan::System::StandardFile::close(), Ceylan::System::StandardFile::Create(), DuplicateStream(), dataUtils::e, dataUtils::f, generalUtils::false, Ceylan::System::StandardFile::getFileDescriptor(), and Ceylan::Exception::toString().
Referenced by RunExecutable().
void Process::Restart | ( | ) | [static] |
Restarts the corresponding processs with command line options as saved previously by calling saveState.
ProcessException | if the operation failed. |
Definition at line 788 of file CeylanProcess.cc.
References _ArgumentList, _Executable, _Path, _Saved, Ceylan::System::Directory::ChangeWorkingDirectory(), dataUtils::e, and RunExecutable().
void Process::run | ( | ) | [virtual] |
To be called in order to launch the process after its creation.
RunnableException | if the process creation failed. |
Implements Ceylan::System::Runnable.
Definition at line 156 of file CeylanProcess.cc.
References _error, _id, processCreationFailed(), and start().
void Process::RunExecutable | ( | const std::string & | filename, | |
const std::list< std::string > & | arguments, | |||
const std::string & | stdoutFilename = 0 , |
|||
const std::string & | stderrFilename = 0 , |
|||
const std::string & | stdinFilename = 0 | |||
) | [static] |
Replaces the current process by the one obtained by executing filename.
filename | executable file name. | |
arguments | the arguments vector, without filename at the beginning. | |
stdoutFilename | file name for the stdout to be redirected to, if not empty. | |
stderrFilename | file name for the stderr to be redirected to, if not empty. | |
stdinFilename | file name for the stdin to be redirected from, if not empty. |
Definition at line 415 of file CeylanProcess.cc.
References Ceylan::System::explainError(), RedirectStderr(), RedirectStdin(), and RedirectStdout().
Referenced by Restart().
void Process::SaveState | ( | int | argc, | |
char ** | argv | |||
) | [static] |
Saves the command line of the corresponding process, line which is to be used in the restart mehod.
Definition at line 773 of file CeylanProcess.cc.
References _ArgumentList, _Executable, _Path, _Saved, Ceylan::System::Directory::GetCurrentWorkingDirectoryPath(), and generalUtils::true.
void TextDisplayable::SetOutputFormat | ( | TextOutputFormat | newOutputFormat | ) | [static, inherited] |
Sets the current overall text format to be used by TextDisplayable instances.
newOutputFormat | the new output format. |
Definition at line 72 of file CeylanTextDisplayable.cc.
References Ceylan::TextDisplayable::_OutputFormat.
Referenced by Ceylan::Log::LogHolder::LogHolder().
virtual void Ceylan::System::Process::start | ( | ) | [pure virtual] |
const std::string TextDisplayable::ToString | ( | std::list< TextDisplayable * > | displayables, | |
Ceylan::VerbosityLevels | level = Ceylan::high | |||
) | [static, inherited] |
Returns a user-friendly description of this list of pointers to text displayable instances.
displayables | a list of pointers to TextDisplayable instances/ | |
level | the requested verbosity level. |
Definition at line 45 of file CeylanTextDisplayable.cc.
References Ceylan::formatStringList().
const string Process::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const [virtual] |
Returns a user-friendly description of the state of this object.
level | the requested verbosity level. |
Implements Ceylan::System::Runnable.
Definition at line 262 of file CeylanProcess.cc.
References _id.
Process::ExitReason Process::WaitChildProcess | ( | const Process & | childProcess, | |
ErrorCode * | executionInfo = 0 | |||
) | [static] |
Waits for the child process to terminate.
childProcess | the child process reference. | |
executionInfo | the return status if exited normally, or the signal number if signaled. |
ProcessException | if the operation failed or is not supported. |
Definition at line 328 of file CeylanProcess.cc.
References BadChildPid, ExitedNormally, getPID(), Signaled, and Stopped.
Referenced by kill().
list< string > Process::_ArgumentList [static, private] |
The argument list given to this process.
Definition at line 507 of file CeylanProcess.h.
Referenced by Restart(), and SaveState().
ErrorCode Ceylan::System::Process::_error [private] |
The error code returned by this process, if any.
Definition at line 473 of file CeylanProcess.h.
Referenced by getError(), kill(), processCreationFailed(), and run().
string Process::_Executable [static, private] |
The name of the executable corresponding to this process.
Definition at line 494 of file CeylanProcess.h.
Referenced by Restart(), and SaveState().
Pid Ceylan::System::Process::_id [private] |
The PID of this process.
Definition at line 469 of file CeylanProcess.h.
Referenced by getPID(), isRunning(), kill(), run(), and toString().
TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited] |
The text format to be used currently by TextDisplayable instances.
Definition at line 158 of file CeylanTextDisplayable.h.
Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().
string Process::_Owner [static, private] |
The owner of this process.
Definition at line 482 of file CeylanProcess.h.
Referenced by GetOwner().
string Process::_Path [static, private] |
The path where the executable of this process should be run.
Definition at line 490 of file CeylanProcess.h.
Referenced by Restart(), and SaveState().
bool Process::_Saved = false [static, private] |
Tells whether the process state has already been saved.
Definition at line 486 of file CeylanProcess.h.
Referenced by Restart(), and SaveState().