1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
//
// DO NOT EDIT.  THIS FILE IS GENERATED FROM ../../../dist/idl/nsIThread.idl
//


/// `interface nsIThread : nsISerialEventTarget`
///

/// ```text
/// /**
///  * This interface provides a high-level abstraction for an operating system
///  * thread.
///  *
///  * Threads have a built-in event queue, and a thread is an event target that
///  * can receive nsIRunnable objects (events) to be processed on the thread.
///  *
///  * See nsIThreadManager for the API used to create and locate threads.
///  */
/// ```
///

// The actual type definition for the interface. This struct has methods
// declared on it which will call through its vtable. You never want to pass
// this type around by value, always pass it behind a reference.

#[repr(C)]
pub struct nsIThread {
    vtable: *const nsIThreadVTable,

    /// This field is a phantomdata to ensure that the VTable type and any
    /// struct containing it is not safe to send across threads, as XPCOM is
    /// generally not threadsafe.
    ///
    /// XPCOM interfaces in general are not safe to send across threads.
    __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>,
}

// Implementing XpCom for an interface exposes its IID, which allows for easy
// use of the `.query_interface<T>` helper method. This also defines that
// method for nsIThread.
unsafe impl XpCom for nsIThread {
    const IID: nsIID = nsID(0x5801d193, 0x29d1, 0x4964,
        [0xa6, 0xb7, 0x70, 0xeb, 0x69, 0x7d, 0xdf, 0x2b]);
}

// We need to implement the RefCounted trait so we can be used with `RefPtr`.
// This trait teaches `RefPtr` how to manage our memory.
unsafe impl RefCounted for nsIThread {
    #[inline]
    unsafe fn addref(&self) {
        self.AddRef();
    }
    #[inline]
    unsafe fn release(&self) {
        self.Release();
    }
}

// This trait is implemented on all types which can be coerced to from nsIThread.
// It is used in the implementation of `fn coerce<T>`. We hide it from the
// documentation, because it clutters it up a lot.
#[doc(hidden)]
pub trait nsIThreadCoerce {
    /// Cheaply cast a value of this type from a `nsIThread`.
    fn coerce_from(v: &nsIThread) -> &Self;
}

// The trivial implementation: We can obviously coerce ourselves to ourselves.
impl nsIThreadCoerce for nsIThread {
    #[inline]
    fn coerce_from(v: &nsIThread) -> &Self {
        v
    }
}

impl nsIThread {
    /// Cast this `nsIThread` to one of its base interfaces.
    #[inline]
    pub fn coerce<T: nsIThreadCoerce>(&self) -> &T {
        T::coerce_from(self)
    }
}

// Every interface struct type implements `Deref` to its base interface. This
// causes methods on the base interfaces to be directly avaliable on the
// object. For example, you can call `.AddRef` or `.QueryInterface` directly
// on any interface which inherits from `nsISupports`.
impl ::std::ops::Deref for nsIThread {
    type Target = nsISerialEventTarget;
    #[inline]
    fn deref(&self) -> &nsISerialEventTarget {
        unsafe {
            ::std::mem::transmute(self)
        }
    }
}

// Ensure we can use .coerce() to cast to our base types as well. Any type which
// our base interface can coerce from should be coercable from us as well.
impl<T: nsISerialEventTargetCoerce> nsIThreadCoerce for T {
    #[inline]
    fn coerce_from(v: &nsIThread) -> &Self {
        T::coerce_from(v)
    }
}

// This struct represents the interface's VTable. A pointer to a statically
// allocated version of this struct is at the beginning of every nsIThread
// object. It contains one pointer field for each method in the interface. In
// the case where we can't generate a binding for a method, we include a void
// pointer.
#[doc(hidden)]
#[repr(C)]
pub struct nsIThreadVTable {
    /// We need to include the members from the base interface's vtable at the start
    /// of the VTable definition.
    pub __base: nsISerialEventTargetVTable,

    /* [noscript] readonly attribute PRThread PRThread; */
    /// Unable to generate binding because `native type PRThread is unsupported`
    pub GetPRThread: *const ::libc::c_void,

    /* [noscript] attribute boolean CanInvokeJS; */
    pub GetCanInvokeJS: unsafe extern "system" fn (this: *const nsIThread, aCanInvokeJS: *mut bool) -> nsresult,

    /* [noscript] attribute boolean CanInvokeJS; */
    pub SetCanInvokeJS: unsafe extern "system" fn (this: *const nsIThread, aCanInvokeJS: bool) -> nsresult,

    /* void shutdown (); */
    pub Shutdown: unsafe extern "system" fn (this: *const nsIThread) -> nsresult,

