anchor_window Class Reference

Implements a graceful shutdown procedure for an application. More...

#include <anchor_window.h>

Inheritance diagram for anchor_window:

Inheritance graph
[legend]
Collaboration diagram for anchor_window:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 anchor_window ()
 constructor does very little; setup() begins operation.
virtual ~anchor_window ()
 IMPLEMENT_CLASS_NAME ("anchor_window")
bool defunct () const
 returns true if the object has been marked as defunct.
void set_defunct ()
 used by the derived class to mark that this object is about to exit.
bool setup (application_instance handle, const istring &application_name, int timing_cycle=0)
 constructs a anchor_window for the "application_name" specified.
void register_window (window_handle window)
 this supports the anchor window being created elsewhere.
virtual void handle_startup ()
 derived classes can override this to catch the application startup.
virtual void handle_timer ()
 invoked periodically if the anchor was setup() with a timer "cycle".
virtual void handle_shutdown ()
 invoked just prior to the shutdown of this window.

Static Public Member Functions

static bool close_this_program ()
 causes this particular program to shut down.
static bool close_app_window (const istring &app_name)
 closes the window associated with "app_name".
static bool launch (anchor_window &window, application_instance handle, const istring &app, int cycle=0)
 establishes an anchor window for the program named "app".
static istring make_well_known_title (const istring &application_name)
 returns the string form of the well-known window title.
static istring make_well_known_class (const istring &application_name)
 same as above but for the window's class name.

Detailed Description

Implements a graceful shutdown procedure for an application.

The advantage of the anchor_window (where it's actually a window, which is to say, under win32) is that it's hidden and has a well-known name. This allows it to be found through FindWindow to facilitate a graceful shutdown for the applications that use it. On linux, it is implemented with a shutdown_alerter object instead and is not actually a window.

Definition at line 38 of file anchor_window.h.


Constructor & Destructor Documentation

anchor_window::anchor_window (  ) 

constructor does very little; setup() begins operation.

Definition at line 63 of file anchor_window.cpp.

anchor_window::~anchor_window (  )  [virtual]

Definition at line 79 of file anchor_window.cpp.

References NIL, set_defunct(), and WHACK().


Member Function Documentation

anchor_window::IMPLEMENT_CLASS_NAME ( "anchor_window"   ) 

bool anchor_window::close_this_program (  )  [static]

causes this particular program to shut down.

this method is available for programs that support the graceful shutdown process. it causes the machinery of the anchor_window to alert the application that a graceful shutdown has been started. the method returns true if this program's anchor_window was found and sent the close message.

Reimplemented from shutdown_alerter.

Definition at line 102 of file anchor_window.cpp.

References shutdown_alerter::close_this_program(), and NIL.

bool anchor_window::close_app_window ( const istring app_name  )  [static]

closes the window associated with "app_name".

note that this closes *ALL* such windows, so if the application had more than one instance running, they will all shut down. also note: the above doesn't seem to be implemented in the current version.

Definition at line 140 of file anchor_window.cpp.

References shutdown_alerter::close_application(), FUNCDEF, LOG, make_well_known_title(), NIL, and istring::SPRINTF.

bool anchor_window::defunct (  )  const

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 120 of file anchor_window.cpp.

References shutdown_alerter::is_defunct().

void anchor_window::set_defunct (  ) 

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

Reimplemented from shutdown_alerter.

Definition at line 130 of file anchor_window.cpp.

References shutdown_alerter::set_defunct().

Referenced by ~anchor_window().

bool anchor_window::setup ( application_instance  handle,
const istring application_name,
int  timing_cycle = 0 
)

constructs a anchor_window for the "application_name" specified.

the instance "handle" is the link to the application. the window is created and made hidden if successful. the standard here for the "application_name" is that it should not have any directory components, but it should be the full program name (including extension). if "timing_cycle" is non-zero, then it is used as a timer interval. every time the interval elapses, the handle_timer() method is invoked. note that this function is invoked by launch() and does not need to be called by a user unless launch() is not being used to control the anchor window's lifetime.

Definition at line 186 of file anchor_window.cpp.

References make_well_known_class(), make_well_known_title(), NIL, register_window(), and shutdown_alerter::setup().

Referenced by launch().

void anchor_window::register_window ( window_handle  window  ) 

this supports the anchor window being created elsewhere.

when the window is created independently but should still function as an anchor_window, then this method can be used to hook in that external "window" into our support. this only makes sense for the windows version.

Definition at line 214 of file anchor_window.cpp.

Referenced by setup().

bool anchor_window::launch ( anchor_window window,
application_instance  handle,
const istring app,
int  cycle = 0 
) [static]

establishes an anchor window for the program named "app".

this function will not return until WM_CLOSE is received; it is the main message loop for a simple application. the "handle" parameter should be coming from the main function for the program. note that the "window" should be constructed but not have any functions called on it yet. this is important since this function does all the setup. using a "window" derived from anchor_window is also okay. the "cycle" is passed to the setup() method.

Definition at line 335 of file anchor_window.cpp.

References path_configuration::application_name(), shutdown_alerter::launch_console(), NIL, and setup().

void anchor_window::handle_startup (  )  [virtual]

derived classes can override this to catch the application startup.

this function is guaranteed to be called after the event processing loop has started, but before much of anything else is done in the application.

Reimplemented from shutdown_alerter.

Definition at line 96 of file anchor_window.cpp.

void anchor_window::handle_timer (  )  [virtual]

invoked periodically if the anchor was setup() with a timer "cycle".

Reimplemented from shutdown_alerter.

Definition at line 98 of file anchor_window.cpp.

void anchor_window::handle_shutdown (  )  [virtual]

invoked just prior to the shutdown of this window.

Reimplemented from shutdown_alerter.

Definition at line 100 of file anchor_window.cpp.

static istring anchor_window::make_well_known_title ( const istring application_name  )  [static]

returns the string form of the well-known window title.

this title identifies the "application_name" and is used for our hidden window. this is how the window can be found at runtime. note that this approach will only work properly if there is only one window by that name on a host at a time (due to how the windows are registered).

Referenced by close_app_window(), and setup().

static istring anchor_window::make_well_known_class ( const istring application_name  )  [static]

same as above but for the window's class name.

Referenced by setup().


The documentation for this class was generated from the following files:
Generated on Fri Aug 29 04:30:18 2008 for HOOPLE Libraries by  doxygen 1.5.1