1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Take a look at the license at the top of the repository in the LICENSE file.

use std::ffi::c_void;

use crate::ffi;
use glib::translate::*;

pub trait PluginApiExt {
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "gst_type_mark_as_plugin_api")]
    fn mark_as_plugin_api(self, flags: crate::PluginAPIFlags);
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "gst_type_is_plugin_api")]
    fn plugin_api_flags(self) -> Option<crate::PluginAPIFlags>;
    #[doc(alias = "gst_element_type_set_skip_documentation")]
    fn set_skip_documentation(self);
    #[doc(alias = "gst_element_factory_get_skip_documentation")]
    fn skip_documentation(self) -> bool;
}

impl PluginApiExt for glib::Type {
    fn set_skip_documentation(self) {
        let quark = glib::Quark::from_str("GST_ELEMENTCLASS_SKIP_DOCUMENTATION");
        unsafe {
            crate::glib::gobject_ffi::g_type_set_qdata(
                self.into_glib(),
                quark.into_glib(),
                1 as *mut c_void,
            );
        }
    }

    fn skip_documentation(self) -> bool {
        let quark = glib::Quark::from_str("GST_ELEMENTCLASS_SKIP_DOCUMENTATION");
        unsafe {
            !crate::glib::gobject_ffi::g_type_get_qdata(self.into_glib(), quark.into_glib())
                .is_null()
        }
    }

    fn plugin_api_flags(self) -> Option<crate::PluginAPIFlags> {
        assert_initialized_main_thread!();
        unsafe {
            use std::mem;

            let mut flags = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gst_type_is_plugin_api(
                self.into_glib(),
                flags.as_mut_ptr(),
            ));
            if ret {
                Some(from_glib(flags.assume_init()))
            } else {
                None
            }
        }
    }

    fn mark_as_plugin_api(self, flags: crate::PluginAPIFlags) {
        assert_initialized_main_thread!();

        unsafe { ffi::gst_type_mark_as_plugin_api(self.into_glib(), flags.into_glib()) }
    }
}

#[cfg(test)]
mod tests {
    use glib::prelude::StaticType;

    use super::*;

    #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
    #[repr(u32)]
    #[enum_type(name = "GstTestEnum")]
    pub enum TestEnum {
        #[enum_value(name = "test", nick = "test")]
        Test,
    }

    #[test]
    fn test_gtype_mark_as_api() {
        crate::init().unwrap();

        assert!(TestEnum::static_type().plugin_api_flags().is_none());
        assert!(!TestEnum::static_type().skip_documentation());

        TestEnum::static_type().mark_as_plugin_api(crate::PluginAPIFlags::empty());
        TestEnum::static_type().set_skip_documentation();

        assert!(
            TestEnum::static_type().plugin_api_flags().unwrap() == crate::PluginAPIFlags::empty()
        );
        assert!(TestEnum::static_type().skip_documentation());
    }
}