feisty meow concerns codebase  2.140
application::hoople_service Class Reference

A platform-independent way to alert a program that it should shut down immediately. More...

#include <hoople_service.h>

Inheritance diagram for application::hoople_service:
Collaboration diagram for application::hoople_service:

Public Member Functions

 hoople_service ()
 constructor does very little; setup() is what begins operation. More...
 
virtual ~hoople_service ()
 
 DEFINE_CLASS_NAME ("hoople_service")
 
bool setup (const basis::astring &app_name, int timer_period=0)
 constructs a hoople_service for the "app_name" specified. More...
 
bool saw_interrupt ()
 reports whether the process saw an interrupt from the user. More...
 
virtual void handle_startup ()
 this function is called once the program has begun operation. More...
 
virtual void handle_shutdown ()
 called during the program's shutdown process. More...
 
virtual void handle_timer ()
 called periodically if a timer period was specified. More...
 

Static Public Member Functions

static bool is_defunct ()
 returns true if the object has been marked as defunct. More...
 
static void make_defunct ()
 used by the derived class to mark that this object is about to exit. More...
 
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. More...
 
static void close_this_program ()
 causes this particular application to begin shutting down. More...
 
static bool close_application (const basis::astring &app_name)
 attempts to close the application named "app_name". More...
 
static void handle_OS_signal (int sig_id)
 processes the signal from the OS when its time to shut down. More...
 

Detailed Description

A platform-independent way to alert a program that it should shut down immediately.

This can provide a service management feature for graceful shutdown of an application, allowing it a chance to close its objects cleanly, rather than just being whacked in the middle of whatever it's doing. Only one of these objects should be instantiated per program, but the static methods can be used from anywhere in the program.

Definition at line 34 of file hoople_service.h.

Constructor & Destructor Documentation

◆ hoople_service()

application::hoople_service::hoople_service ( )

constructor does very little; setup() is what begins operation.

Definition at line 65 of file hoople_service.cpp.

◆ ~hoople_service()

application::hoople_service::~hoople_service ( )
virtual

Definition at line 69 of file hoople_service.cpp.

Member Function Documentation

◆ close_application()

bool application::hoople_service::close_application ( const basis::astring app_name)
static

attempts to close the application named "app_name".

this can only be done if this program possesses sufficient rights to zap that program.

Definition at line 94 of file hoople_service.cpp.

References processes::process_control::find_process_in_list(), FUNCDEF, basis::array< contents >::length(), LOG, and processes::process_control::query_processes().

◆ close_this_program()

void application::hoople_service::close_this_program ( )
static

causes this particular application to begin shutting down.

this is a static method available for programs that support the hoople_service's graceful shutdown process. it causes the application to begin the shutdown.

Definition at line 89 of file hoople_service.cpp.

◆ DEFINE_CLASS_NAME()

application::hoople_service::DEFINE_CLASS_NAME ( "hoople_service"  )

◆ handle_OS_signal()

void application::hoople_service::handle_OS_signal ( int  sig_id)
static

processes the signal from the OS when its time to shut down.

Definition at line 128 of file hoople_service.cpp.

◆ handle_shutdown()

void application::hoople_service::handle_shutdown ( )
virtual

called during the program's shutdown process.

this is invoked just prior to the destruction of this class which is also just before the shutdown of the program overall. in this method, the derived object must ensure that any threads the program started get stopped, that any opened files get closed, and that any other resources are released. this is the application's last chance to clean up.

Definition at line 79 of file hoople_service.cpp.

Referenced by launch_console().

◆ handle_startup()

void application::hoople_service::handle_startup ( )
virtual

this function is called once the program has begun operation.

Definition at line 77 of file hoople_service.cpp.

Referenced by launch_console().

◆ handle_timer()

void application::hoople_service::handle_timer ( )
virtual

called periodically if a timer period was specified.

Definition at line 81 of file hoople_service.cpp.

◆ is_defunct()

static bool application::hoople_service::is_defunct ( )
inlinestatic

returns true if the object has been marked as defunct.

this means that it is either shutting down or soon will be.

Definition at line 53 of file hoople_service.h.

Referenced by launch_console().

◆ launch_console()

bool application::hoople_service::launch_console ( hoople_service alert,
const basis::astring app_name,
int  timer_period = 0 
)
static

this is used to begin execution of a console mode application.

this method does not do anything except sit while the extant threads are in play. it will not return until the program must exit, as caused by close_this_program() or close_application().

Definition at line 166 of file hoople_service.cpp.

References application::_global_argv, FUNCDEF, handle_shutdown(), handle_startup(), is_defunct(), program_wide_timer, timely::time_stamp::reset(), basis::SECOND_ms, and setup().

◆ make_defunct()

void application::hoople_service::make_defunct ( )
static

used by the derived class to mark that this object is about to exit.

note that this can be used anywhere in the program to initiate an exit of the program.

Definition at line 136 of file hoople_service.cpp.

◆ saw_interrupt()

bool application::hoople_service::saw_interrupt ( )
inline

reports whether the process saw an interrupt from the user.

Definition at line 61 of file hoople_service.h.

◆ setup()

bool application::hoople_service::setup ( const basis::astring app_name,
int  timer_period = 0 
)

constructs a hoople_service for the "app_name" specified.

this can be any string, although it might be processed for certain operating systems. also, for close_this_program() to work properly, it must be the application's basename. the "timer_period" specifies how frequently to invoke the handle_timer() method during runtime. if it's zero, then no timer will be used.

Definition at line 141 of file hoople_service.cpp.

Referenced by launch_console().


The documentation for this class was generated from the following files: