xorp

RunCommandBase Class Reference

Base virtual class for running an external command. More...

#include <run_command.hh>

Inheritance diagram for RunCommandBase:
RunCommand RunShellCommand

List of all members.

Classes

class  ExecId
 Class for setting the execution ID when running the command. More...

Public Member Functions

 RunCommandBase (EventLoop &eventloop, const string &command, const string &real_command_name, int task_priority=XorpTask::PRIORITY_DEFAULT)
 Constructor for a given command.
virtual ~RunCommandBase ()
 Destructor.
void set_argument_list (const list< string > &v)
 Set the list with the arguments for the command to execute.
int execute ()
 Execute the command.
void terminate ()
 Terminate the command.
void terminate_with_prejudice ()
 Terminate the command with prejudice.
const string & command () const
 Get the name of the command to execute.
const list< string > & argument_list () const
 Get the list with the arguments of the command to execute.
void wait_status_changed (int wait_status)
 Receive a notification that the status of the process has changed.
bool is_exited () const
 Test if the command has exited.
bool is_signal_terminated () const
 Test if the command has been terminated by a signal.
bool is_coredumped () const
 Test if the command has coredumped.
bool is_stopped () const
 Test if the command has been stopped.
int exit_status () const
 Get the command exit status.
int term_signal () const
 Get the signal that terminated the command.
int stop_signal () const
 Get the signal that stopped the command.
int task_priority () const
 Get the priority to use when reading output from the command.
ExecIdexec_id ()
 Get a reference to the ExecId object.
void set_exec_id (const ExecId &v)
 Set the execution ID for executing the command.

Private Member Functions

virtual void stdout_cb_dispatch (const string &output)=0
 A pure virtual method called when there is output on the program's stdout.
virtual void stderr_cb_dispatch (const string &output)=0
 A pure virtual method called when there is output on the program's stderr.
virtual void done_cb_dispatch (bool success, const string &error_msg)=0
 A pure virtual method called when the program execution is completed.
virtual void stopped_cb_dispatch (int stop_signal)=0
 A pure virtual method called when the program has been stopped.
virtual bool redirect_stderr_to_stdout () const =0
 Test if the stderr should be redirected to stdout.
void cleanup ()
 Cleanup state.
int block_child_signals ()
 Block child process signal(s) in current signal mask.
int unblock_child_signals ()
 Unblock child process signal(s) in current signal mask.
void terminate_process (bool with_prejudice)
 Terminate the process.
void close_output ()
 Close the output for the command.
void close_stdout_output ()
 Close the stdout output for the command.
void close_stderr_output ()
 Close the stderr output for the command.
void set_command_status (int status)
 Set the command status.
void append_data (AsyncFileOperator::Event event, const uint8_t *buffer, size_t buffer_bytes, size_t offset)
 Append data from the command.
void io_done (AsyncFileOperator::Event event, int error_code)
 The command's I/O operation has completed.
void done (XorpTimer &done_timer)
 The command has completed.

Private Attributes

EventLoop_eventloop
string _command
string _real_command_name
list< string > _argument_list
AsyncFileReader_stdout_file_reader
AsyncFileReader_stderr_file_reader
FILE * _stdout_stream
FILE * _stderr_stream
uint8_t _stdout_buffer [BUF_SIZE]
uint8_t _stderr_buffer [BUF_SIZE]
size_t _last_stdout_offset
size_t _last_stderr_offset
pid_t _pid
bool _is_error
string _error_msg
bool _is_running
ExecId _exec_id
bool _command_is_exited
bool _command_is_signal_terminated
bool _command_is_coredumped
bool _command_is_stopped
int _command_exit_status
int _command_term_signal
int _command_stop_signal
XorpTimer _done_timer
bool _stdout_eof_received
bool _stderr_eof_received
int _task_priority

Static Private Attributes

static const size_t BUF_SIZE = 8192

Detailed Description

Base virtual class for running an external command.


Constructor & Destructor Documentation

RunCommandBase::RunCommandBase ( EventLoop eventloop,
const string &  command,
const string &  real_command_name,
int  task_priority = XorpTask::PRIORITY_DEFAULT 
)

Constructor for a given command.

Parameters:
eventloopthe event loop.
commandthe command to execute.
real_command_namethe real command name.
task_prioritythe priority to read stdout and stderr.

Member Function Documentation

void RunCommandBase::append_data ( AsyncFileOperator::Event  event,
const uint8_t *  buffer,
size_t  buffer_bytes,
size_t  offset 
) [private]

Append data from the command.

