gstreamer/auto/
bus.rs

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