alarmmgr.pp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: AlarmMgr.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * Description:
  12. * Include file for Alarm Manager
  13. *
  14. * History:
  15. * 4/11/95 VMK - Created by Vitaly Kruglikov
  16. *
  17. *****************************************************************************)
  18. {$IFNDEF FPC_DOTTEDUNITS}
  19. unit alarmmgr;
  20. {$ENDIF FPC_DOTTEDUNITS}
  21. interface
  22. {$IFDEF FPC_DOTTEDUNITS}
  23. uses PalmApi.Palmos, PalmApi.Coretraps, PalmApi.Errorbase;
  24. {$ELSE FPC_DOTTEDUNITS}
  25. uses palmos, coretraps, errorbase;
  26. {$ENDIF FPC_DOTTEDUNITS}
  27. (************************************************************
  28. * Alarm Manager result codes
  29. * (almErrorClass is defined in ErrorBase)
  30. *************************************************************)
  31. const
  32. almErrMemory = almErrorClass or 1; // ran out of memory
  33. almErrFull = almErrorClass or 2; // alarm table is full
  34. (********************************************************************
  35. * Alarm Manager Structures
  36. ********************************************************************)
  37. // Structure passed with the sysAppLaunchCmdAlarmTriggered action code:
  38. //
  39. // This is a notification that an alarm set by the creator has
  40. // gone off. The action code handler should not do anything time-
  41. // consuming here. The intended use is to set the next alarm and/or
  42. // to perform some quick maintenance task. Particularly, this action code
  43. // handler is not allowed to display any UI(dialogs, etc.) -- this would delay
  44. // notification for alarms set by others. This action code may be ignored.
  45. type
  46. SysAlarmTriggeredParamType = record
  47. ref: UInt32; // --> alarm reference value passed by caller;
  48. alarmSeconds: UInt32; // --> alarm date/time in seconds since 1/1/1904;
  49. purgeAlarm: Boolean; // <-- if set to true on return, this alarm
  50. // will be removed from the alarm table and the
  51. // display notification will NOT be generated for it
  52. padding: UInt8;
  53. end;
  54. // Structure passed with the sysAppLaunchCmdDisplayAlarm action code:
  55. //
  56. // This is a notification to display an alarm. This action code
  57. // will be called sometime after the app receives a sysAppLaunchCmdAlarmTriggered
  58. // notification(perhaps after a significant delay). It is possible that this
  59. // notification will not be sent at all in the event the alarm table becomes full and
  60. // the alarm table entry is used to hold a new alarm (this does NOT apply to the
  61. // sysAppLaunchCmdAlarmTriggered notification). This action code may be ignored.
  62. SysDisplayAlarmParamType = record
  63. ref: UInt32; // alarm reference value passed by caller;
  64. alarmSeconds: UInt32; // alarm date/time in seconds since 1/1/1904;
  65. soundAlarm: Boolean; // non-zero if alarm needs to be sounded;
  66. padding: UInt8;
  67. end;
  68. (************************************************************
  69. * <chg 4-1-98 RM>
  70. *
  71. * New PalmOS 3.2 support for procedure alarms. These alarms
  72. * are designed to call a procedure pointer rather than send
  73. * an action code to an application.
  74. *
  75. * They are set using the AlmSetProcAlarm() macro. The caller
  76. * passes a pointer to a procedure of type AlmAlarmProc and
  77. * this procedure will be called when the alarm goes off.
  78. *
  79. * When the alarm fires, the alarm proc will be called with
  80. * an almProcCmd of almProcCmdTriggered and paramP containing
  81. * to the alarm parameters.
  82. *
  83. * When a system time or date change occurs, the alarm proc will
  84. * be called with a almProcCmdReschedule cmd. The alarm proc should
  85. * reschedule itself at this time using AlmSetProcAlarm().
  86. *
  87. * The almProcCmd's at almProcCmdCustom are available for custom
  88. * use by the alarm proc as it sees fit.
  89. *
  90. *************************************************************)
  91. type
  92. AlmProcCmdEnum = WordEnum;
  93. const
  94. almProcCmdTriggered = 0; // Alarm triggered
  95. almProcCmdReschedule = Succ(almProcCmdTriggered); // Reschedule (usually as a result of time change)
  96. // Alarm manager reserves all enums up to almProcCmdCustom
  97. almProcCmdCustom = $8000;
  98. type
  99. AlmAlarmProc = procedure({AlmProcCmdEnum} almProcCmd: UInt16; var paramP: SysAlarmTriggeredParamType);
  100. const
  101. almProcAlarmCardNo = $8000; // passed in cardNo to AlmSetAlarm
  102. // and AlmGetAlarm
  103. (********************************************************************
  104. * Alarm Manager Routines
  105. * These are define as syscall calls only under emulation mode or
  106. * under native mode from the module that actually installs the trap
  107. * vectors
  108. ********************************************************************)
  109. //-------------------------------------------------------------------
  110. // Initialization
  111. //-------------------------------------------------------------------
  112. //
  113. // ISSUES:
  114. // 1. Is the Alarms Database always on Card 0 ?
  115. //
  116. // A: We will store alarm info on the dynamic heap. Upon reset and
  117. // time change, apps will be notified via action code and will re-
  118. // submit their alarms.
  119. //
  120. // 2. Should a semaphore be used by the Alarm Manager ?
  121. //
  122. // A: No. Present implementation does not require it. May add one
  123. // in the future to ensure data integrity between tasks.
  124. //
  125. // 3. Pilot will need to go back to sleep even if the alarms dialog box is
  126. // not closed after some interval.
  127. //
  128. // A: This will happen in GetNextEvent.
  129. //
  130. // 4. We will need to sound the alarm for all newly triggered alarms
  131. // even while another alarm dialog box is on-screen.
  132. //
  133. // A: Yes. We will keep a flag in our globals to indicate when the
  134. // alarm manager is displaying an alarm. This way we do not hog
  135. // stack and dynamic heap memory with additional alarm boxes.
  136. //
  137. // 5. Should the alarm dialog box be system-modal ?
  138. //
  139. // A: Yes -- by swallowing the "QUIT" (and/or others) message in the alarm dialog's
  140. // event loop.
  141. //
  142. // AlmInit()
  143. //
  144. // Initializes the Alarm Manager.
  145. //
  146. // Create the Alarm Globals.
  147. //
  148. function AlmInit: Err; syscall sysTrapAlmInit;
  149. //-------------------------------------------------------------------
  150. // API
  151. //-------------------------------------------------------------------
  152. // AlmSetAlarm()
  153. //
  154. // Sets an alarm for the given application. If an alarm for that
  155. // application had been previously set, it will be replaced. Passing
  156. // a zero for alarmSeconds cancels the current alarm for the application.
  157. //
  158. function AlmSetAlarm(cardNo: UInt16; dbID: LocalID; ref, alarmSeconds: UInt32; quiet: Boolean): Err; syscall sysTrapAlmSetAlarm;
  159. // AlmGetAlarm()
  160. //
  161. // Gets the alarm seconds for a given app.
  162. // Zero is returned if there is no alarm setting for the app.
  163. function AlmGetAlarm(cardNo: UInt16; dbID: LocalID; var refP: UInt32): UInt32; syscall sysTrapAlmGetAlarm;
  164. // AlmEnableNotification
  165. //
  166. // Enables/disables Alarm Manager's notification mechanism. For example,
  167. // the HotSync application disables Alarm notifications during the sync
  168. // to ensure that apps do not try to access their data database until
  169. // the DesktopLink server had a chance to notify the apps whose databases
  170. // were modified during the session. This also prevents the alarm dialogs from
  171. // blocking the HotSync UI. A call to disable MUST always
  172. // precede the call to enable.
  173. //
  174. procedure AlmEnableNotification(enable: Boolean); syscall sysTrapAlmEnableNotification;
  175. // AlmDisplayAlarm()
  176. //
  177. // Displays any alarms that have gone off.
  178. //
  179. // This function is called by the Event Manager executing on some app's
  180. // thread. This permits us to access resources and execute system calls
  181. // which would not be possible at interrupt time.
  182. // 12/8/98 jb Added return code.
  183. function AlmDisplayAlarm(okToDisplay: Boolean): Boolean; syscall sysTrapAlmDisplayAlarm;
  184. // AlmCancelAll()
  185. //
  186. // Cancels all alarms managed by the Alarm Manager. This
  187. // function is presently called by the Time Manager to cancel all alarms
  188. // when the user changes date/time.
  189. //
  190. procedure AlmCancelAll; syscall sysTrapAlmCancelAll;
  191. // AlmAlarmCallback()
  192. //
  193. // This function is called at interrupt time by the Time Manager when
  194. // an alarm goes off.
  195. //
  196. procedure AlmAlarmCallback; syscall sysTrapAlmAlarmCallback;
  197. // AlmTimeChange()
  198. //
  199. // This function gets called by TimSetSeconds() and gives the alarm manager
  200. // a chance to notify all procedure alarms of the time change.
  201. //
  202. procedure AlmTimeChange; syscall sysTrapAlmTimeChange;
  203. procedure AlmSetProcAlarm(procP: AlmAlarmProc; ref, alarmSeconds: UInt32);
  204. function AlmGetProcAlarm(procP: AlmAlarmProc; var refP: UInt32): UInt32;
  205. implementation
  206. // macros
  207. procedure AlmSetProcAlarm(procP: AlmAlarmProc; ref, alarmSeconds: UInt32);
  208. begin
  209. AlmSetAlarm(almProcAlarmCardNo, LocalID(procP), ref, alarmSeconds, True);
  210. end;
  211. function AlmGetProcAlarm(procP: AlmAlarmProc; var refP: UInt32): UInt32;
  212. begin
  213. AlmGetProcAlarm := AlmGetAlarm(almProcAlarmCardNo, LocalID(procP), refP);
  214. end;
  215. end.