feisty meow concerns codebase  2.140
shutdown_alerter.h
Go to the documentation of this file.
1 #ifndef SHUTDOWN_ALERTER_CLASS
2 #define SHUTDOWN_ALERTER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : shutdown_alerter *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2003-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/definitions.h>
20 #include <timely/timer_driver.h>
21 
22 // forward.
23 //class basis::astring_object;
24 
26 
33 class shutdown_alerter : public virtual basis::root_object, public timely::timeable
34 {
35 public:
38 
39  virtual ~shutdown_alerter();
40 
41  DEFINE_CLASS_NAME("shutdown_alerter");
42 
43  bool setup(const basis::astring &app_name, int timer_period = 0);
45 
50  static bool is_defunct() { return _defunct(); }
52 
54  static void set_defunct();
56 
59  inline bool saw_interrupt() { return _saw_interrupt(); }
61 
62  // these virtual methods can be overridden by applications derived from the
63  // shutdown_alerter. they support a graceful shutdown process by which
64  // applications can be alerted that they must shutdown, allowing them to take
65  // care of releasing resources beforehand.
66 
67  virtual void handle_startup();
69 
70  virtual void handle_shutdown();
72 
78  virtual void handle_timer();
80 
81  // static methods that can be used by the program for starting up or for
82  // graceful shutdown.
83 
84  static bool launch_console(shutdown_alerter &alert, const basis::astring &app_name,
85  int timer_period = 0);
87 
91 #if 0 //not implemented.
92 #ifdef __WIN32__
93  static bool launch_event_loop(shutdown_alerter &alert,
94  const basis::astring &app_name, int timer_period = 0);
96 
98 #endif
99 #endif
100 
101  static void close_this_program();
103 
107  static bool close_application(const basis::astring &app_name);
109 
112  // internal methods not to be used by outside objects.
113 
114  static void handle_OS_signal(int sig_id);
116 
117 private:
118  static bool &_saw_interrupt();
119  static basis::astring &_app_name();
120  static bool &_defunct();
121  static int &_timer_period();
122 
123  virtual void handle_timer_callback();
125 
126  // not appropriate.
128  shutdown_alerter &operator =(const shutdown_alerter &);
129 };
130 
131 #endif // outer guard.
132 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
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.
DEFINE_CLASS_NAME("shutdown_alerter")
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.
bool saw_interrupt()
reports whether the process saw an interrupt from the user.
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".
timeable is the base for objects that can be hooked into timer events.
Definition: timer_driver.h:33
Constants and objects used throughout HOOPLE.