home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * Quit.c
- *
- * This is a support file for "Grant's CGI Framework".
- * Please see the license agreement that accompanies the distribution package
- * for licensing details.
- *
- * Copyright ©1995,1996 by Grant Neufeld
- * grant@acm.com
- * http://arpp.carleton.ca/grant/
- *
- *****/
-
- #include "MyConfiguration.h"
-
- #include "compiler_stuff.h"
- #include "globals.h"
-
- #include "EventUtil.h"
- #include "LogUtil.h"
- #include "MemoryUtil.h"
- #include "ProcessUtil.h"
- #include "WindowInt.h"
-
- #include "Quit.h"
-
-
- /*** INTERFACE ***/
-
- /* Handle an interface or scripting call to quit the applciation */
- void
- doQuitApp ( void )
- {
- /* set application to quit */
- gQuit = true;
- } /* doQuitApp */
-
-
- /*** FUNCTIONS ***/
- #pragma mark -
-
- /* Confirm that the application can quit, prompt the user if necessary.
- Clean up, if the application can quit.
- Return true if application is set to quit, false if it can't quit. */
- Boolean
- QuitPrepare ( Boolean allowUserInteract )
- {
- Boolean memoryLow;
- Boolean gotEvent;
- EventRecord theEvent;
- Boolean success;
-
- gQuit = true;
-
- /* check for emergency memory store. If it isn't available, memory is low */
- memoryLow = !IsEmergencyMemAvail ();
-
- /* Should add check for outstanding events and handle them as appropriate.
- Especially important is to check for any queued high level events. */
- if ( !memoryLow )
- {
- /* check for outstanding events and handle them as appropriate */
- do
- {
- gotEvent = WaitNextEvent ( highLevelEventMask, &theEvent, 0, NULL );
- if ( gotEvent )
- {
- /* • Need to figure out a good way to distinguish between idle time
- quits and others. So, if quitting on idle and an event is
- found gQuit will be reset to false. Otherwise, if quitting
- normally and an event is found gQuit will be left alone. */
- switch ( theEvent.what )
- {
- case kHighLevelEvent :
- doHighLevelEvent ( &theEvent );
- break;
- }
- }
- } while ( gotEvent == true );
- }
-
- #if kCompileWithForeground
- /* get rid of document windows */
- success = WindowCloseAll ( (!memoryLow) && allowUserInteract );
-
- if ( success || !allowUserInteract || memoryLow )
- #endif /* kCompileWithForeground */
- {
- #if kCompileWithThreadsOptional
- if ( gHasThreadMgr )
- #endif
- {
- /* while there remain other threads, let them finish before quitting */
- ThreadFinishAllSubThreads ();
- }
-
- success = CustomQuit ( allowUserInteract );
-
- /* close up the log file */
- LogQuit ();
-
- /* can quit if successful or user is not allowed to interact */
- gQuit = ( success || !allowUserInteract || memoryLow );
- }
- #if kCompileWithForeground
- else
- {
- gQuit = false;
- }
- #endif
-
- return gQuit;
- } /* QuitPrepare */
-
-
- /* force the application to quit, doing necessary cleanup. */
- p_export
- void
- ForceQuit ( void )
- {
- /* quit with no user interaction */
- QuitPrepare ( false );
-
- ExitToShell ();
- } /* ForceQuit */
-
-
- /** Utilities **/
- #pragma mark -
-
- #if kCompileWithQuitOnLongIdle
- p_export
- void
- ResetQuitIdleTimer ( void )
- {
- if ( gDoIdleQuit )
- {
- gTimeLastAction = TickCount ();
- }
- } /* ResetQuitIdleTimer */
- #endif
-
-
- /***** EOF *****/
-