Bug 496271, automation config for Tb2.0.0.22 build1, p=joduinn, r=me
[mozilla-1.9.git] / xpcom / threads / nsITimer.idl
blob25c9774e918a8ce0c118b393c1c315fc2d2841c9
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
15 * License.
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.
24 * Contributor(s):
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;
44 %{C++
45 /**
46 * The signature of the timer callback function passed to initWithFuncCallback.
47 * This is the function that will get called when the timer expires if the
48 * timer is initialized via initWithFuncCallback.
50 * @param aTimer the timer which has expired
51 * @param aClosure opaque parameter passed to initWithFuncCallback
53 * Implementers should return the following:
55 * @return NS_OK
58 class nsITimer;
59 typedef void (*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure);
62 native nsTimerCallbackFunc(nsTimerCallbackFunc);
64 /**
65 * The callback interface for timers.
67 interface nsITimer;
69 [function, scriptable, uuid(a796816d-7d47-4348-9ab8-c7aeb3216a7d)]
70 interface nsITimerCallback : nsISupports
72 /**
73 * @param aTimer the timer which has expired
75 void notify(in nsITimer timer);
79 /**
80 * nsITimer instances must be initialized by calling one of the "init" methods
81 * documented below. You may also re-initialize an existing instance with new
82 * delay to avoid the overhead of destroying and creating a timer. It is not
83 * necessary to cancel the timer in that case.
85 [scriptable, uuid(436a83fa-b396-11d9-bcfa-00112478d626)]
86 interface nsITimer : nsISupports
88 /* Timer types */
90 /**
91 * Type of a timer that fires once only.
93 const short TYPE_ONE_SHOT = 0;
95 /**
96 * After firing, a TYPE_REPEATING_SLACK timer is stopped and not restarted
97 * until its callback completes. Specified timer period will be at least
98 * the time between when processing for last firing the callback completes
99 * and when the next firing occurs.
101 * This is the preferable repeating type for most situations.
103 const short TYPE_REPEATING_SLACK = 1;
106 * An TYPE_REPEATING_PRECISE repeating timer aims to have constant period
107 * between firings. The processing time for each timer callback should not
108 * influence the timer period. However, if the processing for the last
109 * timer firing could not be completed until just before the next firing
110 * occurs, then you could have two timer notification routines being
111 * executed in quick succession.
113 const short TYPE_REPEATING_PRECISE = 2;
116 * Initialize a timer that will fire after the said delay.
117 * A user must keep a reference to this timer till it is
118 * is no longer needed or has been cancelled.
120 * @param aObserver the callback object that observes the
121 * ``timer-callback'' topic with the subject being
122 * the timer itself when the timer fires:
124 * observe(nsISupports aSubject, => nsITimer
125 * string aTopic, => ``timer-callback''
126 * wstring data => null
128 * @param aDelay delay in milliseconds for timer to fire
129 * @param aType timer type per TYPE* consts defined above
131 void init(in nsIObserver aObserver, in unsigned long aDelay,
132 in unsigned long aType);
136 * Initialize a timer to fire after the given millisecond interval.
137 * This version takes a function to call and a closure to pass to
138 * that function.
140 * @param aFunc The function to invoke
141 * @param aClosure An opaque pointer to pass to that function
142 * @param aDelay The millisecond interval
143 * @param aType Timer type per TYPE* consts defined above
145 [noscript] void initWithFuncCallback(in nsTimerCallbackFunc aCallback,
146 in voidPtr aClosure,
147 in unsigned long aDelay,
148 in unsigned long aType);
151 * Initialize a timer to fire after the given millisecond interval.
152 * This version takes a function to call and a closure to pass to
153 * that function.
155 * @param aFunc nsITimerCallback interface to call when timer expires
156 * @param aDelay The millisecond interval
157 * @param aType Timer type per TYPE* consts defined above
159 void initWithCallback(in nsITimerCallback aCallback,
160 in unsigned long aDelay,
161 in unsigned long aType);
164 * Cancel the timer. This method works on all types, not just on repeating
165 * timers -- you might want to cancel a TYPE_ONE_SHOT timer, and even reuse
166 * it by re-initializing it (to avoid object destruction and creation costs
167 * by conserving one timer instance).
169 void cancel();
172 * The millisecond delay of the timeout
174 attribute unsigned long delay;
177 * The timer type : one shot or repeating
179 attribute unsigned long type;
182 * The opaque pointer pass to initWithFuncCallback.
184 [noscript] readonly attribute voidPtr closure;
187 * The nsITimerCallback object passed to initWithCallback.
189 readonly attribute nsITimerCallback callback;
192 %{C++
193 #define NS_TIMER_CONTRACTID "@mozilla.org/timer;1"
194 #define NS_TIMER_CALLBACK_TOPIC "timer-callback"