|  |  |  |  | 
 36
 Notification Manager
  
36
 Notification ManagerNotifyMgr.h declares the API that this chapter describes. For more information on the notification manager, see the section "Notifications"  in the "Palm System Features" chapter of the Palm OS Programmer's Companion. 
SleepEventParamType struct is used in notifications of type sysNotifySleepRequestEvent to indicate why the system is going to sleep and whether sleep should be deferred. 
typedef struct {    UInt16 reason;    UInt16 deferSleep;} SleepEventParamType;
SysNotifyDisplayChangeDetailsType struct is used in notifications of type sysNotifyDisplayChangeEvent to indicate how the bit depth changed. If the two values in the struct are equal, it means that the color palette has changed instead of the bit depth. 
typedef struct {    UInt32 oldDepth;    UInt32 newDepth;} SysNotifyDisplayChangeDetailsType;
SysNotifyParamType struct defines a notification event. This struct is sent along with the typedef struct SysNotifyParamType {    UInt32	 	 	 	 notifyType;    UInt32	 	 	 	 broadcaster;    void *	 	 	 	 notifyDetailsP;    void *	 	 	 	 userDataP;    Boolean	 	 	 	 handled;    UInt8	 	 	 	 reserved2;} SysNotifyParamType;
| notifyType | The type of event that occurred. See Notification Manager Event Constants. | 
| broadcaster | The creator ID of the application that broadcast the notification (the application that called SysNotifyBroadcastorSysNotifyBroadcastDeferred), orsysNotifyBroadcasterCodeif the system broadcast the event. | 
| notifyDetailsP | Pointer to data specific to this notification. Most notifications do not use this parameter. See Notification Manager Event Constants for the specific instances where this parameter is used. | 
| userDataP | Pointer to custom data that your notification handler requires. You create this data and pass its pointer to SysNotifyRegister. | 
| handled | trueif event is handled yet;falseotherwise. In some cases, notification handlers can set this field totrueto indicate that they have handled an event. See Notification Manager Event Constants. | 
| reserved2 | Reserved for future use. | 
| Constant | Description | 
|---|---|
| sysNotifyAntennaRaisedEvent | Sent during SysHandleEventwhen the antenna is raised on a Palm VII series device. | 
| sysNotifyDisplayChangeEvent | Sent just after the color table has been set to use a specific palette or just after WinScreenModehas changed the bit depth. | 
| sysNotifyEarlyWakeupEvent | Sent during SysHandleEventimmediately after the system has finished sleeping. The screen may still be turned off, and the system may quickly go back to sleep after handling a procedure alarm or charger event. | 
| sysNotifyForgotPasswordEvent | Sent if the user taps the Lost Password button in the Security application. The notification is sent after the user has confirmed that all private records should be deleted but before the deletion actually occurs. | 
| sysNotifyLateWakeupEvent | Sent during SysHandleEventimmediately after the device has finished waking up. This is sent at the late stage of wakeup, after the screen has been turned on. | 
| sysNotifyMenuCmdBarOpenEvent | Sent during MenuHandleEventwhen it is about to display the menu shortcut command bar.
 | 
| sysNotifyResetFinishedEvent | Sent immediately after the system has finished a reset. | 
| sysNotifySleepNotifyEvent | Sent during SysHandleEventimmediately before the system is put to sleep. After the broadcast is complete, the system is put to sleep. | 
| sysNotifySleepRequestEvent | Sent during SysHandleEventprocessing when the system has decided to go to sleep.
 | 
| sysNotifySyncFinishEvent | Sent immediately after a HotSync® operation is complete. | 
| sysNotifySyncStartEvent | Sent immediately before a HotSync operation is begun. | 
| sysNotifyTimeChangeEvent | Sent just after the system time has been changed using TimSetSeconds. | 
| Constant | Value | Description | 
|---|---|---|
| sysNotifyBroadcasterCode | 'psys' | Value passed as the creator ID of the broadcaster for notifications broadcast by the system. | 
| sysNotifyDefaultQueueSize | 15 | Maximum number of nested broadcasts allowed. | 
| sysNotifyNormalPriority | 0 | Typical priority value used when registering for notifications. | 
| sysNotifyVersionNum | 1 | Current notification manager version. This number is stored in the system feature sysFtrNumNotifyMgrVersion. | 
Err SysNotifyBroadcast (SysNotifyParamType *notify)
|   |  | No error. | 
|   |  | The broadcast stack limit has already been reached. | 
|   |  | The background thread is broadcasting the notification and the notifyparameter isNULL. | 
|   |  | There is not enough space on the stack for the notification. | 
SysNotifyBroadcast call returns. This notification occurs in priority order.
 
