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
use super::event::SBEvent;
use super::listener::SBListener;
use sys;
#[derive(Debug)]
pub struct SBBroadcaster {
pub raw: sys::SBBroadcasterRef,
}
impl SBBroadcaster {
pub fn new() -> SBBroadcaster {
SBBroadcaster::wrap(unsafe { sys::CreateSBBroadcaster() })
}
pub fn wrap(raw: sys::SBBroadcasterRef) -> SBBroadcaster {
SBBroadcaster { raw: raw }
}
pub fn maybe_wrap(raw: sys::SBBroadcasterRef) -> Option<SBBroadcaster> {
if unsafe { sys::SBBroadcasterIsValid(raw) != 0 } {
Some(SBBroadcaster { raw: raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBBroadcasterIsValid(self.raw) != 0 }
}
#[allow(missing_docs)]
pub fn broadcast_event_by_type(&self, event_type: u32, unique: bool) {
unsafe { sys::SBBroadcasterBroadcastEventByType(self.raw, event_type, unique as u8) };
}
#[allow(missing_docs)]
pub fn broadcast_event(&self, event: &SBEvent, unique: bool) {
unsafe { sys::SBBroadcasterBroadcastEvent(self.raw, event.raw, unique as u8) };
}
#[allow(missing_docs)]
pub fn add_initial_events_to_listener(&self, listener: &SBListener, requested_events: u32) {
unsafe {
sys::SBBroadcasterAddInitialEventsToListener(self.raw, listener.raw, requested_events)
};
}
#[allow(missing_docs)]
pub fn add_listener(&self, listener: &SBListener, event_mask: u32) -> u32 {
unsafe { sys::SBBroadcasterAddListener(self.raw, listener.raw, event_mask) }
}
#[allow(missing_docs)]
pub fn event_type_has_listeners(&self, event_type: u32) -> bool {
unsafe { sys::SBBroadcasterEventTypeHasListeners(self.raw, event_type) != 0 }
}
#[allow(missing_docs)]
pub fn remove_listener(&self, listener: &SBListener, event_mask: u32) -> bool {
unsafe { sys::SBBroadcasterRemoveListener(self.raw, listener.raw, event_mask) != 0 }
}
}
impl Default for SBBroadcaster {
fn default() -> SBBroadcaster {
SBBroadcaster::new()
}
}
impl Drop for SBBroadcaster {
fn drop(&mut self) {
unsafe { sys::DisposeSBBroadcaster(self.raw) };
}
}