    /* boolean hasPendingEvents (); */
    pub HasPendingEvents: unsafe extern "system" fn (this: *const nsIThread, _retval: *mut bool) -> nsresult,

    /* boolean processNextEvent (in boolean mayWait); */
    pub ProcessNextEvent: unsafe extern "system" fn (this: *const nsIThread, mayWait: bool, _retval: *mut bool) -> nsresult,

    /* void asyncShutdown (); */
    pub AsyncShutdown: unsafe extern "system" fn (this: *const nsIThread) -> nsresult,

    /* [noscript] void idleDispatch (in alreadyAddRefed_nsIRunnable event); */
    /// Unable to generate binding because `native type already_AddRefed<nsIRunnable> is unsupported`
    pub IdleDispatch: *const ::libc::c_void,

    /* readonly attribute nsIEventTarget eventTarget; */
    pub GetEventTarget: unsafe extern "system" fn (this: *const nsIThread, aEventTarget: *mut *const nsIEventTarget) -> nsresult,

    /* [noscript,notxpcom] nsIEventTargetPtr EventTarget (); */
    /// Unable to generate binding because `native type nsIEventTarget* is unsupported`
    pub EventTarget: *const ::libc::c_void,

    /* [noscript,notxpcom] nsISerialEventTargetPtr SerialEventTarget (); */
    /// Unable to generate binding because `native type nsISerialEventTarget* is unsupported`
    pub SerialEventTarget: *const ::libc::c_void,
}


// The implementations of the function wrappers which are exposed to rust code.
// Call these methods rather than manually calling through the VTable struct.
impl nsIThread {

    /// ```text
    /// /**
    ///    * @returns
    ///    *   The NSPR thread object corresponding to this nsIThread.
    ///    */
    /// ```
    ///

    /// `[noscript] readonly attribute PRThread PRThread;`
    const _GetPRThread: () = ();

    /// ```text
    /// /**
    ///    * @returns
    ///    *  Whether or not this thread may call into JS. Used in the profiler
    ///    *  to avoid some unnecessary locking.
    ///    */
    /// ```
    ///

    /// `[noscript] attribute boolean CanInvokeJS;`
    #[inline]
    pub unsafe fn GetCanInvokeJS(&self, aCanInvokeJS: *mut bool) -> nsresult {
        ((*self.vtable).GetCanInvokeJS)(self, aCanInvokeJS)
    }


    /// ```text
    /// /**
    ///    * @returns
    ///    *  Whether or not this thread may call into JS. Used in the profiler
    ///    *  to avoid some unnecessary locking.
    ///    */
    /// ```
    ///

    /// `[noscript] attribute boolean CanInvokeJS;`
    #[inline]
    pub unsafe fn SetCanInvokeJS(&self, aCanInvokeJS: bool) -> nsresult {
        ((*self.vtable).SetCanInvokeJS)(self, aCanInvokeJS)
    }


    /// ```text
    /// /**
    ///    * Shutdown the thread.  This method prevents further dispatch of events to
    ///    * the thread, and it causes any pending events to run to completion before
    ///    * the thread joins (see PR_JoinThread) with the current thread.  During this
    ///    * method call, events for the current thread may be processed.
    ///    *
    ///    * This method MAY NOT be executed from the thread itself.  Instead, it is
    ///    * meant to be executed from another thread (usually the thread that created
        ///    * this thread or the main application thread).  When this function returns,
    ///    * the thread will be shutdown, and it will no longer be possible to dispatch
    ///    * events to the thread.
    ///    *
    ///    * @throws NS_ERROR_UNEXPECTED
    ///    *   Indicates that this method was erroneously called when this thread was
    ///    *   the current thread, that this thread was not created with a call to
    ///    *   nsIThreadManager::NewThread, or if this method was called more than once
    ///    *   on the thread object.
    ///    */
    /// ```
    ///

    /// `void shutdown ();`
    #[inline]
    pub unsafe fn Shutdown(&self, ) -> nsresult {
        ((*self.vtable).Shutdown)(self, )
    }


    /// ```text
    /// /**
    ///    * This method may be called to determine if there are any events ready to be
    ///    * processed.  It may only be called when this thread is the current thread.
    ///    *
    ///    * Because events may be added to this thread by another thread, a "false"
    ///    * result does not mean that this thread has no pending events.  It only
    ///    * means that there were no pending events when this method was called.
    ///    *
    ///    * @returns
    ///    *   A boolean value that if "true" indicates that this thread has one or
    ///    *   more pending events.
    ///    *
    ///    * @throws NS_ERROR_UNEXPECTED
    ///    *   Indicates that this method was erroneously called when this thread was
    ///    *   not the current thread.
    ///    */
    /// ```
    ///

