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
44mod sealed {
45    pub trait Sealed {}
46    impl<T: super::IsA<super::SystemClock>> Sealed for T {}
47}
48
49pub trait SystemClockExt: IsA<SystemClock> + sealed::Sealed + 'static {
50    #[doc(alias = "clock-type")]
51    fn clock_type(&self) -> ClockType {
52        ObjectExt::property(self.as_ref(), "clock-type")
53    }
54
55    #[doc(alias = "clock-type")]
56    fn set_clock_type(&self, clock_type: ClockType) {
57        ObjectExt::set_property(self.as_ref(), "clock-type", clock_type)
58    }
59
60    #[doc(alias = "clock-type")]
61    fn connect_clock_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
62        &self,
63        f: F,
64    ) -> SignalHandlerId {
65        unsafe extern "C" fn notify_clock_type_trampoline<
66            P: IsA<SystemClock>,
67            F: Fn(&P) + Send + Sync + 'static,
68        >(
69            this: *mut ffi::GstSystemClock,
70            _param_spec: glib::ffi::gpointer,
71            f: glib::ffi::gpointer,
72        ) {
73            let f: &F = &*(f as *const F);
74            f(SystemClock::from_glib_borrow(this).unsafe_cast_ref())
75        }
76        unsafe {
77            let f: Box_<F> = Box_::new(f);
78            connect_raw(
79                self.as_ptr() as *mut _,
80                b"notify::clock-type\0".as_ptr() as *const _,
81                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
82                    notify_clock_type_trampoline::<Self, F> as *const (),
83                )),
84                Box_::into_raw(f),
85            )
86        }
87    }
88}
89
90impl<O: IsA<SystemClock>> SystemClockExt for O {}