Class Overview
This class provides standard application methods for the Monsterworks' Framework. It embodies the singleton pattern and must be created on the heap (not on the stack) because of its protected destructor.
Inheritance
The class is a subcass of the PowerPlant LApplication class.
Requirements
Use of this class requires a substantial portion of the PowerPlant and Monsterworks' Framework.
Files
- CCGIThreadApp.h
- CCGIThreadApp.ip
- CCGIThreadApp.cp
public
CCGIApp(
void
);
virtual
void
DeleteApp(
void
);
virtual
void
CheckMe(
void
);
static
void
CheckUs(
void
);
virtual
void
Run(
void
);
virtual
Boolean
ObeyCommand(
CommandT inCommand,
void* ioParam
);
virtual
void
FindCommandStatus(
CommandT inCommand,
Boolean& outEnabled,
Boolean& outUsesMark,
UInt16& outMark,
Str255 outName
);
void
SetLogPreferences(
void
);
virtual
void
Log(
const LStr255& inEntryStr
);
virtual
void
Log(
const unsigned char* inEntryStr
);
virtual
void
LogError(
const LStr255& inErrorStr,
bool isFatal = false
);
virtual
void
LogError(
const unsigned char* inErrorStr,
bool isFatal = false
);
virtual
void
EventStarted(
void
);
virtual
void
EventFinished(
void
);
static
const CCGIApp*
CCGIAppP (
void
);
protected
virtual
~CCGIApp(
void
);
virtual
void
Initialize(
void
);
virtual
OSErr
HandleWWWEvent(
const AppleEvent* inEventP,
AppleEvent* outReplyP,
long inRefCon
);
LPreferencesFile*
PrefsP(
void
);
private
static pascal
OSErr
WWWHandler(
const AppleEvent* inEventP,
AppleEvent* outReplyP,
long inRefCon
);
CCGIApp(
const CCGIApp&
);
const CCGIApp&
operator=(
const CCGIApp&
);
LWindow*
myWindowP;
LStaticText*
myLastHitPaneP;
LStaticText*
myTotalHitsPaneP;
LStaticText*
myLogFilePaneP;
StDeleter<LPreferencesFile>
myPrefFileP;
StResource
myLogPrefsH;
struct SCGILogPrefs;
SCGILogPrefs*
myLogPrefsP;
static CCGIApp*
ourCCGIApp;
statics
static
void
CheckUs(
void
);
static
const CCGIApp*
CCGIAppP (
void
);
static pascal
OSErr
WWWHandler(
const AppleEvent* inEventP,
AppleEvent* outReplyP,
long inRefCon
);
overrides
virtual
void
Run(
void
);
virtual
Boolean
ObeyCommand(
CommandT inCommand,
void* ioParam
);
virtual
void
FindCommandStatus(
CommandT inCommand,
Boolean& outEnabled,
Boolean& outUsesMark,
UInt16& outMark,
Str255 outName
);
virtual
void
Initialize(
void
);
new virtuals
virtual
void
DeleteApp(
void
);
virtual
void
CheckMe(
void
);
virtual
void
Log(
const LStr255& inEntryStr
);
virtual
void
Log(
const unsigned char* inEntryStr
);
virtual
void
LogError(
const LStr255& inErrorStr,
bool isFatal = false
);
virtual
void
LogError(
const unsigned char* inErrorStr,
bool isFatal = false
);
virtual
void
EventStarted(
void
);
virtual
void
EventFinished(
void
);
virtual
~CCGIApp(
void
);
virtual
OSErr
HandleWWWEvent(
const AppleEvent* inEventP,
AppleEvent* outReplyP,
long inRefCon
);
Structs
struct SCGILogPrefs;
This struct is used internally by the class to store logging preferences. Users should not rely on its internal layout.
Member Data
LWindow*
myWindowP;
LStaticText*
myLastHitPaneP;
LStaticText*
myTotalHitsPaneP;
LStaticText*
myLogFilePaneP;
Pointers to items in the application's window which change frequently.
StDeleter<LPreferencesFile>
myPrefFileP;
myPrefFileP is a pointer to the preferences file for the application. It will delete the preferences file object upon destruction.
StResource
myLogPrefsH;
myLogPrefsH is the resource handle to the SCGILogPrefs resource in the preferences file. It will release the resource upon destruction.
SCGILogPrefs*
myLogPrefsP;
myLogPrefsP is a pointer to the SCGILogPrefs resource in the preferences file.
static
CCGIApp*
ourCCGIApp;
This is really just a static name for this since the CCGIApp is a singleton.
Ctor/Dtor/Copy
CCGIApp
Constructs a CCGIApp.
CCGIApp(
void
);
This method is implemented.
CCGIApp(
const CCGIApp&
);
This class does not implement a copy constructor.
operator=
This class does not implement an assignment operator.
const CCGIApp&
operator=(
const CCGIApp&
);
Initialize
This overrides LApplication's Initialize to install the debug menu.
virtual void Initialize (void);
~CCGIApp
This method deletes the CCGIApp.
virtual ~CCGIApp (void);
DeleteApp
This method will delete the CCGIApp after deleting any running CCGIThreads.
This method will not be completed if called from a CCGIThread. As a result the CCGIApp will not be deleted although all CCGIThreads will be deleted.
virtual
void
DeleteApp(
void
);
Object Validation
CheckMe
This method will check the internal structure of a CCGIApp.
This method will probably throw an exception if called from within a constructor of a CCGIApp. The solution the framework takes to avoid this is to statically bind all calls to CheckMe from within member methods.
virtual
void
CheckMe(
void
);
CheckUs
This method will check the static internal structure of a CCGIApp.
This method will probably throw an exception if called from within a constructor of a CCGIApp. The solution the framework takes to avoid this is to statically bind all calls to CheckUs from within member methods.
static
void
CheckUs(
void
);
LApplication
Run
This overrides the LApplication version of Run by removing the try block around event processing. This insures that all exceptions are handled by the user of the framework.
virtual
void
Run(
void
);
ObeyCommand
This overrides the LApplication version of ObeyCommand to add the ability to set logging preferences.
virtual
Boolean
ObeyCommand(
CommandT inCommand,
void* ioParam
);
FindCommandStatus
This overrides the LApplication version of FindCommandStatus to add the ability to set logging preferences.
virtual
void
FindCommandStatus(
CommandT inCommand,
Boolean& outEnabled,
Boolean& outUsesMark,
UInt16& outMark,
Str255 outName
);
Logging
Log
Write a string out to the Log file.
virtual
void
Log(
const LStr255& inEntryStr
);
- inEntryStr
- is the string to log.
virtual
void
Log(
const unsigned char* inEntryStr
);
- inEntryStr
- is the string to log.
LogError
Used to indicate an error has occured. It will log the error, update the application's window and possibly terminate the application.
virtual
void
LogError(
const LStr255& inErrorStr,
bool isFatal = false
);
- inErrorStr
- is the string written to the log file.
- isFatal
- determines whether the application should quit,
true indicates the application should quit,
false indicates the application should continue
virtual
void
LogError(
const unsigned char* inErrorStr,
bool isFatal = false
);
- inErrorStr
- is the string written to the log file.
- isFatal
- determines whether the application should quit,
true indicates the application should quit,
false indicates the application should continue
WWW Event Handling
EventStarted
This method updates the application's window when a new CGI request is received.
virtual
void
EventStarted(
void
);
EventFinished
This method updates the application's window when a CGI request is completed.
virtual
void
EventFinished(
void
);
HandleWWWEvent
This method is the "real" event handler. Its current implementation is to create a CCGIThread and resume it.
virtual
OSErr
HandleWWWEvent (
const AppleEvent* inEventP,
AppleEvent* outReplyP,
long inRefCon
);
- inEventP
- is the event to be handled.
- outReplyP
- is the event to be used to reply to the
AppleEvent.
- inRefCon
- is the reference constant passed in by the System.
WWWHandler
This method passes its arguments to HandleWWWEvent.
static pascal
OSErr
WWWHandler(
const AppleEvent* inEventP,
AppleEvent* outReplyP,
long inRefCon
);
- inEventP
- is the event to be handled.
- outReplyP
- is the event to be used to reply to the
AppleEvent.
- inRefCon
- is the reference constant passed in by the System.
Preferences
SetLogPreferences
This is the method associated with the command to set Logging preferences.
void
SetLogPreferences(
void
);
PrefsP
This allows access to the application's preferences file.
LPreferencesFile*
PrefsP(
void
);
Static Pointer
CCGIAppP
This allows static access to the single CCGIApp.
static
const CCGIApp*
CCGIAppP (
void
); |