Back to index

lightning-sunbird  0.9+nobinonly
pralarm.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** File:             pralarm.h
00040 ** Description:      API to periodic alarms.
00041 **
00042 **
00043 ** Alarms are defined to invoke some client specified function at 
00044 ** a time in the future. The notification may be a one time event
00045 ** or repeated at a fixed interval. The interval at which the next
00046 ** notification takes place may be modified by the client code only
00047 ** during the respective notification.
00048 **
00049 ** The notification is delivered on a thread that is part of the
00050 ** alarm context (PRAlarm). The thread will inherit the priority
00051 ** of the Alarm creator.
00052 **
00053 ** Any number of periodic alarms (PRAlarmID) may be created within
00054 ** the context of a single alarm (PRAlarm). The notifications will be
00055 ** scheduled as close to the desired time as possible.
00056 **
00057 ** Repeating periodic notifies are expected to run at a fixed rate.
00058 ** That rate is expressed as some number of notifies per period where
00059 ** the period is much larger than a PRIntervalTime (see prinrval.h).
00060 */
00061 
00062 #if !defined(pralarm_h)
00063 #define pralarm_h
00064 
00065 #include "prtypes.h"
00066 #include "prinrval.h"
00067 
00068 
00069 PR_BEGIN_EXTERN_C
00070 
00071 /**********************************************************************/
00072 /************************* TYPES AND CONSTANTS ************************/
00073 /**********************************************************************/
00074 
00075 typedef struct PRAlarm PRAlarm;
00076 typedef struct PRAlarmID PRAlarmID;
00077 
00078 typedef PRBool (PR_CALLBACK *PRPeriodicAlarmFn)(
00079     PRAlarmID *id, void *clientData, PRUint32 late);
00080 
00081 /**********************************************************************/
00082 /****************************** FUNCTIONS *****************************/
00083 /**********************************************************************/
00084 
00085 /***********************************************************************
00086 ** FUNCTION:    PR_CreateAlarm
00087 ** DESCRIPTION:
00088 **  Create an alarm context.
00089 ** INPUTS:      void
00090 ** OUTPUTS:     None
00091 ** RETURN:      PRAlarm*
00092 **  
00093 ** SIDE EFFECTS:
00094 **  This creates an alarm context, which is an object used for subsequent
00095 **  notification creations. It also creates a thread that will be used to
00096 ** deliver the notifications that are expected to be defined. The client
00097 ** is resposible for destroying the context when appropriate.
00098 ** RESTRICTIONS:
00099 **  None. 
00100 ** MEMORY:      The object (PRAlarm) and a thread to support notifications.
00101 ** ALGORITHM:   N/A
00102 ***********************************************************************/
00103 NSPR_API(PRAlarm*) PR_CreateAlarm(void);
00104 
00105 /***********************************************************************
00106 ** FUNCTION:    PR_DestroyAlarm
00107 ** DESCRIPTION:
00108 **  Destroys the context created by PR_CreateAlarm().
00109 ** INPUTS:      PRAlarm*
00110 ** OUTPUTS:     None
00111 ** RETURN:      PRStatus
00112 **  
00113 ** SIDE EFFECTS:
00114 **  This destroys the context that was created by PR_CreateAlarm().
00115 **  If there are any active alarms (PRAlarmID), they will be cancelled.
00116 **  Once that is done, the thread that was used to deliver the alarms
00117 **  will be joined. 
00118 ** RESTRICTIONS:
00119 **  None. 
00120 ** MEMORY:      N/A
00121 ** ALGORITHM:   N/A
00122 ***********************************************************************/
00123 NSPR_API(PRStatus) PR_DestroyAlarm(PRAlarm *alarm);
00124 
00125 /***********************************************************************
00126 ** FUNCTION:    PR_SetAlarm
00127 ** DESCRIPTION:
00128 **  Creates a periodic notifier that is to be delivered to a specified
00129 **  function at some fixed interval.
00130 ** INPUTS:      PRAlarm *alarm              Parent alarm context
00131 **              PRIntervalTime period       Interval over which the notifies
00132 **                                          are delivered.
00133 **              PRUint32 rate               The rate within the interval that
00134 **                                          the notifies will be delivered.
00135 **              PRPeriodicAlarmFn function  Entry point where the notifies
00136 **                                          will be delivered.
00137 ** OUTPUTS:     None
00138 ** RETURN:      PRAlarmID*                  Handle to the notifier just created
00139 **                                          or NULL if the request failed.
00140 **  
00141 ** SIDE EFFECTS:
00142 **  A periodic notifier is created. The notifications will be delivered
00143 **  by the alarm's internal thread at a fixed interval whose rate is the
00144 **  number of interrupts per interval specified. The first notification
00145 **  will be delivered as soon as possible, and they will continue until
00146 **  the notifier routine indicates that they should cease of the alarm
00147 **  context is destroyed (PR_DestroyAlarm).
00148 ** RESTRICTIONS:
00149 **  None. 
00150 ** MEMORY:      Memory for the notifier object.
00151 ** ALGORITHM:   The rate at which notifications are delivered are stated
00152 **              to be "'rate' notifies per 'interval'". The exact time of
00153 **              the notification is computed based on a epoch established
00154 **              when the notifier was set. Each notification is delivered
00155 **              not ealier than the epoch plus the fixed rate times the
00156 **              notification sequence number. Such notifications have the
00157 **              potential to be late by not more than 'interval'/'rate'.
00158 **              The amount of lateness of one notification is taken into
00159 **              account on the next in an attempt to avoid long term slew.  
00160 ***********************************************************************/
00161 NSPR_API(PRAlarmID*) PR_SetAlarm(
00162     PRAlarm *alarm, PRIntervalTime period, PRUint32 rate,
00163     PRPeriodicAlarmFn function, void *clientData);
00164 
00165 /***********************************************************************
00166 ** FUNCTION:    PR_ResetAlarm
00167 ** DESCRIPTION:
00168 **  Resets an existing alarm.
00169 ** INPUTS:      PRAlarmID *id               Identify of the notifier.
00170 **              PRIntervalTime period       Interval over which the notifies
00171 **                                          are delivered.
00172 **              PRUint32 rate               The rate within the interval that
00173 **                                          the notifies will be delivered.
00174 ** OUTPUTS:     None
00175 ** RETURN:      PRStatus                    Indication of completion.
00176 **  
00177 ** SIDE EFFECTS:
00178 **  An existing alarm may have its period and rate redefined. The
00179 **  additional side effect is that the notifier's epoch is recomputed.
00180 **  The first notification delivered by the newly refreshed alarm is
00181 **  defined to be 'interval'/'rate' from the time of the reset.
00182 ** RESTRICTIONS:
00183 **  This function may only be called in the notifier for that alarm.
00184 ** MEMORY:      N/A.
00185 ** ALGORITHM:   See PR_SetAlarm().  
00186 ***********************************************************************/
00187 NSPR_API(PRStatus) PR_ResetAlarm(
00188        PRAlarmID *id, PRIntervalTime period, PRUint32 rate);
00189 
00190 PR_END_EXTERN_C
00191 
00192 #endif /* !defined(pralarm_h) */
00193 
00194 /* prinrval.h */