1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla code.
18 * The Initial Developer of the Original Code is Google Inc.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
23 * Darin Fisher <darin@meer.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include
"nsIThread.idl"
41 interface nsIThreadObserver
;
42 interface nsIThreadEventFilter
;
45 * The XPCOM thread object implements this interface, which allows a consumer
46 * to observe dispatch activity on the thread.
48 [scriptable
, uuid(f89b5063
-b06d
-42f8
-bf23
-4dfcf2d80d6a
)]
49 interface nsIThreadInternal
: nsIThread
52 * Get/set the current thread observer (may be null). This attribute may be
53 * read from any thread, but must only be set on the thread corresponding to
56 attribute nsIThreadObserver observer
;
59 * This method causes any events currently enqueued on the thread to be
60 * suppressed until PopEventQueue is called. Additionally, any new events
61 * dispatched to the thread will only be processed if they are accepted by
62 * the given filter. If the filter is null, then new events are accepted.
63 * Calls to PushEventQueue may be nested and must each be paired with a call
64 * to PopEventQueue in order to restore the original state of the thread.
67 * The thread event filter to apply to dispatched events, or null to accept
68 * all dispatched events.
70 void pushEventQueue
(in nsIThreadEventFilter filter
);
73 * Revert a call to PushEventQueue. When an event queue is popped, any
74 * events remaining in the queue are appended to the elder queue.
80 * This interface provides the observer with hooks to implement a layered
81 * event queue. For example, it is possible to overlay processing events
82 * for a GUI toolkit on top of the events for a thread:
86 * onDispatchedEvent(thread) {
87 * NativeQueue.signal();
89 * onProcessNextEvent(thread, mayWait, recursionDepth) {
90 * if (NativeQueue.hasNextEvent())
91 * NativeQueue.processNextEvent();
92 * while (mayWait && !thread.hasPendingEvent()) {
94 * NativeQueue.processNextEvent();
99 * NOTE: The implementation of this interface must be threadsafe.
101 * NOTE: It is valid to change the thread's observer during a call to an
104 [scriptable
, uuid(81D0B509
-F198
-4417-8020-08EB4271491F
)]
105 interface nsIThreadObserver
: nsISupports
108 * This method is called after an event has been dispatched to the thread.
109 * This method may be called from any thread.
112 * The thread where the event is being dispatched.
114 void onDispatchedEvent
(in nsIThreadInternal thread
);
117 * This method is called (from nsIThread::ProcessNextEvent) before an event
118 * is processed. This method is only called on the target thread.
121 * The thread being asked to process another event.
123 * Indicates whether or not the method is allowed to block the calling
124 * thread. For example, this parameter is false during thread shutdown.
125 * @param recursionDepth
126 * Indicates the number of calls to ProcessNextEvent on the call stack in
127 * addition to the current call.
129 void onProcessNextEvent
(in nsIThreadInternal thread
, in boolean mayWait
,
130 in unsigned long recursionDepth
);
133 * This method is called (from nsIThread::ProcessNextEvent) after an event
134 * is processed. This method is only called on the target thread.
137 * The thread that processed another event.
138 * @param recursionDepth
139 * Indicates the number of calls to ProcessNextEvent on the call stack in
140 * addition to the current call.
142 void afterProcessNextEvent
(in nsIThreadInternal thread
,
143 in unsigned long recursionDepth
);
147 * Interface passed to the nsIThreadInternal::PushEventQueue method.
149 [scriptable
, uuid(a0605c0b
-17f5
-4681-b8cd
-a1cd75d42559
)]
150 interface nsIThreadEventFilter
: nsISupports
153 * This method is called to determine whether or not an event may be accepted
154 * by a "nested" event queue (see nsIThreadInternal::PushEventQueue).
157 * The event being dispatched.
159 * WARNING: This method must not make any calls on the thread object.
161 [notxpcom
] boolean acceptEvent
(in nsIRunnable event
);