gstreamer/auto/
system_clock.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, Clock, ClockType, Object};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GstSystemClock")]
16    pub struct SystemClock(Object<ffi::GstSystemClock, ffi::GstSystemClockClass>) @extends Clock, Object;
17
18    match fn {
19        type_ => || ffi::gst_system_clock_get_type(),
20    }
21}
22
23impl SystemClock {
24    pub const NONE: Option<&'static SystemClock> = None;
25
26    #[doc(alias = "gst_system_clock_obtain")]
27    pub fn obtain() -> Clock {
28        assert_initialized_main_thread!();
29        unsafe { from_glib_full(ffi::gst_system_clock_obtain()) }
30    }
31
32    #[doc(alias = "gst_system_clock_set_default")]
33    pub fn set_default(new_clock: Option<&impl IsA<Clock>>) {
34        assert_initialized_main_thread!();
35        unsafe {
36            ffi::gst_system_clock_set_default(new_clock.map(|p| p.as_ref()).to_glib_none().0);
37        }
38    }
39}
40
41unsafe impl Send for SystemClock {}
42unsafe impl Sync for SystemClock {}
43
44pub trait SystemClockExt: IsA<SystemClock> + 'static {
45    #[doc(alias = "clock-type")]
46    fn clock_type(&self) -> ClockType {
47        ObjectExt::property(self.as_ref(), "clock-type")
48    }
49
50    #[doc(alias = "clock-type")]
51    fn set_clock_type(&self, clock_type: ClockType) {
52        ObjectExt::set_property(self.as_ref(), "clock-type", clock_type)
53    }
54
55    #[doc(alias = "clock-type")]
56    fn connect_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
57        &self,
58        f: F,
59    ) -> SignalHandlerId {
60        unsafe extern "C" fn notify_clock_type_trampoline<
61            P: IsA<SystemClock>,
62            F: Fn(&P) + Send + Sync + 'static,
63        >(
64            this: *mut ffi::GstSystemClock,
65            _param_spec: glib::ffi::gpointer,
66            f: glib::ffi::gpointer,
67        ) {
68            let f: &F = &*(f as *const F);
69            f(SystemClock::from_glib_borrow(this).unsafe_cast_ref())
70        }
71        unsafe {
72            let f: Box_<F> = Box_::new(f);
73            connect_raw(
74                self.as_ptr() as *mut _,
75                c"notify::clock-type".as_ptr() as *const _,
76                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
77                    notify_clock_type_trampoline::<Self, F> as *const (),
78                )),
79                Box_::into_raw(f),
80            )
81        }
82    }
83}
84
85impl<O: IsA<SystemClock>> SystemClockExt for O {}