33 using namespace basis;
44 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
52 bool &hoople_service::_defunct() {
static bool _defu =
false;
return _defu; }
54 bool &hoople_service::_saw_interrupt()
55 {
static bool _saw =
false;
return _saw; }
57 int &hoople_service::_timer_period() {
static int _tim = 0;
return _tim; }
61 static hoople_service *_global_hoople_service =
NULL_POINTER;
65 hoople_service::hoople_service()
69 hoople_service::~hoople_service()
72 if (_global_hoople_service) {
77 void hoople_service::handle_startup() { }
79 void hoople_service::handle_shutdown() { }
81 void hoople_service::handle_timer() { }
83 void hoople_service::handle_timer_callback()
86 if (!is_defunct()) handle_timer();
89 void hoople_service::close_this_program()
94 bool hoople_service::close_application(
const astring &app_name)
109 LOG(
astring(
"couldn't find process in the list of active ones."));
114 for (
int i = 0; i < pids.
length(); i++) {
117 kill(pids[i], SIGHUP);
128 void hoople_service::handle_OS_signal(
int formal(sig_id))
130 _saw_interrupt() =
true;
131 if (_global_hoople_service) {
136 void hoople_service::make_defunct()
141 bool hoople_service::setup(
const astring &app_name,
int timer_period)
146 _timer_period() = timer_period;
147 _app_name() = app_name;
149 _global_hoople_service =
this;
154 signal(SIGHUP, handle_OS_signal);
158 signal(SIGINT, handle_OS_signal);
167 const astring &app_name,
int timer_period)
169 #ifdef DEBUG_HOOPLE_SERVICE
172 if (!alert.
setup(app_name, timer_period))
return false;
177 if (_timer_period()) {
181 #ifdef DEBUG_HOOPLE_SERVICE
186 #ifdef DEBUG_HOOPLE_SERVICE
188 printf(
"%s: shout out from my main thread yo.\n",
_global_argv[0]);
192 time_control::sleep_ms(42);
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.
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.
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 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.