A while ago, I posted a question to the forum asking what to do if an
alarm is triggered in your app. and there's not enough stack free to
process it. Since nobody responded (including Palm Support ;-) ), I
thought that you might like to see how I have got around the problem.
Additionally, I welcome validation of the approach.
Essentially, when I receive an alarm event, I check to see if the event
has been launched with a new stack. If it has not then I wrap up the
command ptr. and launch flags in a structure and re-launch with my own
custom launch code. Additionally, I request a new stack. Here's a code
snippet (Teenee::AppLaunch is a utility to obtain creator id info. and
then call SysAppLaunch for the info.):
*****
Err Application::SysAppLaunchCmdAlarmTriggered(Ptr inCmdPBP, Word
inLaunchFlags)
{
LaunchCommandBlock theNewParams = {inCmdPBP, inLaunchFlags};
if (inLaunchFlags & sysAppLaunchFlagNewStack)
SysAppLaunchCmdAlarmTriggeredWithStack(reinterpret_cast<Ptr>(&theNewParams),
sysAppLaunchFlagNewStack);
else
ReturnIfErr_(Teenee::AppLaunch(
APPLICATION_CREATOR,
sysAppLaunchCmdCustomBase,
reinterpret_cast<Ptr>(&theNewParams),
sysAppLaunchFlagNewStack
));
// Ensure that there's enough space on the stack to process the
alarm.
return 0;
}
Err Application::SysAppLaunchCmdAlarmTriggeredWithStack(Ptr inCmdPBP,
Word inLaunchFlags)
{
#if ERROR_CHECK_LEVEL == ERROR_CHECK_NONE
#pragma unused(inLaunchFlags)
#endif
/*
* Set up the old parameter block
*/
ErrFatalDisplayIf(!(inLaunchFlags & sysAppLaunchFlagNewStack), "Need a
new stack");
LaunchCommandBlock& theNewCommand =
reinterpret_cast<LaunchCommandBlock&>(*inCmdPBP);
/*
* Execute the new command given our new stack environment.
*/
SysAlarmTriggeredParamType& theCommand =
reinterpret_cast<SysAlarmTriggeredParamType&>(*(theNewCommand.mCmdPBP));
. . .
return 0;
}
*****
Application::SysAppLaunchCmdAlarmTriggered is called by handling the
sysAppLaunchCmdAlarmTriggered event.
Application::SysAppLaunchCmdAlarmTriggeredWithStack is called by
handling our sysAppLaunchCmdCustomBase event.
Here's what I persist across the real alarm event and my custom one.
I've found that it is important to preserve information across the
re-launch given the potential for new globals, sub calls etc. in the
original call.
*****
struct LaunchCommandBlock
{
Ptr mCmdPBP;
Word mLaunchFlags;
};
*****
Enjoy!
--
Christopher Hunt
Class Action Pty. Ltd.
Are you a time zone traveler that owns a Palm(tm) connected organizer?
Check out http://www.classactionpl.com/TimeTraveler/index.htm