shutdown_alerter.h

Go to the documentation of this file.
00001 #ifndef SHUTDOWN_ALERTER_CLASS
00002 #define SHUTDOWN_ALERTER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : shutdown_alerter                                                  *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2003-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "dll_processes.h"
00019 
00020 #include <basis/object_base.h>
00021 #include <opsystem/timer_driver.h>
00022 
00023 // forward.
00024 class istring_object;
00025 
00027 
00035 class PROCESSES_CLASS_STYLE shutdown_alerter
00036 : public virtual object_base, public timed_object
00037 {
00038 public:
00039   shutdown_alerter();
00041 
00042   virtual ~shutdown_alerter();
00043 
00044   IMPLEMENT_CLASS_NAME("shutdown_alerter");
00045 
00046   bool setup(const istring &app_name, int timer_period = 0);
00048 
00053   static bool is_defunct() { return _defunct(); }
00055 
00057   static void set_defunct();
00059 
00062   inline bool saw_interrupt() { return _saw_interrupt(); }
00064 
00065   // these virtual methods can be overridden by applications derived from the
00066   // shutdown_alerter.  they support a graceful shutdown process by which
00067   // applications can be alerted that they must shutdown, allowing them to take
00068   // care of releasing resources beforehand.
00069 
00070   virtual void handle_startup();
00072 
00073   virtual void handle_shutdown();
00075 
00081   virtual void handle_timer();
00083 
00084   // static methods that can be used by the program for starting up or for
00085   // graceful shutdown.
00086 
00087   static bool launch_console(shutdown_alerter &alert, const istring &app_name,
00088           int timer_period = 0);
00090 
00094 #if 0  //not implemented.
00095 #ifdef __WIN32__
00096   static bool launch_event_loop(shutdown_alerter &alert,
00097           const istring &app_name, int timer_period = 0);
00099 
00101 #endif
00102 #endif
00103 
00104   static void close_this_program();
00106 
00110   static bool close_application(const istring &app_name);
00112 
00115   // internal methods not to be used by outside objects.
00116 
00117   static void handle_OS_signal(int sig_id);
00119 
00120 private:
00121   static bool &_saw_interrupt();  
00122   static istring_object &_app_name();  
00123   static bool &_defunct();  
00124   static int &_timer_period();  
00125 
00126   virtual void handle_timer_callback();
00128 
00129   // not appropriate.
00130   shutdown_alerter(const shutdown_alerter &);
00131   shutdown_alerter &operator =(const shutdown_alerter &);
00132 };
00133 
00134 #endif // outer guard.
00135 

Generated on Fri Nov 21 04:29:57 2008 for HOOPLE Libraries by  doxygen 1.5.1