1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2002
22 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include
"nsISupports.idl"
42 interface nsIObserver
;
43 interface nsIEventTarget
;
47 * The signature of the timer callback function passed to initWithFuncCallback.
48 * This is the function that will get called when the timer expires if the
49 * timer is initialized via initWithFuncCallback.
51 * @param aTimer the timer which has expired
52 * @param aClosure opaque parameter passed to initWithFuncCallback
54 * Implementers should return the following:
60 typedef void (*nsTimerCallbackFunc
) (nsITimer
*aTimer
, void *aClosure
);
63 native nsTimerCallbackFunc
(nsTimerCallbackFunc
);
66 * The callback interface for timers.
70 [function
, scriptable
, uuid(a796816d
-7d47
-4348-9ab8
-c7aeb3216a7d
)]
71 interface nsITimerCallback
: nsISupports
74 * @param aTimer the timer which has expired
76 void notify
(in nsITimer timer
);
81 * nsITimer instances must be initialized by calling one of the "init" methods
82 * documented below. You may also re-initialize an existing instance with new
83 * delay to avoid the overhead of destroying and creating a timer. It is not
84 * necessary to cancel the timer in that case.
86 [scriptable
, uuid(193fc37a
-8aa4
-4d29
-aa57
-1acd87c26b66
)]
87 interface nsITimer
: nsISupports
92 * Type of a timer that fires once only.
94 const short TYPE_ONE_SHOT
= 0;
97 * After firing, a TYPE_REPEATING_SLACK timer is stopped and not restarted
98 * until its callback completes. Specified timer period will be at least
99 * the time between when processing for last firing the callback completes
100 * and when the next firing occurs.
102 * This is the preferable repeating type for most situations.
104 const short TYPE_REPEATING_SLACK
= 1;
107 * An TYPE_REPEATING_PRECISE repeating timer aims to have constant period
108 * between firings. The processing time for each timer callback should not
109 * influence the timer period. However, if the processing for the last
110 * timer firing could not be completed until just before the next firing
111 * occurs, then you could have two timer notification routines being
112 * executed in quick succession.
114 const short TYPE_REPEATING_PRECISE
= 2;
117 * Initialize a timer that will fire after the said delay.
118 * A user must keep a reference to this timer till it is
119 * is no longer needed or has been cancelled.
121 * @param aObserver the callback object that observes the
122 * ``timer-callback'' topic with the subject being
123 * the timer itself when the timer fires:
125 * observe(nsISupports aSubject, => nsITimer
126 * string aTopic, => ``timer-callback''
127 * wstring data => null
129 * @param aDelay delay in milliseconds for timer to fire
130 * @param aType timer type per TYPE* consts defined above
132 void init
(in nsIObserver aObserver
, in unsigned long aDelay
,
133 in unsigned long aType
);
137 * Initialize a timer to fire after the given millisecond interval.
138 * This version takes a function to call and a closure to pass to
141 * @param aFunc The function to invoke
142 * @param aClosure An opaque pointer to pass to that function
143 * @param aDelay The millisecond interval
144 * @param aType Timer type per TYPE* consts defined above
146 [noscript
] void initWithFuncCallback
(in nsTimerCallbackFunc aCallback
,
148 in unsigned long aDelay
,
149 in unsigned long aType
);
152 * Initialize a timer to fire after the given millisecond interval.
153 * This version takes a function to call and a closure to pass to
156 * @param aFunc nsITimerCallback interface to call when timer expires
157 * @param aDelay The millisecond interval
158 * @param aType Timer type per TYPE* consts defined above
160 void initWithCallback
(in nsITimerCallback aCallback
,
161 in unsigned long aDelay
,
162 in unsigned long aType
);
165 * Cancel the timer. This method works on all types, not just on repeating
166 * timers -- you might want to cancel a TYPE_ONE_SHOT timer, and even reuse
167 * it by re-initializing it (to avoid object destruction and creation costs
168 * by conserving one timer instance).
173 * The millisecond delay of the timeout
175 attribute
unsigned long delay
;
178 * The timer type : one shot or repeating
180 attribute
unsigned long type
;
183 * The opaque pointer pass to initWithFuncCallback.
185 [noscript
] readonly attribute voidPtr closure
;
188 * The nsITimerCallback object passed to initWithCallback.
190 readonly attribute nsITimerCallback
callback;
193 * The nsIEventTarget where the callback will be dispatched. Note that this
194 * target may only be set before the call to one of the init methods above.
196 attribute nsIEventTarget target
;
200 #define NS_TIMER_CONTRACTID
"@mozilla.org/timer;1"
201 #define NS_TIMER_CALLBACK_TOPIC
"timer-callback"