38 using namespace basis;
45 #define DEBUG_SHUTDOWN_ALERTER
49 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
55 bool &
shutdown_alerter::_defunct() {
static bool _defu =
false;
return _defu; }
57 bool &shutdown_alerter::_saw_interrupt()
58 {
static bool _saw =
false;
return _saw; }
60 int &shutdown_alerter::_timer_period() {
static int _tim = 0;
return _tim; }
75 if (_global_shutdown_alerter) {
86 void shutdown_alerter::handle_timer_callback()
89 if (!is_defunct()) handle_timer();
106 LOG(
"couldn't get process list.");
112 LOG(
"couldn't find process in the list of active ones.");
117 for (
int i = 0; i < pids.
length(); i++) {
120 kill(pids[i], SIGHUP);
134 _saw_interrupt() =
true;
135 if (_global_shutdown_alerter) {
150 _timer_period() = timer_period;
151 _app_name() = app_name;
153 _global_shutdown_alerter =
this;
158 signal(SIGHUP, handle_OS_signal);
162 signal(SIGINT, handle_OS_signal);
164 signal(SIGBREAK, handle_OS_signal);
171 const astring &app_name,
int timer_period)
174 if (!alert.
setup(app_name, timer_period))
return false;
179 if (_timer_period()) {
183 #ifdef DEBUG_SHUTDOWN_ALERTER
189 #ifdef DEBUG_SHUTDOWN_ALERTER
192 next_report.
reset(REPORT_CYCLE);
195 time_control::sleep_ms(42);
a_sprintf is a specialization of astring that provides printf style support.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
Provides a bridge to the operating system for information on processes.
static bool find_process_in_list(const process_entry_array &processes, const basis::astring &app_name, structures::int_set &pids)
uses a pre-existing list of "processes" to search for the "app_name".
bool query_processes(process_entry_array &to_fill)
finds the processes that are running and drops them into "to_fill".
a handy class that implements an array of process entries.
A platform-independent way to alert a program that it should shut down immediately.
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.
virtual void handle_timer()
called periodically if a timer period was specified.
bool setup(const basis::astring &app_name, int timer_period=0)
constructs a shutdown_alerter for the "app_name" specified.
static void handle_OS_signal(int sig_id)
processes the signal from the OS when its time to shut down.
static void close_this_program()
causes this particular application to begin shutting down.
shutdown_alerter()
constructor does very little; setup() is what begins operation.
static bool launch_console(shutdown_alerter &alert, const basis::astring &app_name, int timer_period=0)
this is used to begin execution of a console mode application.
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 ~shutdown_alerter()
static bool close_application(const basis::astring &app_name)
attempts to close the application named "app_name".
A simple object that wraps a templated set of ints.
Represents a point in time relative to the operating system startup time.
void reset()
sets the stamp time back to now.
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
const int SECOND_ms
Number of milliseconds in a second.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
#define SAFE_STATIC(type, func_name, parms)
Statically defines a singleton object whose scope is the program's lifetime.
#define program_wide_timer()
provides access to the singleton timer_driver.