xpcom/threads/nsITimer.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsISupports.idl"
michael@0 7
michael@0 8 interface nsIObserver;
michael@0 9 interface nsIEventTarget;
michael@0 10
michael@0 11 %{C++
michael@0 12 /**
michael@0 13 * The signature of the timer callback function passed to initWithFuncCallback.
michael@0 14 * This is the function that will get called when the timer expires if the
michael@0 15 * timer is initialized via initWithFuncCallback.
michael@0 16 *
michael@0 17 * @param aTimer the timer which has expired
michael@0 18 * @param aClosure opaque parameter passed to initWithFuncCallback
michael@0 19 */
michael@0 20 class nsITimer;
michael@0 21 typedef void (*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure);
michael@0 22 %}
michael@0 23
michael@0 24 native nsTimerCallbackFunc(nsTimerCallbackFunc);
michael@0 25
michael@0 26 /**
michael@0 27 * The callback interface for timers.
michael@0 28 */
michael@0 29 interface nsITimer;
michael@0 30
michael@0 31 [function, scriptable, uuid(a796816d-7d47-4348-9ab8-c7aeb3216a7d)]
michael@0 32 interface nsITimerCallback : nsISupports
michael@0 33 {
michael@0 34 /**
michael@0 35 * @param aTimer the timer which has expired
michael@0 36 */
michael@0 37 void notify(in nsITimer timer);
michael@0 38 };
michael@0 39
michael@0 40 %{C++
michael@0 41 // Two timer deadlines must differ by less than half the PRIntervalTime domain.
michael@0 42 #define DELAY_INTERVAL_LIMIT PR_BIT(8 * sizeof(PRIntervalTime) - 1)
michael@0 43 %}
michael@0 44
michael@0 45 /**
michael@0 46 * nsITimer instances must be initialized by calling one of the "init" methods
michael@0 47 * documented below. You may also re-initialize (using one of the init()
michael@0 48 * methods) an existing instance to avoid the overhead of destroying and
michael@0 49 * creating a timer. It is not necessary to cancel the timer in that case.
michael@0 50 *
michael@0 51 * By default a timer will fire on the thread that created it. Set the .target
michael@0 52 * attribute to fire on a different thread. Once you have set a timer's .target
michael@0 53 * and called one of its init functions, any further interactions with the timer
michael@0 54 * (calling cancel(), changing member fields, etc) should only be done by the
michael@0 55 * target thread, or races may occur with bad results like timers firing after
michael@0 56 * they've been canceled, and/or not firing after re-initiatization.
michael@0 57 */
michael@0 58 [scriptable, uuid(193fc37a-8aa4-4d29-aa57-1acd87c26b66)]
michael@0 59 interface nsITimer : nsISupports
michael@0 60 {
michael@0 61 /* Timer types */
michael@0 62
michael@0 63 /**
michael@0 64 * Type of a timer that fires once only.
michael@0 65 */
michael@0 66 const short TYPE_ONE_SHOT = 0;
michael@0 67
michael@0 68 /**
michael@0 69 * After firing, a TYPE_REPEATING_SLACK timer is stopped and not restarted
michael@0 70 * until its callback completes. Specified timer period will be at least
michael@0 71 * the time between when processing for last firing the callback completes
michael@0 72 * and when the next firing occurs.
michael@0 73 *
michael@0 74 * This is the preferable repeating type for most situations.
michael@0 75 */
michael@0 76 const short TYPE_REPEATING_SLACK = 1;
michael@0 77
michael@0 78 /**
michael@0 79 * An TYPE_REPEATING_PRECISE repeating timer aims to have constant period
michael@0 80 * between firings. The processing time for each timer callback should not
michael@0 81 * influence the timer period. However, if the processing for the last
michael@0 82 * timer firing could not be completed until just before the next firing
michael@0 83 * occurs, then you could have two timer notification routines being
michael@0 84 * executed in quick succession. Furthermore, if your callback processing
michael@0 85 * time is longer than the timer period, then the timer will post more
michael@0 86 * notifications while your callback is running. For example, if a
michael@0 87 * REPEATING_PRECISE timer has a 10ms period and a callback takes 50ms,
michael@0 88 * then by the time the callback is done there will be 5 events to run the
michael@0 89 * timer callback in the event queue. Furthermore, the next scheduled time
michael@0 90 * will always advance by exactly the delay every time the timer fires.
michael@0 91 * This means that if the clock increments without the timer thread running
michael@0 92 * (e.g. the computer is asleep) when the timer thread gets to run again it
michael@0 93 * will post all the events that it "missed" while it wasn't running. Use
michael@0 94 * this timer type with extreme caution. Chances are, this is not what you
michael@0 95 * want.
michael@0 96 */
michael@0 97 const short TYPE_REPEATING_PRECISE = 2;
michael@0 98
michael@0 99 /**
michael@0 100 * A TYPE_REPEATING_PRECISE_CAN_SKIP repeating timer aims to have constant
michael@0 101 * period between firings. The processing time for each timer callback
michael@0 102 * should not influence the timer period. However this timer type
michael@0 103 * guarantees that it will not queue up new events to fire the callback
michael@0 104 * until the previous callback event finishes firing. If the callback
michael@0 105 * takes a long time, then the next callback will be scheduled immediately
michael@0 106 * afterward, but only once, unlike TYPE_REPEATING_PRECISE. If you want a
michael@0 107 * non-slack timer, you probably want this one.
michael@0 108 */
michael@0 109 const short TYPE_REPEATING_PRECISE_CAN_SKIP = 3;
michael@0 110
michael@0 111 /**
michael@0 112 * Initialize a timer that will fire after the said delay.
michael@0 113 * A user must keep a reference to this timer till it is
michael@0 114 * is no longer needed or has been cancelled.
michael@0 115 *
michael@0 116 * @param aObserver the callback object that observes the
michael@0 117 * ``timer-callback'' topic with the subject being
michael@0 118 * the timer itself when the timer fires:
michael@0 119 *
michael@0 120 * observe(nsISupports aSubject, => nsITimer
michael@0 121 * string aTopic, => ``timer-callback''
michael@0 122 * wstring data => null
michael@0 123 *
michael@0 124 * @param aDelay delay in milliseconds for timer to fire
michael@0 125 * @param aType timer type per TYPE* consts defined above
michael@0 126 */
michael@0 127 void init(in nsIObserver aObserver, in unsigned long aDelay,
michael@0 128 in unsigned long aType);
michael@0 129
michael@0 130
michael@0 131 /**
michael@0 132 * Initialize a timer to fire after the given millisecond interval.
michael@0 133 * This version takes a function to call and a closure to pass to
michael@0 134 * that function.
michael@0 135 *
michael@0 136 * @param aFunc The function to invoke
michael@0 137 * @param aClosure An opaque pointer to pass to that function
michael@0 138 * @param aDelay The millisecond interval
michael@0 139 * @param aType Timer type per TYPE* consts defined above
michael@0 140 */
michael@0 141 [noscript] void initWithFuncCallback(in nsTimerCallbackFunc aCallback,
michael@0 142 in voidPtr aClosure,
michael@0 143 in unsigned long aDelay,
michael@0 144 in unsigned long aType);
michael@0 145
michael@0 146 /**
michael@0 147 * Initialize a timer to fire after the given millisecond interval.
michael@0 148 * This version takes a function to call.
michael@0 149 *
michael@0 150 * @param aFunc nsITimerCallback interface to call when timer expires
michael@0 151 * @param aDelay The millisecond interval
michael@0 152 * @param aType Timer type per TYPE* consts defined above
michael@0 153 */
michael@0 154 void initWithCallback(in nsITimerCallback aCallback,
michael@0 155 in unsigned long aDelay,
michael@0 156 in unsigned long aType);
michael@0 157
michael@0 158 /**
michael@0 159 * Cancel the timer. This method works on all types, not just on repeating
michael@0 160 * timers -- you might want to cancel a TYPE_ONE_SHOT timer, and even reuse
michael@0 161 * it by re-initializing it (to avoid object destruction and creation costs
michael@0 162 * by conserving one timer instance).
michael@0 163 */
michael@0 164 void cancel();
michael@0 165
michael@0 166 /**
michael@0 167 * The millisecond delay of the timeout.
michael@0 168 *
michael@0 169 * NOTE: Re-setting the delay on a one-shot timer that has already fired
michael@0 170 * doesn't restart the timer. Call one of the init() methods to restart
michael@0 171 * a one-shot timer.
michael@0 172 */
michael@0 173 attribute unsigned long delay;
michael@0 174
michael@0 175 /**
michael@0 176 * The timer type - one of the above TYPE_* constants.
michael@0 177 */
michael@0 178 attribute unsigned long type;
michael@0 179
michael@0 180 /**
michael@0 181 * The opaque pointer pass to initWithFuncCallback.
michael@0 182 */
michael@0 183 [noscript] readonly attribute voidPtr closure;
michael@0 184
michael@0 185 /**
michael@0 186 * The nsITimerCallback object passed to initWithCallback.
michael@0 187 */
michael@0 188 readonly attribute nsITimerCallback callback;
michael@0 189
michael@0 190 /**
michael@0 191 * The nsIEventTarget where the callback will be dispatched. Note that this
michael@0 192 * target may only be set before the call to one of the init methods above.
michael@0 193 *
michael@0 194 * By default the target is the thread that created the timer.
michael@0 195 */
michael@0 196 attribute nsIEventTarget target;
michael@0 197 };
michael@0 198
michael@0 199 %{C++
michael@0 200 #define NS_TIMER_CONTRACTID "@mozilla.org/timer;1"
michael@0 201 #define NS_TIMER_CALLBACK_TOPIC "timer-callback"
michael@0 202 %}
michael@0 203

mercurial