gstreamer/
bus_unix.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3cfg_if::cfg_if! {
4    if #[cfg(unix)] {
5        use glib::translate::ToGlibPtr;
6
7        use std::mem;
8        use std::os::unix;
9    } else if #[cfg(docsrs)] {
10        // Declare a fake RawFd for doc generation on windows
11        pub mod unix {
12            pub mod io {
13                pub struct RawFd{}
14            }
15        }
16    }
17}
18
19use super::Bus;
20use glib::prelude::*;
21
22pub trait UnixBusExtManual: IsA<Bus> + 'static {
23    #[doc(alias = "get_pollfd")]
24    #[doc(alias = "gst_bus_get_pollfd")]
25    fn pollfd(&self) -> unix::io::RawFd;
26}
27
28impl<T: IsA<Bus>> UnixBusExtManual for T {
29    fn pollfd(&self) -> unix::io::RawFd {
30        #[cfg(unix)]
31        unsafe {
32            let mut pollfd = mem::MaybeUninit::uninit();
33            crate::ffi::gst_bus_get_pollfd(self.as_ref().to_glib_none().0, pollfd.as_mut_ptr());
34            let pollfd = pollfd.assume_init();
35            pollfd.fd
36        }
37
38        #[cfg(all(not(unix), docsrs))]
39        unix::io::RawFd {}
40    }
41}