sysNotifyDefaultQueueSize specifies how many levels of nested notification are allowed. If you reach this limit, the error sysNotifyErrBroadcastBusy is returned and your notification is not broadcast. To avoid reaching the limit, use 
WARNING!Do not callSysNotifyBroadcastfrom code that might be called from a background task (such as a trap patch) with the memory semaphore reserved. UseSysNotifyBroadcastDeferredinstead.
Err SysNotifyBroadcastDeferred (SysNotifyParamType *notify, Int16 paramSize)
|   | <->  | The notification to enqueue. See SysNotifyParamType. | 
|   | ->  | Size of the data pointed to by the field notify->notifyDetailsP. | 
|   |  | No error. | 
|   |  | There is not enough memory to allocate a new notification entry in the queue. | 
|   |  | paramSizeis a negative number. | 
|   |  | The queue has reached its maximum number of entries. | 
notify structure to a new memory chunk, which is disposed of upon completion of the broadcast. (The paramSize parameter is used when copying the notifyDetailsP portion of the notify structure.) 
Err SysNotifyRegister (UInt16 cardNo, LocalID dbID, UInt32 notifyType, SysNotifyProcPtr callbackP, Int8 priority, void *userDataP)
|   | ->  | Number of the storage card on which the application or code resource resides. | 
|   | ->  | Local ID of the application or code resource. | 
|   | ->  | The event that the application wants to receive notifications about. See Notification Manager Event Constants. | 
|   | ->  | NULLto receive the notification as an application launch code. If your code does not have aPilotMainfunction (for example, if it is a shared library), pass a pointer to a function that should be called when the notification is broadcast. SeeSysNotifyProcPtr. | 
|   | ->  | The priority with which the application should receive the event. Most applications and other code resources should always use sysNotifyNormalPriority. In rare circumstances, you may need to ensure that your code is notified toward the beginning or toward the end of the notification sequence. If so, specify a value between -15 and +15. The smaller the priority, the earlier your code is notified. | 
|   | ->  | Caller-defined data to pass to the notification handler. | 
NULL as the callbackP parameter. In this case, the system notifies your application by sending it the callbackP. This callback should follow the prototype shown in SysNotifyRegister, even if you specify a callback function. 
 
IMPORTANT: Because thecallbackPpointer is used to directly call the function, the pointer must remain valid from the timeSysNotifyRegisteris called to the time the notification is broadcast. If the function is in a shared library, you must keep the library open. If the function is in a separately loaded code resource, the resource must remain locked while registered for the notification. When you close a library or unlock a resource, you must first unregister for any notifications. If you don't, the system will crash when the notification is broadcast.
sysAppLaunchCmdNotify or uses the callback function, the notification handler may perform any processing necessary. As with most launch codes, it's not possible to access global variables. If the handler needs access to any particular value to respond to the notification, pass a pointer to that value in the userDataP parameter. The system passes this pointer back to your application or callback function in the launch code's parameter block. 
 
SysHandleEvent. 
Err SysNotifyUnregister(UInt16 cardNo, LocalID dbID, UInt32 notifyType, Int8 priority)
|   | ->  | Number of the storage card on which the application or code resource resides. | 
|   | ->  | Local ID of the application or code resource. | 
|   | ->  | The event to unregister for. See Notification Manager Event Constants. | 
|   | ->  | The priority value you passed as part of SysNotifyRegister. | 
Err (*SysNotifyProcPtr) (SysNotifyParamType *notifyParamsP)
|   | ->  | Pointer to a structure that contains the notification event that occurred and any other information about it. See SysNotifyParamType. | 
PilotMain for a notification. See the description of 
IMPORTANT: Because thecallbackPpointer is used to directly call the function, the pointer must remain valid from the timeSysNotifyRegisteris called to the time the notification is broadcast. If the function is in a shared library, you must keep the library open. If the function is in a separately loaded code resource, the resource must remain locked while registered for the notification. When you close a library or unlock a resource, you must first unregister for any notifications. If you don't, the system will crash when the notification is broadcast.
|   |  |  |  |  |   |