sysAppLaunchCmdNormalLaunch
, which tells the application to perform a full launch and display its user interface.
PilotMain
. PilotMain
is the entry point for all applications.
PilotMain
from the Datebook application as an example. To see the complete example, go to the examples folder in the Palm OS SDK and look at the file Datebook.c
.
UInt32 PilotMain (UInt16 cmd, void *cmdPBP, UInt16 launchFlags)
{
    return DBPilotMain(cmd, cmdPBP, launchFlags);
}
static UInt32 DBPilotMain (UInt16 cmd, void *cmdPBP, UInt16 launchFlags)
{
    UInt16 error;
    Boolean launched;
    // This app makes use of PalmOS 2.0 features.It will crash if
    // run on an earlier version of PalmOS. Detect and warn if this
    // happens, then exit.
    error = RomVersionCompatible (version20, launchFlags);
    if (error)
    return error;
    // Launch code sent by the launcher or the datebook button.
    if (cmd == sysAppLaunchCmdNormalLaunch)
    {
    error = StartApplication ();
    if (error) return (error);
    FrmGotoForm (DayView);
    EventLoop ();
    StopApplication ();
    }
   
    // Launch code sent by text search.
    else if (cmd == sysAppLaunchCmdFind)
    {
    Search ((FindParamsPtr)cmdPBP);
    }
   
    // This launch code might be sent to the app when it's already
    // running if the user hits the "Go To" button in the Find
    // Results dialog box.
    else if (cmd == sysAppLaunchCmdGoTo)
    {
    launched = launchFlags & sysAppLaunchFlagNewGlobals;
    if (launched)
    {
    error = StartApplication ();
    if (error) return (error);
    GoToItem ((GoToParamsPtr) cmdPBP, launched);
    EventLoop ();
    StopApplication ();
    }
    else
    GoToItem ((GoToParamsPtr) cmdPBP, launched);
    }
    // Launch code sent by sync application to notify the datebook
    // application that its database was been synced.
    // ...
    // Launch code sent by Alarm Manager to notify the datebook
    // application that an alarm has triggered.
    // ...
    // Launch code sent by Alarm Manager to notify the datebook
    // application that is should display its alarm dialog.
    // ...
    // Launch code sent when the system time is changed.
    // ...
    // Launch code sent after the system is reset. We use this time
    // to create our default database if this is a hard reset
    // ...
    // Launch code sent by the DesktopLink server when it create
    // a new database. We will initialize the new database.
    return (0);
}
sysAppLaunchCmdNormalLaunch
, it begins with a startup routine, then goes into an event loop, and finally exits with a stop routine. (The event loop is described in Chapter 4, "Event Loop." The stop routine is shown in the section "Stopping an Application" at the end of this chapter.)
sysAppLaunchCmdNormalLaunch
by calling a function named StartApplication
. Listing 3.2 shows the StartApplication
function.
static UInt16 StartApplication (void)
{
    UInt16 error = 0;
    Err err = 0;
    UInt16 mode;
    DateTimeType dateTime;
    DatebookPreferenceType prefs;
    SystemPreferencesType sysPrefs;
    UInt16 prefsSize;
    // Step 1: Get system-wide preferences.
    PrefGetPreferences (&sysPrefs);
    // Determime if secret records should be displayed.
    HideSecretRecords = sysPrefs.hideSecretRecords;
   
    if (HideSecretRecords)
    mode = dmModeReadWrite;
    else
    mode = dmModeReadWrite | dmModeShowSecret;
    // Get the time formats from the system preferences.
    TimeFormat = sysPrefs.timeFormat;
    // Get the date formats from the system preferences.
    LongDateFormat = sysPrefs.longDateFormat;
    ShortDateFormat = sysPrefs.dateFormat;
    // Get the starting day of the week from the
    // system preferences.
    StartDayOfWeek = sysPrefs.weekStartDay;
   
    // Get today's date.
    TimSecondsToDateTime (TimGetSeconds (), &dateTime);
    Date.year = dateTime.year - firstYear;
    Date.month = dateTime.month;
    Date.day = dateTime.day;
    // Step 2. Find the application's data file. If it doesn't
// exist, create it.
    ApptDB = DmOpenDatabaseByTypeCreator(datebookDBType,
sysFileCDatebook, mode);
    if (! ApptDB)
    {
    error = DmCreateDatabase (0, datebookDBName, sysFileCDatebook,
    datebookDBType, false);
    if (error) return error;
   
    ApptDB = DmOpenDatabaseByTypeCreator(datebookDBType,
sysFileCDatebook, mode);
    if (! ApptDB) return (1);
    error = ApptAppInfoInit (ApptDB);
    if (error) return error;
    }
   
    // Step 3. Get application-specific preferences.
    // Read the preferences / saved-state information. There is
    // only one version of the DateBook preferences so don't worry
    // about multiple versions.
    prefsSize = sizeof (DatebookPreferenceType);
    if (PrefGetAppPreferences (sysFileCDatebook, datebookPrefID,
&prefs, &prefsSize,
    true) != noPreferenceFound)
    {
    DayStartHour = prefs.dayStartHour;
    DayEndHour = prefs.dayEndHour;
    AlarmPreset = prefs.alarmPreset;
    NoteFont = prefs.noteFont;
    SaveBackup = prefs.saveBackup;
    ShowTimeBars = prefs.showTimeBars;
    CompressDayView = prefs.compressDayView;
    ShowTimedAppts = prefs.showTimedAppts;
    ShowUntimedAppts = prefs.showUntimedAppts;
    ShowDailyRepeatingAppts = prefs.showDailyRepeatingAppts;
    }
    // Step 4. Initialize any other global variables.
    TopVisibleAppt = 0;
    CurrentRecord = noRecordSelected;
   
    // Load the far call jump table.
    FarCalls.apptGetAppointments = ApptGetAppointments;
    FarCalls.apptGetRecord = ApptGetRecord;
    FarCalls.apptFindFirst = ApptFindFirst;
    FarCalls.apptNextRepeat = ApptNextRepeat;
    FarCalls.apptNewRecord = ApptNewRecord;
    FarCalls.moveEvent = MoveEvent;
    return (error);
}
sysAppLaunchCmdNormalLaunch
, it decides if it should respond to that launch code. If it responds to the launch code, it does so by implementing a launch code handler, which is invoked from its PilotMain
function.
sysAppLaunchCmdNormalLaunch
(see Listing 3.2) or
sysAppLaunchCmdGoto
; so if the application hasn't received either of these launch codes, its global variables are usually not allocated and not accessible. In addition, if the application has multiple code segments, you cannot access code outside of segment 0 (the first segment) if the application has no access to global variables.
sysAppLaunchCmdURLParams
. If this launch code results from a palm
URL, then globals are available. If the launch code results from a palmcall
URL, then globals are not available. The URL is passed to your application in the launch parameter block.
NOTE:  Static local variables are stored with the global variables on the system's dynamic heap. They are not accessible if global variables are not accessible.
sysAppLaunchFlagNewGlobals
flag is set, then your application's global variables have been allocated on this launch. This flag is set by the system and isn't (and shouldn't be) set by the sender of a launch code.
Boolean appHasGlobals = launchFlags & sysAppLaunchFlagNewGlobals
;
sysAppLaunchCmdNormalLaunch
or sysAppLaunchCmdGoTo
, you can find out if it is the current application by checking the launch flags that are sent with the launch code. If the application is the currently running application, the sysAppLaunchFlagSubCall
flag is set. This flag is set by the system and isn't (and shouldn't be) set by the sender of a launch code.
Boolean appIsActive = launchFlags & sysAppLaunchFlagSubCall;
SysAppLaunch
. This routine notifies the system which application to launch next and feeds an application-quit event into the event queue. If and when the current application responds to the quit event and returns, the system launches the new application.
SysUIAppSwitch
or SysAppLaunch
, you must call
MemPtrSetOwner
to grant ownership of the parameter block chunk to the OS (your application is originally set as the owner). If the parameter block structure contains references by pointer or handle to any other chunks, you also must set the owner of those chunks by calling MemPtrSetOwner
or
MemHandleSetOwner
. If you don't change the ownership of the parameter block, it will get freed before the application you're launching has a chance to use it.
WARNING!Do not use the SysUIAppSwitch or SysAppLaunch functions to open the Application Launcher application.
appStopEvent
. Note that this is an event, not a launch code. The application must detect this event and terminate. (You'll learn more about events in the next chapter.)
StopApplication
routine from Datebook.c
.
static void StopApplication (void)
{
    DatebookPreferenceType prefs;
   
    // Write the preferences / saved-state information.
    prefs.noteFont = NoteFont;
    prefs.dayStartHour = DayStartHour;
    prefs.dayEndHour = DayEndHour;
    prefs.alarmPreset = AlarmPreset;
    prefs.saveBackup = SaveBackup;
    prefs.showTimeBars = ShowTimeBars;
    prefs.compressDayView = CompressDayView;
    prefs.showTimedAppts = ShowTimedAppts;
    prefs.showUntimedAppts = ShowUntimedAppts;
    prefs.showDailyRepeatingAppts = ShowDailyRepeatingAppts;
    // Write the state information.
    PrefSetAppPreferences (sysFileCDatebook, datebookPrefID,
datebookVersionNum, &prefs, sizeof (DatebookPreferenceType),
true);
    // Send a frmSave event to all the open forms.
    FrmSaveAllForms ();
   
    // Close all the open forms.
    FrmCloseAllForms ();
    // Close the application's data file.
    DmCloseDatabase (ApptDB);
}
SystemMgr.h
. All the parameters for a launch code are passed in a single parameter block, and the results are returned in the same parameter block.
Code | Request |
---|---|
scptLaunchCmdExecuteCmd | Execute the specified Network login script plugin command. |
scptLaunchCmdListCmds | Provide information about the commands that your Network script plugin executes. |
sysAppLaunchCmdAddRecord
| Add a record to a database. |
sysAppLaunchCmdAlarmTriggered
| Schedule next alarm or perform quick actions such as sounding alarm tones. |
sysAppLaunchCmdCountryChange
| Respond to country change. |
sysAppLaunchCmdDisplayAlarm
| Display specified alarm dialog or perform time-consuming alarm-related actions. |
sysAppLaunchCmdExgAskUser
| Let application override display of dialog asking user if they want to receive incoming data via the exchange manager. |
sysAppLaunchCmdExgReceiveData
| Notify application that it should receive incoming data via the exchange manager. |
sysAppLaunchCmdFind | Find a text string. |
sysAppLaunchCmdGoto | Go to a particular record, display it, and optionally select the specified text. |
sysAppLaunchCmdGoToURL | Launch Clipper application and open a URL. (Palm VII system only.) |
sysAppLaunchCmdInitDatabase | Initialize database. |
sysAppLaunchCmdLookup
|
Look up data. In contrast to sysAppLaunchCmdFind , a level of indirection is implied. For example, look up a phone number associated with a name.
|
sysAppLaunchCmdNormalLaunch | Launch normally. |
sysAppLaunchCmdNotify | Broadcast a notification. |
sysAppLaunchCmdOpenDB | Launch application and open a database. (Palm VII system only.) |
sysAppLaunchCmdPanelCalledFromApp | Tell preferences panel that it was invoked from an application, not the Preferences application. |
sysAppLaunchCmdReturnFromPanel | Tell an application that it's restarting after preferences panel had been called. |
sysAppLaunchCmdSaveData | Save data. Often sent before find operations. |
sysAppLaunchCmdSyncNotify | Notify applications that a HotSync has been completed. |
sysAppLaunchCmdSystemLock | Sent to the Security application to request that the system be locked down. |
sysAppLaunchCmdSystemReset | Respond to system reset. No UI is allowed during this launch code. |
sysAppLaunchCmdTimeChange | Respond to system time change. |
sysAppLaunchCmdURLParams | Launch an application with parameters from Clipper. (Palm VII system only.) |
  |   |