shutdown_alerter Class Reference

A platform-independent way to alert a program that it should shut down immediately. More...

#include <shutdown_alerter.h>

Inheritance diagram for shutdown_alerter:

Inheritance graph
[legend]
Collaboration diagram for shutdown_alerter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 shutdown_alerter ()
 constructor does very little; setup() is what begins operation.
virtual ~shutdown_alerter ()
 IMPLEMENT_CLASS_NAME ("shutdown_alerter")
bool setup (const istring &app_name, int timer_period=0)
 constructs a shutdown_alerter for the "app_name" specified.
bool saw_interrupt ()
 reports whether the process saw an interrupt from the user.
virtual void handle_startup ()
 this function is called once the program has begun operation.
virtual void handle_shutdown ()
 called during the program's shutdown process.
virtual void handle_timer ()
 called periodically if a timer period was specified.

Static Public Member Functions

static bool is_defunct ()
 returns true if the object has been marked as defunct.
static void set_defunct ()
 used by the derived class to mark that this object is about to exit.
static bool launch_console (shutdown_alerter &alert, const istring &app_name, int timer_period=0)
 this is used to begin execution of a console mode application.
static void close_this_program ()
 causes this particular application to begin shutting down.
static bool close_application (const istring &app_name)
 attempts to close the application named "app_name".
static void handle_OS_signal (int sig_id)
 processes the signal from the OS when its time to shut down.

Detailed Description

A platform-independent way to alert a program that it should shut down immediately.

This can provide a service management feature for graceful shutdown of an application, allowing it a chance to close its objects cleanly, rather than just being whacked in the middle of whatever it's doing. Only one of these objects should be instantiated per program, but the static methods can be used from anywhere in the program.

Definition at line 35 of file shutdown_alerter.h.


Constructor & Destructor Documentation

shutdown_alerter::shutdown_alerter (  ) 

constructor does very little; setup() is what begins operation.

Definition at line 58 of file shutdown_alerter.cpp.

shutdown_alerter::~shutdown_alerter (  )  [virtual]

Definition at line 62 of file shutdown_alerter.cpp.

References program_wide_timer, and set_defunct().


Member Function Documentation

shutdown_alerter::IMPLEMENT_CLASS_NAME ( "shutdown_alerter"   ) 

bool shutdown_alerter::setup ( const istring app_name,
int  timer_period = 0 
)

constructs a shutdown_alerter for the "app_name" specified.

this can be any string, although it might be processed for certain operating systems. also, for close_this_program() to work properly, it must be the application's basename. the "timer_period" specifies how frequently to invoke the handle_timer() method during runtime.

Definition at line 135 of file shutdown_alerter.cpp.

References handle_OS_signal().

Referenced by launch_console(), and anchor_window::setup().

static bool shutdown_alerter::is_defunct (  )  [inline, static]

returns true if the object has been marked as defunct.

this means that it is either shutting down or soon will be.

Definition at line 53 of file shutdown_alerter.h.

Referenced by anchor_window::defunct(), and launch_console().

void shutdown_alerter::set_defunct (  )  [static]

used by the derived class to mark that this object is about to exit.

note that this can be used anywhere in the program to initiate an exit of the program.

Reimplemented in anchor_window.

Definition at line 130 of file shutdown_alerter.cpp.

Referenced by close_this_program(), anchor_window::set_defunct(), and ~shutdown_alerter().

bool shutdown_alerter::saw_interrupt (  )  [inline]

reports whether the process saw an interrupt from the user.

Definition at line 61 of file shutdown_alerter.h.

void shutdown_alerter::handle_startup (  )  [virtual]

this function is called once the program has begun operation.

Reimplemented in anchor_window.

Definition at line 70 of file shutdown_alerter.cpp.

Referenced by launch_console().

void shutdown_alerter::handle_shutdown (  )  [virtual]

called during the program's shutdown process.

this is invoked just prior to the destruction of this class which is also just before the shutdown of the program overall. in this method, the derived object must ensure that any threads the program started get stopped, that any opened files get closed, and that any other resources are released. this is the application's last chance to clean up.

Reimplemented in anchor_window.

Definition at line 72 of file shutdown_alerter.cpp.

Referenced by launch_console().

void shutdown_alerter::handle_timer (  )  [virtual]

called periodically if a timer period was specified.

Reimplemented in anchor_window.

Definition at line 74 of file shutdown_alerter.cpp.

bool shutdown_alerter::launch_console ( shutdown_alerter alert,
const istring app_name,
int  timer_period = 0 
) [static]

this is used to begin execution of a console mode application.

this method does not do anything except sit while the extant threads are in play. it will not return until the program must exit, as caused by close_this_program() or close_application().

Definition at line 160 of file shutdown_alerter.cpp.

References __argv, FUNCDEF, handle_shutdown(), handle_startup(), is_defunct(), program_wide_timer, time_stamp::reset(), SECOND_ms, setup(), and portable::sleep_ms().

Referenced by anchor_window::launch(), and main().

void shutdown_alerter::close_this_program (  )  [static]

causes this particular application to begin shutting down.

this is a static method available for programs that support the shutdown_alerter's graceful shutdown process. it causes the application to begin the shutdown.

Reimplemented in anchor_window.

Definition at line 82 of file shutdown_alerter.cpp.

References set_defunct().

Referenced by anchor_window::close_this_program().

bool shutdown_alerter::close_application ( const istring app_name  )  [static]

attempts to close the application named "app_name".

this can only be done if this program possesses sufficient rights to zap that program.

Definition at line 87 of file shutdown_alerter.cpp.

References process_control::find_process_in_list(), FUNCDEF, array< contents >::length(), LOG, and process_control::query_processes().

Referenced by anchor_window::close_app_window().

static void shutdown_alerter::handle_OS_signal ( int  sig_id  )  [static]

processes the signal from the OS when its time to shut down.

Referenced by setup().


The documentation for this class was generated from the following files:
Generated on Fri Aug 29 04:30:46 2008 for HOOPLE Libraries by  doxygen 1.5.1