Parameters:
eventthe event from the command (
See also:
AsyncFileOperator::Event).
Parameters:
bufferthe buffer with the data.
buffer_bytesthe maximum number of bytes in the buffer.
offsetoffset of the last byte read.
const list<string>& RunCommandBase::argument_list ( ) const [inline]

Get the list with the arguments of the command to execute.

Returns:
a string with the arguments of the command to execute.
const string& RunCommandBase::command ( ) const [inline]

Get the name of the command to execute.

Returns:
a string with the name of the command to execute.
void RunCommandBase::done ( XorpTimer done_timer) [private]

The command has completed.

Parameters:
done_timerthe timer associated with the event.
virtual void RunCommandBase::done_cb_dispatch ( bool  success,
const string &  error_msg 
) [private, pure virtual]

A pure virtual method called when the program execution is completed.

Parameters:
successif true the program execution has succeeded, otherwise it has failed.
error_msgif error, the string with the error message.

Implemented in RunCommand, and RunShellCommand.

ExecId& RunCommandBase::exec_id ( ) [inline]

Get a reference to the ExecId object.

Returns:
a reference to the ExecId object that is used for setting the execution ID when running the command.
int RunCommandBase::execute ( )

Execute the command.

Returns:
XORP_OK on success, otherwise XORP_ERROR.
int RunCommandBase::exit_status ( ) const [inline]

Get the command exit status.

Returns:
the command exit status.
void RunCommandBase::io_done ( AsyncFileOperator::Event  event,
int  error_code 
) [private]

The command's I/O operation has completed.

Parameters:
eventthe last event from the command. (
See also:
AsyncFileOperator::Event).
Parameters:
error_codethe error code if the event indicates an error (e.g., if it is not equal to AsyncFileOperator::END_OF_FILE), otherwise its value is ignored.
bool RunCommandBase::is_coredumped ( ) const [inline]

Test if the command has coredumped.

Returns:
true if the command has coredumped, otherwise false.
bool RunCommandBase::is_exited ( ) const [inline]

Test if the command has exited.

Returns:
true if the command has exited, otherwise false.
bool RunCommandBase::is_signal_terminated ( ) const [inline]

Test if the command has been terminated by a signal.

Returns:
true if the command has been terminated by a signal, otherwise false.
bool RunCommandBase::is_stopped ( ) const [inline]

Test if the command has been stopped.

Returns:
true if the command has been stopped, otherwise false.
virtual bool RunCommandBase::redirect_stderr_to_stdout ( ) const [private, pure virtual]

Test if the stderr should be redirected to stdout.

Returns:
true if the stderr should be redirected to stdout, otherwise false.

Implemented in RunCommand, and RunShellCommand.

void RunCommandBase::set_argument_list ( const list< string > &  v) [inline]

Set the list with the arguments for the command to execute.

Parameters:
vthe list with the arguments for the command to execute.
void RunCommandBase::set_command_status ( int  status) [private]

Set the command status.

Parameters:
statusthe command status.
void RunCommandBase::set_exec_id ( const ExecId v)

Set the execution ID for executing the command.

Parameters:
vthe execution ID.
virtual void RunCommandBase::stderr_cb_dispatch ( const string &  output) [private, pure virtual]

A pure virtual method called when there is output on the program's stderr.

Parameters:
outputthe string with the output.

Implemented in RunCommand, and RunShellCommand.

virtual void RunCommandBase::stdout_cb_dispatch ( const string &  output) [private, pure virtual]

A pure virtual method called when there is output on the program's stdout.

Parameters:
outputthe string with the output.

Implemented in RunCommand, and RunShellCommand.

int RunCommandBase::stop_signal ( ) const [inline]

Get the signal that stopped the command.

Returns:
the signal that stopped the command.
virtual void RunCommandBase::stopped_cb_dispatch ( int  stop_signal) [private, pure virtual]

A pure virtual method called when the program has been stopped.

Parameters:
stop_signalthe signal used to stop the program.

Implemented in RunCommand, and RunShellCommand.

int RunCommandBase::task_priority ( ) const [inline]

Get the priority to use when reading output from the command.

Returns:
the stdout and stderr priority.
int RunCommandBase::term_signal ( ) const [inline]

Get the signal that terminated the command.

Returns:
the signal that terminated the command.
void RunCommandBase::terminate_process ( bool  with_prejudice) [private]

Terminate the process.

Parameters:
with_prejudiceif true then terminate the process with prejudice, otherwise attempt to kill it gracefully.
void RunCommandBase::wait_status_changed ( int  wait_status)

Receive a notification that the status of the process has changed.

Parameters:
wait_statusthe wait status.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations