feisty meow concerns codebase  2.140
hoople_service.h
Go to the documentation of this file.
1 #ifndef HOOPLE_SERVICE_CLASS
2 #define HOOPLE_SERVICE_CLASS
3 
5 // Name : hoople_service
6 // Author : Chris Koeritz
8 // Copyright (c) 2000-$now By Author. This program is free software; you can
9 // redistribute it and/or modify it under the terms of the GNU General Public
10 // License as published by the Free Software Foundation:
11 // http://www.gnu.org/licenses/gpl.html
12 // or under the terms of the GNU Library license:
13 // http://www.gnu.org/licenses/lgpl.html
14 // at your preference. Those licenses describe your legal rights to this
15 // software, and no other rights or warranties apply.
16 // Please send updates for this code to: fred@gruntose.com -- Thanks, fred.
18 
19 #include <basis/astring.h>
20 #include <basis/definitions.h>
21 #include <timely/timer_driver.h>
22 
23 namespace application {
24 
26 
35 : public virtual basis::root_object, public timely::timeable
36 {
37 public:
40 
41  virtual ~hoople_service();
42 
43  DEFINE_CLASS_NAME("hoople_service");
44 
45  bool setup(const basis::astring &app_name, int timer_period = 0);
47 
53  static bool is_defunct() { return _defunct(); }
55 
57  static void make_defunct();
59 
62  bool saw_interrupt() { return _saw_interrupt(); }
64 
65  // these virtual methods can be overridden by applications derived from the
66  // hoople_service. they support a graceful shutdown process by which
67  // applications can be alerted that they must shutdown, allowing them to take
68  // care of releasing resources beforehand.
69 
70  virtual void handle_startup();
72 
73  virtual void handle_shutdown();
75 
81  virtual void handle_timer();
83 
84  // static methods that can be used by the program for starting up or for
85  // graceful shutdown.
86 
87 //why?
88  static bool launch_console(hoople_service &alert, const basis::astring &app_name,
89  int timer_period = 0);
91 
95 #if 0 //not implemented.
96 #ifdef __WIN32__
97  static bool launch_event_loop(hoople_service &alert,
98  const basis::astring &app_name, int timer_period = 0);
100 
102 #endif
103 #endif
104 
105  static void close_this_program();
107 
111  static bool close_application(const basis::astring &app_name);
113 
116  // internal methods not to be used by outside objects.
117 
118  static void handle_OS_signal(int sig_id);
120 
121 private:
122  static bool &_saw_interrupt();
123  static basis::astring &_app_name();
124  static bool &_defunct();
125  static int &_timer_period();
126 
127  virtual void handle_timer_callback();
128 
129  // not appropriate.
131  hoople_service &operator =(const hoople_service &);
132 };
133 
134 } //namespace.
135 
136 #endif // outer guard.
137 
A platform-independent way to alert a program that it should shut down immediately.
virtual void handle_startup()
this function is called once the program has begun operation.
hoople_service()
constructor does very little; setup() is what begins operation.
static void make_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("hoople_service")
static void handle_OS_signal(int sig_id)
processes the signal from the OS when its time to shut down.
bool saw_interrupt()
reports whether the process saw an interrupt from the user.
static bool launch_console(hoople_service &alert, const basis::astring &app_name, int timer_period=0)
this is used to begin execution of a console mode application.
static bool is_defunct()
returns true if the object has been marked as defunct.
bool setup(const basis::astring &app_name, int timer_period=0)
constructs a hoople_service for the "app_name" specified.
static void close_this_program()
causes this particular application to begin shutting down.
virtual void handle_shutdown()
called during the program's shutdown process.
static bool close_application(const basis::astring &app_name)
attempts to close the application named "app_name".
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
timeable is the base for objects that can be hooked into timer events.
Definition: timer_driver.h:33
Constants and objects used throughout HOOPLE.
Implements an application lock to ensure only one is running at once.