notifymgr.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. {$MACRO ON}
  2. {$define Rsc := }
  3. (******************************************************************************
  4. *
  5. * Copyright (c) 1998-2000 Palm, Inc. or its subsidiaries.
  6. * All rights reserved.
  7. *
  8. * File: NotifyMgr.h
  9. *
  10. * Release: Palm OS SDK 4.0 (63220)
  11. *
  12. * Description:
  13. * Include file for Notification Manager
  14. *
  15. * History:
  16. * 6/15/98 JED - Created by Jesse Donaldson
  17. * 12/23/99 jmp - Fix <> vs. "" problem.
  18. * 10/19/00 PPL - Change cncNotifyCurrentConfigurationChange 'conf'
  19. * to cncNotifyProfileEvent 'cncp'
  20. *
  21. *****************************************************************************)
  22. {$IFNDEF FPC_DOTTEDUNITS}
  23. unit notifymgr;
  24. {$ENDIF FPC_DOTTEDUNITS}
  25. interface
  26. {$IFDEF FPC_DOTTEDUNITS}
  27. uses PalmApi.Palmos, PalmApi.Coretraps, PalmApi.Datamgr, PalmApi.Localemgr, PalmApi.Systemresources;
  28. {$ELSE FPC_DOTTEDUNITS}
  29. uses palmos, coretraps, datamgr, localemgr, systemresources;
  30. {$ENDIF FPC_DOTTEDUNITS}
  31. type
  32. SysNotifyParamType = record
  33. notifyType: UInt32; // What type of event occurred?
  34. broadcaster: UInt32; // normally creator code of broadcasting app
  35. notifyDetailsP: Pointer; // ptr to notification-specific data, if any
  36. userDataP: Pointer; // user specified ptr passed back with notification
  37. handled: Boolean; // true if event is handled yet
  38. reserved2: UInt8;
  39. end;
  40. type
  41. SysNotifyProc = function (var notifyParamsP: SysNotifyParamType): Err;
  42. SysNotifyProcPtr = SysNotifyProc;
  43. const
  44. sysNotifyNormalPriority = 0; // clients should use this priority
  45. sysNotifyBroadcasterCode = sysFileCSystem; // broadcaster code for events broadcast by the system
  46. sysNotifyNoDatabaseID = $FFFFFFFF; // for system use only!!!
  47. sysNotifyVersionNum = 1; // version of the NotifyMgr, obtained from the feature
  48. // The queue is much smaller in debug builds so that we aren't tempted to overflow it
  49. // (and larger for release builds so that when we do, it will work).
  50. sysNotifyDefaultQueueSize = 30;
  51. (*
  52. Notify Manager Events:
  53. Note that in general, for notifications regarding the creation of information
  54. (e.g. sysNotifyDBAddedEvent) the broadcast goes out AFTER the fact (e.g.,
  55. after the database has been created) and that notifications regarding
  56. the deletion of information are broadcast BEFORE the fact. A notable and
  57. unfortunate exception to this rule is the database deleted notification, which
  58. is sent out after the fact.
  59. The sleep & wake notifications require a little special attention. These
  60. notifications are _not_ guaranteed to always be broadcast, and hence are unsuitable
  61. for applications where syscall hardware must be shut off to conserve power when
  62. we go to sleep. For example, the sleep notification will not be broadcast when
  63. we do an emergency shutdown due to low battery conditions. Also note that any
  64. sort of prolonged activity (especially displaying UI sich as a dialog) in response
  65. to these noticfications can complicate things immensely. UI is very tricky because
  66. these notifications are broadcast from SysHandleEvent. The result is that you may
  67. receive more than one sleep notification if one of the notification clients puts up
  68. a dialog or something, and it remains there long enough for another AutoOff event
  69. to come through. There are also possible problems with reentrancy and stack space
  70. usage since the notification is broadcast from SysHandleEvent inside an application's
  71. event loop.
  72. *)
  73. sysNotifySyncStartEvent = Rsc('hots');
  74. // Sent at the start of a hotsync.
  75. // Always sent from UI thread.
  76. // param: none
  77. sysNotifySyncFinishEvent = Rsc('sync');
  78. // Sent at the end of a hotsync.
  79. // Always sent from UI thread.
  80. // param: none
  81. sysNotifyAntennaRaisedEvent = Rsc('tena');
  82. // Sent when the antenna is raised on a
  83. // Palm VII series device.
  84. // Always sent from UI thread.
  85. // param: none
  86. sysNotifyResetFinishedEvent = Rsc('rstf');
  87. // Broadcast after all app launchcodes
  88. // are sent after a reset.
  89. // Always sent from UI thread.
  90. // param: none
  91. sysNotifyForgotPasswordEvent = Rsc('bozo');
  92. // Broadcast when the user presses the
  93. // 'Forgotten Password' button in the
  94. // security app, just before every database's
  95. // private records are deleted.
  96. sysNotifyTimeChangeEvent = Rsc('time');
  97. // Broadcast when the time is changed by the user.
  98. // param: Int32*, ptr to time change delta in
  99. // seconds (e.g., a value of 100 means that the
  100. // user set the clock ahead 100 seconds).
  101. sysNotifySleepRequestEvent = Rsc('slpq');
  102. // A "Sleep Request Event" is broadcast when the device
  103. // is about to go to sleep, and is a chance for clients
  104. // to do perform an action or even delay going to sleep
  105. // for a little while. This may be broadcast multiple
  106. // times if one or more clients defer the sleep. Parameter
  107. // is a pointer to a SleepEventParamType. See below
  108. // details on this structure. Note that this event is
  109. // NOT guaranteed to be broadcast. See the big comment
  110. // at the top of this list for important detials & warnings.
  111. // Always sent from UI thread.
  112. sysNotifySleepNotifyEvent = Rsc('slp!');
  113. // A "Sleep Notify Event" is broadcast when the device is
  114. // definitely going to sleep as soon as the broadcast
  115. // is finished. Parameter is unused.
  116. // Note that this event is NOT guaranteed to be broadcast.
  117. // See the big comment at the top of this list for
  118. // important detials & warnings.
  119. // Always sent from UI thread.
  120. sysNotifyEarlyWakeupEvent = Rsc('worm');
  121. // ...the early bird gets the worm...
  122. // Broadcast just after the device wakes up
  123. // at the early stage where the screen may
  124. // still be turned off and we may quickly go
  125. // back to sleep after handling an alarm or
  126. // charger event.
  127. // Always sent from UI thread.
  128. sysNotifyLateWakeupEvent = Rsc('lazy');
  129. // Broadcast after the device wakes up
  130. // at the later stage of the wakeup
  131. // process after we turn the screen on,
  132. // broadcast from EvtResetAutoOffEvent
  133. // the first time it is called implying
  134. // that the device will remain awake
  135. // for at least a little while.
  136. // Always sent from UI thread.
  137. sysNotifyDisplayChangeEvent = Rsc('scrd');
  138. // Sent when the display depth is
  139. // changed, notifyDetailsP has old/new depth
  140. // see SysNotifyDisplayChangeDetailsType
  141. sysNotifyMenuCmdBarOpenEvent = Rsc('cbar');
  142. // Sent by FormHandleEvent when a menuCmdBarOpenEvent
  143. // passes through. The system will not open the toolbar
  144. // if the 'handled' field is set in the parameter block,
  145. // so most clients should not set it. The notification
  146. // is provided so that Hack-like entities can catch
  147. // it and add their own buttons to the bar. These
  148. // buttons will show up to the left of cut/copy/paste/undo and
  149. // to the right of everything else. Without this
  150. // notification, people would hack SysHandleEvent... ick.
  151. cncNotifyProfileEvent = Rsc('cncp');
  152. // sent by the Connection Panel to inform its clients
  153. // that the current configuration has change
  154. // void * notifyDetailsP : has to be casted as UInt32
  155. // to get the Broadcasted Profile ID user specified ptr
  156. // passed back with notification
  157. // void * userDataP : has to be casted as UInt16
  158. // to get the device kind of the Broadcasted Profile ID
  159. syssyscallConnectorAttachEvent = Rsc('ecna');
  160. // Broadcast when anything is attached to
  161. // the syscall connector.
  162. syssyscallConnectorDetachEvent = Rsc('ecnd');
  163. // Broadcast when anything is detached from
  164. // the syscall connector.
  165. sysNotifyCardInsertedEvent = Rsc('crdi');
  166. // Broadcast when an ExpansionMgr card is
  167. // inserted into a slot, and the slot driver
  168. // calls ExpCardInserted. Always broadcast
  169. // from UI task.
  170. // ExpansionMgr will play a sound & attempt to
  171. // mount a volume unless the corresponding
  172. // bits in the 'handled' field are set by a
  173. // notification handler (see ExpansionMgr.h).
  174. // PARAMETER: slot number cast as void*
  175. sysNotifyCardRemovedEvent = Rsc('crdo');
  176. // Broadcast when an ExpansionMgr card is
  177. // removed from a slot, and the slot driver
  178. // calls ExpCardRemoved. Always broadcast
  179. // from UI task.
  180. // ExpansionMgr will play a sound & attempt to
  181. // unmount a volume unless the corresponding
  182. // bits in the 'handled' field are set by a
  183. // notification handler (see ExpansionMgr.h).
  184. // PARAMETER: slot number cast as void*
  185. sysNotifyVolumeMountedEvent = Rsc('volm');
  186. // Broadcast when a VFSMgr volume is
  187. // mounted, Always broadcast from UI task.
  188. // VFSMgr will run start.prc (if present),
  189. // and SysUIAppSwitch to it or the Launcher
  190. // unless the appropriate bits in the 'handled'
  191. // field are set by a notification handler.
  192. // PARAMETER: VFSAnyMountParamPtr cast as void*
  193. sysNotifyVolumeUnmountedEvent = Rsc('volu');
  194. // Broadcast AFTER a VFSMgr volume is
  195. // unmounted, Always broadcast from UI task.
  196. // VFSMgr will delete start.prc (if it was loaded).
  197. // The volume ref number for the unmounted volume is
  198. // NO LONGER VALID, so don't bother trying to use it.
  199. // PARAMETER: volume refNum cast as void*
  200. sysNotifyHelperEvent = Rsc('hlpr');
  201. // Sent by Address Book (or any
  202. // 3rd party application) to
  203. // communicate with Phone Apps
  204. sysNotifyPOSEMountEvent = Rsc('pose');
  205. // Sent by HostFS to communicate with itself,
  206. // saving on stack depth.
  207. sysNotifyLocaleChangedEvent = Rsc('locc');
  208. // Notify apps/panel that the system locale
  209. // has changed.
  210. // This is broadcast by the language picker after it
  211. // has changed the locale.
  212. // Always sent from UI thread.
  213. // param: ptr to SysNotifyLocaleChangedType
  214. sysNotifyRetryEnqueueKey = Rsc('retk');
  215. // An EvtEnqueueKey failed, so retry.
  216. sysNotifyGotUsersAttention = Rsc('attn');
  217. // Got users attention.
  218. sysNotifyDBDeletedEvent = Rsc('dbs-');
  219. // broadcast AFTER a database is removed from the device.
  220. // Note that the database ID in the parameter block is
  221. // NO LONGER VALID, and you WILL CRASH the device if you
  222. // try to pass it to any DataMgr routines.
  223. // notifyDetailsP: ptr to SysNotifyDBDeletedType.
  224. sysNotifyDeviceUnlocked = Rsc('unlk');
  225. // Broadcasted by the Security app After the device is
  226. //unlocked.
  227. //notifyDetailsP: none
  228. sysNotifyPhoneEvent = Rsc('fone');
  229. // Sent by third-party applications to communicate
  230. // with built-in or syscall phones.
  231. // NOTE THAT THIS EVENT IS FOR FUTURE USE
  232. sysNotifyNetLibIFMediaEvent = Rsc('neti');
  233. // Broadcasted by NetLib to communicate its interfaces media Up and Down requests
  234. // to registered Apps.
  235. // notifyDetailsP: ptr to SysNotifyNetLibIFMediaType.
  236. sysNotifyDeleteProtectedEvent = Rsc('-pdb');
  237. // Broadcast BEFORE a database is removed from the device when a user
  238. // or installer application wants to remove a protected database. This
  239. // will ONLY be issued from the UI task and should be issued before each
  240. // user driven deletion that targets a protected database that the app
  241. // running does not own (i.e. needs to request be unprotected).
  242. // This gives the unlucky client a chance to do any required
  243. // cleanup work. Note that if an application has multiple protected
  244. // databases, this notification may be sent out more than once.
  245. // notifyDetailsP: ptr to SysNotifyDBInfoType.
  246. sysNotifyIrDASniffEvent = Rsc('irda');
  247. // Sent by IrDA sniffing code when an incomming IrDA frame is detected
  248. // for sysNotifyDisplayChangeEvent
  249. type
  250. SysNotifyDisplayChangeDetailsTag = record
  251. oldDepth: UInt32;
  252. newDepth: UInt32;
  253. end;
  254. SysNotifyDisplayChangeDetailsType = SysNotifyDisplayChangeDetailsTag;
  255. // For sysNotifyLocaleChangedEvent
  256. type
  257. SysNotifyLocaleChangedTag = record
  258. oldLocale: LmLocaleType;
  259. newLocale: LmLocaleType;
  260. end;
  261. SysNotifyLocaleChangedType = SysNotifyLocaleChangedTag;
  262. // Possible values for the sleep-reason for the sysNotifySleepEvent
  263. const
  264. sysSleepPowerButton = 0;
  265. sysSleepAutoOff = 1;
  266. sysSleepResumed = 2;
  267. sysSleepUnknown = 3;
  268. // for sysNotifySleepRequestEvent
  269. type
  270. SleepEventParamTag = record
  271. reason: UInt16; // contains the reason we are going to sleep. See above list for possible values.
  272. deferSleep: UInt16; // Only used for the sysNotifySleepRequestEvent, this should be incremented by
  273. // clients that want to defer the sleep. They are then responsible for enqueing
  274. // a resumeSleepChr in the event queue.
  275. end;
  276. SleepEventParamType = SleepEventParamTag;
  277. // for sysNotifyDeleteProtectedEvent, and possibly others...
  278. type
  279. SysNotifyDBInfoTag = record
  280. dbID: LocalID; // database ID of dabatase
  281. cardNo: UInt16; // card number that dabatase resides on
  282. attributes: UInt16; // database attributes
  283. dbName: array [0..dmDBNameLength-1] of AnsiChar; // name of database
  284. creator: UInt32; // creator code of dabatase
  285. type_: UInt32; // type of dabatase
  286. end;
  287. SysNotifyDBInfoType = SysNotifyDBInfoTag;
  288. // for sysNotifyDBDeletedEvent
  289. type
  290. SysNotifyDBDeletedTag = record
  291. oldDBID: LocalID; // old database ID of dabatase, no longer valid
  292. cardNo: UInt16; // card number that dabatase resides on
  293. attributes: UInt16; // database attributes
  294. dbName: array [0..dmDBNameLength-1] of AnsiChar; // name of database
  295. creator: UInt32; // creator code of dabatase
  296. type_: UInt32; // type code of dabatase
  297. end;
  298. SysNotifyDBDeletedType = SysNotifyDBDeletedTag;
  299. (*
  300. Possible event types to be added in the future:
  301. NOTE that these are NOT implemented yet!!!!
  302. sysNotifyDBAddedEvent = Rsc('dbs+');
  303. // Broadcast after a database is added to the device
  304. // param: ptr to SysNotifyDBInfoType.
  305. sysNotifyInitializeEvent = Ord('helo');
  306. // broadcast to an app after its installed
  307. // so it can do any necessary initalization
  308. // This event is always broadcast.
  309. // param: ptr to SysNotifyDBInfoType.
  310. sysNotifyCleanupEvent = Ord('gbye');
  311. // broadcast to an app just before its deleted
  312. // so it can do any necessary cleanup work.
  313. // This event is always broadcast.
  314. // The database's type will have been set to
  315. // sysFileTTemp so that if case the handler
  316. // crashes, the DB will be deleted on reset.
  317. // param: ptr to SysNotifyDBInfoType.
  318. sysNotifyCardChangedEvent = Ord('card');
  319. // broadcast when the owner's business card
  320. // has changed, allowing apps to adjust for that.
  321. // param: ptr to new owner data.
  322. *)
  323. function SysNotifyRegister(cardNo: UInt16; dbID: LocalID; notifyType: UInt32;
  324. callbackP: SysNotifyProcPtr; priority: Int8; userDataP: Pointer): Err; syscall sysTrapSysNotifyRegister;
  325. function SysNotifyUnregister(cardNo: UInt16; dbID: LocalID; notifyType: UInt32; priority: Int8): Err; syscall sysTrapSysNotifyUnregister;
  326. (*
  327. * WARNING: Never call SysNotifyBroadcast from a background task
  328. * (or from any code that might be called from a BG task)
  329. * with the memory semaphore reserved. Deadlock will
  330. * result when the broadcast is deferred and the UI task
  331. * tries to acquire the mem semaphore in order to send it out.
  332. *)
  333. function SysNotifyBroadcast(var notify: SysNotifyParamType): Err; syscall sysTrapSysNotifyBroadcast;
  334. function SysNotifyBroadcastDeferred(var notify: SysNotifyParamType; paramSize: Int16): Err; syscall sysTrapSysNotifyBroadcastDeferred;
  335. // Kick off a notification from an interrupt handler.
  336. // Note: non-interrupt code should use SysNotifyBroadcast
  337. function SysNotifyBroadcastFromInterrupt(notifyType: UInt32; broadcaster: UInt32;
  338. notifyDetailsP: Pointer): Err; syscall sysTrapSysNotifyBroadcastFromInterrupt;
  339. implementation
  340. end.