1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ClockTime, Message, Object};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::{boxed::Box as Box_, mem::transmute};
13
14glib::wrapper! {
15 #[doc(alias = "GstBus")]
16 pub struct Bus(Object<ffi::GstBus, ffi::GstBusClass>) @extends Object;
17
18 match fn {
19 type_ => || ffi::gst_bus_get_type(),
20 }
21}
22
23impl Bus {
24 #[doc(alias = "gst_bus_new")]
25 pub fn new() -> Bus {
26 assert_initialized_main_thread!();
27 unsafe { from_glib_full(ffi::gst_bus_new()) }
28 }
29
30 #[doc(alias = "gst_bus_add_signal_watch")]
31 pub fn add_signal_watch(&self) {
32 unsafe {
33 ffi::gst_bus_add_signal_watch(self.to_glib_none().0);
34 }
35 }
36
37 //#[doc(alias = "gst_bus_async_signal_func")]
38 //pub fn async_signal_func(&self, message: &Message, data: /*Unimplemented*/Option<Basic: Pointer>) -> bool {
39 // unsafe { TODO: call ffi:gst_bus_async_signal_func() }
40 //}
41
42 #[doc(alias = "gst_bus_disable_sync_message_emission")]
43 pub fn disable_sync_message_emission(&self) {
44 unsafe {
45 ffi::gst_bus_disable_sync_message_emission(self.to_glib_none().0);
46 }
47 }
48
49 #[doc(alias = "gst_bus_enable_sync_message_emission")]
50 pub fn enable_sync_message_emission(&self) {
51 unsafe {
52 ffi::gst_bus_enable_sync_message_emission(self.to_glib_none().0);
53 }
54 }
55
56 //#[doc(alias = "gst_bus_get_pollfd")]
57 //#[doc(alias = "get_pollfd")]
58 //pub fn pollfd(&self, fd: /*Ignored*/glib::PollFD) {
59 // unsafe { TODO: call ffi:gst_bus_get_pollfd() }
60 //}
61
62 #[doc(alias = "gst_bus_have_pending")]
63 pub fn have_pending(&self) -> bool {
64 unsafe { from_glib(ffi::gst_bus_have_pending(self.to_glib_none().0)) }
65 }
66
67 #[doc(alias = "gst_bus_peek")]
68 pub fn peek(&self) -> Option<Message> {
69 unsafe { from_glib_full(ffi::gst_bus_peek(self.to_glib_none().0)) }
70 }
71
72 #[doc(alias = "gst_bus_pop")]
73 pub fn pop(&self) -> Option<Message> {
74 unsafe { from_glib_full(ffi::gst_bus_pop(self.to_glib_none().0)) }
75 }
76
77 #[doc(alias = "gst_bus_post")]
78 pub fn post(&self, message: Message) -> Result<(), glib::error::BoolError> {
79 unsafe {
80 glib::result_from_gboolean!(
81 ffi::gst_bus_post(self.to_glib_none().0, message.into_glib_ptr()),
82 "Failed to post message"
83 )
84 }
85 }
86
87 #[doc(alias = "gst_bus_remove_signal_watch")]
88 pub fn remove_signal_watch(&self) {
89 unsafe {
90 ffi::gst_bus_remove_signal_watch(self.to_glib_none().0);
91 }
92 }
93
94 #[doc(alias = "gst_bus_remove_watch")]
95 #[allow(dead_code)]
96 pub(crate) fn remove_watch(&self) -> Result<(), glib::error::BoolError> {
97 unsafe {
98 glib::result_from_gboolean!(
99 ffi::gst_bus_remove_watch(self.to_glib_none().0),
100 "Bus has no event source"
101 )
102 }
103 }
104
105 #[doc(alias = "gst_bus_set_flushing")]
106 pub fn set_flushing(&self, flushing: bool) {
107 unsafe {
108 ffi::gst_bus_set_flushing(self.to_glib_none().0, flushing.into_glib());
109 }
110 }
111
112 //#[doc(alias = "gst_bus_sync_signal_handler")]
113 //pub fn sync_signal_handler(&self, message: &Message, data: /*Unimplemented*/Option<Basic: Pointer>) -> BusSyncReply {
114 // unsafe { TODO: call ffi:gst_bus_sync_signal_handler() }
115 //}
116
117 #[doc(alias = "gst_bus_timed_pop")]
118 pub fn timed_pop(&self, timeout: impl Into<Option<ClockTime>>) -> Option<Message> {
119 unsafe {
120 from_glib_full(ffi::gst_bus_timed_pop(
121 self.to_glib_none().0,
122 timeout.into().into_glib(),
123 ))
124 }
125 }
126
127 #[doc(alias = "message")]
128 pub fn connect_message<F: Fn(&Self, &Message) + Send + 'static>(
129 &self,
130 detail: Option<&str>,
131 f: F,
132 ) -> SignalHandlerId {
133 unsafe extern "C" fn message_trampoline<F: Fn(&Bus, &Message) + Send + 'static>(
134 this: *mut ffi::GstBus,
135 message: *mut ffi::GstMessage,
136 f: glib::ffi::gpointer,
137 ) {
138 let f: &F = &*(f as *const F);
139 f(&from_glib_borrow(this), &from_glib_borrow(message))
140 }
141 unsafe {
142 let f: Box_<F> = Box_::new(f);
143 let detailed_signal_name = detail.map(|name| format!("message::{name}\0"));
144 let signal_name: &[u8] = detailed_signal_name
145 .as_ref()
146 .map_or(&b"message\0"[..], |n| n.as_bytes());
147 connect_raw(
148 self.as_ptr() as *mut _,
149 signal_name.as_ptr() as *const _,
150 Some(transmute::<_, unsafe extern "C" fn()>(
151 message_trampoline::<F> as *const (),
152 )),
153 Box_::into_raw(f),
154 )
155 }
156 }
157
158 #[doc(alias = "sync-message")]
159 pub fn connect_sync_message<F: Fn(&Self, &Message) + Send + Sync + 'static>(
160 &self,
161 detail: Option<&str>,
162 f: F,
163 ) -> SignalHandlerId {
164 unsafe extern "C" fn sync_message_trampoline<
165 F: Fn(&Bus, &Message) + Send + Sync + 'static,
166 >(
167 this: *mut ffi::GstBus,
168 message: *mut ffi::GstMessage,
169 f: glib::ffi::gpointer,
170 ) {
171 let f: &F = &*(f as *const F);
172 f(&from_glib_borrow(this), &from_glib_borrow(message))
173 }
174 unsafe {
175 let f: Box_<F> = Box_::new(f);
176 let detailed_signal_name = detail.map(|name| format!("sync-message::{name}\0"));
177 let signal_name: &[u8] = detailed_signal_name
178 .as_ref()
179 .map_or(&b"sync-message\0"[..], |n| n.as_bytes());
180 connect_raw(
181 self.as_ptr() as *mut _,
182 signal_name.as_ptr() as *const _,
183 Some(transmute::<_, unsafe extern "C" fn()>(
184 sync_message_trampoline::<F> as *const (),
185 )),
186 Box_::into_raw(f),
187 )
188 }
189 }
190}
191
192impl Default for Bus {
193 fn default() -> Self {
194 Self::new()
195 }
196}
197
198unsafe impl Send for Bus {}
199unsafe impl Sync for Bus {}
200