alarmmgr.pp 8.7 KB

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