Ceylan::System::Process Class Reference

#include <CeylanProcess.h>

Inheritance diagram for Ceylan::System::Process:

Inheritance graph
[legend]
Collaboration diagram for Ceylan::System::Process:

Collaboration graph
[legend]

List of all members.

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.
Processoperator= (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.


Detailed Description

Definition at line 103 of file CeylanProcess.h.


Member Enumeration Documentation

Describes how a child process terminated.

Enumerator:
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.

Defines what text output formats for TextDisplayable instances are available.

Enumerator:
rawText 
html 

Definition at line 124 of file CeylanTextDisplayable.h.


Constructor & Destructor Documentation

Process::Process (  ) 

Creates an anonymous Process object.

Definition at line 129 of file CeylanProcess.cc.

Process::Process ( const std::string &  name  )  [explicit]

Creates a named Process object.

Definition at line 139 of file CeylanProcess.cc.

Process::~Process (  )  throw () [virtual]

Basic virtual destructor.

Definition at line 149 of file CeylanProcess.cc.

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.


Member Function Documentation

bool Process::DuplicateStream ( FileDescriptor  FDOld,
FileDescriptor  FDNew 
) [static, private]

Duplicates a file descriptor.

Exceptions:
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]

Returns the error number.

Definition at line 516 of file CeylanProcess.h.

References _error.

Pid Process::GetHostingPID (  )  [static]

Returns the identifier (PID) of the hosting process.

Exceptions:
ProcessException if the operation failed or is not supported.
On OS-less machines (ex: the Nintendo DS), there is only one process, the current one, and its PID is set to 0.

Definition at line 275 of file CeylanProcess.cc.

Referenced by Ceylan::Log::ObjectIdentifier::ObjectIdentifier().

const string & Runnable::getName (  )  const [inherited]

TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat (  )  [static, inherited]

string Process::GetOwner (  )  [static]

Returns the user name of the process owner.

Exceptions:
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.

Exceptions:
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.

Exceptions:
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.

Exceptions:
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.

Exceptions:
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().

Process& Ceylan::System::Process::operator= ( const Process source  )  [private]

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.

Exceptions:
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.

See also:
OutputStream, Pipe, File, Socket.
Exceptions:
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.

Exceptions:
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.

See also:
InputStream, Pipe, File, Socket.
Exceptions:
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.

Exceptions:
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.

See also:
OutputStream, Pipe, File, Socket.
Exceptions:
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.

Exceptions:
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.

Exceptions:
ProcessException if the operation failed.
See also:
saveState

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.

Exceptions:
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.

Parameters:
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.

See also:
restart

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.

Parameters:
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]

Start point of the process: defines what it actually does.

Referenced by run().

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.

Parameters:
displayables a list of pointers to TextDisplayable instances/
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
toString, Ceylan::VerbosityLevels

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.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
TextDisplayable

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.

Parameters:
childProcess the child process reference.
executionInfo the return status if exited normally, or the signal number if signaled.
Returns:
the exit reason.
See also:
ExitReason
Exceptions:
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().


Member Data Documentation

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().

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().

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.

Note:
Defaults to raw text.

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().


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

Generated on Thu Jun 4 20:41:05 2009 for Ceylan by  doxygen 1.5.8