PageRenderTime 113ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/obsolete/pralarm.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 194 lines | 18 code | 16 blank | 160 comment | 0 complexity | 99c1edac23a514af55d4f332b9f0c6e7 MD5 | raw file
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /*
  38. ** File: pralarm.h
  39. ** Description: API to periodic alarms.
  40. **
  41. **
  42. ** Alarms are defined to invoke some client specified function at
  43. ** a time in the future. The notification may be a one time event
  44. ** or repeated at a fixed interval. The interval at which the next
  45. ** notification takes place may be modified by the client code only
  46. ** during the respective notification.
  47. **
  48. ** The notification is delivered on a thread that is part of the
  49. ** alarm context (PRAlarm). The thread will inherit the priority
  50. ** of the Alarm creator.
  51. **
  52. ** Any number of periodic alarms (PRAlarmID) may be created within
  53. ** the context of a single alarm (PRAlarm). The notifications will be
  54. ** scheduled as close to the desired time as possible.
  55. **
  56. ** Repeating periodic notifies are expected to run at a fixed rate.
  57. ** That rate is expressed as some number of notifies per period where
  58. ** the period is much larger than a PRIntervalTime (see prinrval.h).
  59. */
  60. #if !defined(pralarm_h)
  61. #define pralarm_h
  62. #include "prtypes.h"
  63. #include "prinrval.h"
  64. PR_BEGIN_EXTERN_C
  65. /**********************************************************************/
  66. /************************* TYPES AND CONSTANTS ************************/
  67. /**********************************************************************/
  68. typedef struct PRAlarm PRAlarm;
  69. typedef struct PRAlarmID PRAlarmID;
  70. typedef PRBool (PR_CALLBACK *PRPeriodicAlarmFn)(
  71. PRAlarmID *id, void *clientData, PRUint32 late);
  72. /**********************************************************************/
  73. /****************************** FUNCTIONS *****************************/
  74. /**********************************************************************/
  75. /***********************************************************************
  76. ** FUNCTION: PR_CreateAlarm
  77. ** DESCRIPTION:
  78. ** Create an alarm context.
  79. ** INPUTS: void
  80. ** OUTPUTS: None
  81. ** RETURN: PRAlarm*
  82. **
  83. ** SIDE EFFECTS:
  84. ** This creates an alarm context, which is an object used for subsequent
  85. ** notification creations. It also creates a thread that will be used to
  86. ** deliver the notifications that are expected to be defined. The client
  87. ** is resposible for destroying the context when appropriate.
  88. ** RESTRICTIONS:
  89. ** None.
  90. ** MEMORY: The object (PRAlarm) and a thread to support notifications.
  91. ** ALGORITHM: N/A
  92. ***********************************************************************/
  93. NSPR_API(PRAlarm*) PR_CreateAlarm(void);
  94. /***********************************************************************
  95. ** FUNCTION: PR_DestroyAlarm
  96. ** DESCRIPTION:
  97. ** Destroys the context created by PR_CreateAlarm().
  98. ** INPUTS: PRAlarm*
  99. ** OUTPUTS: None
  100. ** RETURN: PRStatus
  101. **
  102. ** SIDE EFFECTS:
  103. ** This destroys the context that was created by PR_CreateAlarm().
  104. ** If there are any active alarms (PRAlarmID), they will be cancelled.
  105. ** Once that is done, the thread that was used to deliver the alarms
  106. ** will be joined.
  107. ** RESTRICTIONS:
  108. ** None.
  109. ** MEMORY: N/A
  110. ** ALGORITHM: N/A
  111. ***********************************************************************/
  112. NSPR_API(PRStatus) PR_DestroyAlarm(PRAlarm *alarm);
  113. /***********************************************************************
  114. ** FUNCTION: PR_SetAlarm
  115. ** DESCRIPTION:
  116. ** Creates a periodic notifier that is to be delivered to a specified
  117. ** function at some fixed interval.
  118. ** INPUTS: PRAlarm *alarm Parent alarm context
  119. ** PRIntervalTime period Interval over which the notifies
  120. ** are delivered.
  121. ** PRUint32 rate The rate within the interval that
  122. ** the notifies will be delivered.
  123. ** PRPeriodicAlarmFn function Entry point where the notifies
  124. ** will be delivered.
  125. ** OUTPUTS: None
  126. ** RETURN: PRAlarmID* Handle to the notifier just created
  127. ** or NULL if the request failed.
  128. **
  129. ** SIDE EFFECTS:
  130. ** A periodic notifier is created. The notifications will be delivered
  131. ** by the alarm's internal thread at a fixed interval whose rate is the
  132. ** number of interrupts per interval specified. The first notification
  133. ** will be delivered as soon as possible, and they will continue until
  134. ** the notifier routine indicates that they should cease of the alarm
  135. ** context is destroyed (PR_DestroyAlarm).
  136. ** RESTRICTIONS:
  137. ** None.
  138. ** MEMORY: Memory for the notifier object.
  139. ** ALGORITHM: The rate at which notifications are delivered are stated
  140. ** to be "'rate' notifies per 'interval'". The exact time of
  141. ** the notification is computed based on a epoch established
  142. ** when the notifier was set. Each notification is delivered
  143. ** not ealier than the epoch plus the fixed rate times the
  144. ** notification sequence number. Such notifications have the
  145. ** potential to be late by not more than 'interval'/'rate'.
  146. ** The amount of lateness of one notification is taken into
  147. ** account on the next in an attempt to avoid long term slew.
  148. ***********************************************************************/
  149. NSPR_API(PRAlarmID*) PR_SetAlarm(
  150. PRAlarm *alarm, PRIntervalTime period, PRUint32 rate,
  151. PRPeriodicAlarmFn function, void *clientData);
  152. /***********************************************************************
  153. ** FUNCTION: PR_ResetAlarm
  154. ** DESCRIPTION:
  155. ** Resets an existing alarm.
  156. ** INPUTS: PRAlarmID *id Identify of the notifier.
  157. ** PRIntervalTime period Interval over which the notifies
  158. ** are delivered.
  159. ** PRUint32 rate The rate within the interval that
  160. ** the notifies will be delivered.
  161. ** OUTPUTS: None
  162. ** RETURN: PRStatus Indication of completion.
  163. **
  164. ** SIDE EFFECTS:
  165. ** An existing alarm may have its period and rate redefined. The
  166. ** additional side effect is that the notifier's epoch is recomputed.
  167. ** The first notification delivered by the newly refreshed alarm is
  168. ** defined to be 'interval'/'rate' from the time of the reset.
  169. ** RESTRICTIONS:
  170. ** This function may only be called in the notifier for that alarm.
  171. ** MEMORY: N/A.
  172. ** ALGORITHM: See PR_SetAlarm().
  173. ***********************************************************************/
  174. NSPR_API(PRStatus) PR_ResetAlarm(
  175. PRAlarmID *id, PRIntervalTime period, PRUint32 rate);
  176. PR_END_EXTERN_C
  177. #endif /* !defined(pralarm_h) */
  178. /* prinrval.h */