    /// `boolean hasPendingEvents ();`
    #[inline]
    pub unsafe fn HasPendingEvents(&self, _retval: *mut bool) -> nsresult {
        ((*self.vtable).HasPendingEvents)(self, _retval)
    }


    /// ```text
    /// /**
    ///    * Process the next event.  If there are no pending events, then this method
    ///    * may wait -- depending on the value of the mayWait parameter -- until an
    ///    * event is dispatched to this thread.  This method is re-entrant but may
    ///    * only be called if this thread is the current thread.
    ///    *
    ///    * @param mayWait
    ///    *   A boolean parameter that if "true" indicates that the method may block
    ///    *   the calling thread to wait for a pending event.
    ///    *
    ///    * @returns
    ///    *   A boolean value that if "true" indicates that an event was processed.
    ///    *
    ///    * @throws NS_ERROR_UNEXPECTED
    ///    *   Indicates that this method was erroneously called when this thread was
    ///    *   not the current thread.
    ///    */
    /// ```
    ///

    /// `boolean processNextEvent (in boolean mayWait);`
    #[inline]
    pub unsafe fn ProcessNextEvent(&self, mayWait: bool, _retval: *mut bool) -> nsresult {
        ((*self.vtable).ProcessNextEvent)(self, mayWait, _retval)
    }


    /// ```text
    /// /**
    ///    * Shutdown the thread asynchronously.  This method immediately prevents
    ///    * further dispatch of events to the thread, and it causes any pending events
    ///    * to run to completion before this thread joins with the current thread.
    ///    *
    ///    * UNLIKE shutdown() this does not process events on the current thread.
    ///    * Instead it merely ensures that the current thread continues running until
    ///    * this thread has shut down.
    ///    *
    ///    * This method MAY NOT be executed from the thread itself.  Instead, it is
    ///    * meant to be executed from another thread (usually the thread that created
        ///    * this thread or the main application thread).  When this function returns,
    ///    * the thread will continue running until it exhausts its event queue.
    ///    *
    ///    * @throws NS_ERROR_UNEXPECTED
    ///    *   Indicates that this method was erroneously called when this thread was
    ///    *   the current thread, that this thread was not created with a call to
    ///    *   nsIThreadManager::NewThread, or if this method was called more than once
    ///    *   on the thread object.
    ///    */
    /// ```
    ///

    /// `void asyncShutdown ();`
    #[inline]
    pub unsafe fn AsyncShutdown(&self, ) -> nsresult {
        ((*self.vtable).AsyncShutdown)(self, )
    }


    /// ```text
    /// /**
    ///    * Dispatch an event to the thread's idle queue.  This function may be called
    ///    * from any thread, and it may be called re-entrantly.
    ///    *
    ///    * @param event
    ///    *   The alreadyAddRefed<> event to dispatch.
    ///    *   NOTE that the event will be leaked if it fails to dispatch.
    ///    *
    ///    * @throws NS_ERROR_INVALID_ARG
    ///    *   Indicates that event is null.
    ///    * @throws NS_ERROR_UNEXPECTED
    ///    *   Indicates that the thread is shutting down and has finished processing
    ///    * events, so this event would never run and has not been dispatched.
    ///    */
    /// ```
    ///

    /// `[noscript] void idleDispatch (in alreadyAddRefed_nsIRunnable event);`
    const _IdleDispatch: () = ();

    /// ```text
    /// /**
    ///    * Use this attribute to dispatch runnables to the thread. Eventually, the
    ///    * eventTarget attribute will be the only way to dispatch events to a
    ///    * thread--nsIThread will no longer inherit from nsIEventTarget.
    ///    */
    /// ```
    ///

    /// `readonly attribute nsIEventTarget eventTarget;`
    #[inline]
    pub unsafe fn GetEventTarget(&self, aEventTarget: *mut *const nsIEventTarget) -> nsresult {
        ((*self.vtable).GetEventTarget)(self, aEventTarget)
    }


    /// ```text
    /// /**
    ///    * A fast C++ getter for the eventTarget.
    ///    */
    /// ```
    ///

    /// `[noscript,notxpcom] nsIEventTargetPtr EventTarget ();`
    const _EventTarget: () = ();

    /// ```text
    /// /**
    ///    * A fast C++ getter for the eventTarget. It asserts that the thread's event
    ///    * target is an nsISerialEventTarget and then returns it.
    ///    */
    /// ```
    ///

    /// `[noscript,notxpcom] nsISerialEventTargetPtr SerialEventTarget ();`
    const _SerialEventTarget: () = ();

}