gstreamer/
gtype.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ffi::c_void;
4
5use crate::ffi;
6use glib::translate::*;
7
8pub trait PluginApiExt {
9    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
10    #[doc(alias = "gst_type_mark_as_plugin_api")]
11    fn mark_as_plugin_api(self, flags: crate::PluginAPIFlags);
12    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
13    #[doc(alias = "gst_type_is_plugin_api")]
14    fn plugin_api_flags(self) -> Option<crate::PluginAPIFlags>;
15    #[doc(alias = "gst_element_type_set_skip_documentation")]
16    fn set_skip_documentation(self);
17    #[doc(alias = "gst_element_factory_get_skip_documentation")]
18    fn skip_documentation(self) -> bool;
19}
20
21impl PluginApiExt for glib::Type {
22    fn set_skip_documentation(self) {
23        let quark = glib::Quark::from_str("GST_ELEMENTCLASS_SKIP_DOCUMENTATION");
24        unsafe {
25            crate::glib::gobject_ffi::g_type_set_qdata(
26                self.into_glib(),
27                quark.into_glib(),
28                1 as *mut c_void,
29            );
30        }
31    }
32
33    fn skip_documentation(self) -> bool {
34        let quark = glib::Quark::from_str("GST_ELEMENTCLASS_SKIP_DOCUMENTATION");
35        unsafe {
36            !crate::glib::gobject_ffi::g_type_get_qdata(self.into_glib(), quark.into_glib())
37                .is_null()
38        }
39    }
40
41    fn plugin_api_flags(self) -> Option<crate::PluginAPIFlags> {
42        assert_initialized_main_thread!();
43        unsafe {
44            use std::mem;
45
46            let mut flags = mem::MaybeUninit::uninit();
47            let ret = from_glib(ffi::gst_type_is_plugin_api(
48                self.into_glib(),
49                flags.as_mut_ptr(),
50            ));
51            if ret {
52                Some(from_glib(flags.assume_init()))
53            } else {
54                None
55            }
56        }
57    }
58
59    fn mark_as_plugin_api(self, flags: crate::PluginAPIFlags) {
60        assert_initialized_main_thread!();
61
62        unsafe { ffi::gst_type_mark_as_plugin_api(self.into_glib(), flags.into_glib()) }
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use glib::prelude::StaticType;
69
70    use super::*;
71
72    #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
73    #[repr(u32)]
74    #[enum_type(name = "GstTestEnum")]
75    pub enum TestEnum {
76        #[enum_value(name = "test", nick = "test")]
77        Test,
78    }
79
80    #[test]
81    fn test_gtype_mark_as_api() {
82        crate::init().unwrap();
83
84        assert!(TestEnum::static_type().plugin_api_flags().is_none());
85        assert!(!TestEnum::static_type().skip_documentation());
86
87        TestEnum::static_type().mark_as_plugin_api(crate::PluginAPIFlags::empty());
88        TestEnum::static_type().set_skip_documentation();
89
90        assert!(
91            TestEnum::static_type().plugin_api_flags().unwrap() == crate::PluginAPIFlags::empty()
92        );
93        assert!(TestEnum::static_type().skip_documentation());
94    }
95}