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
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{ffi, prelude::*, Formatter};
use gst::glib::translate::*;

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Formatter>> Sealed for T {}
}

pub trait FormatterExtManual: sealed::Sealed + IsA<Formatter> + 'static {
    fn can_load_uri(&self, uri: &str) -> Result<(), glib::Error> {
        unsafe {
            let klass = self.class_of::<crate::Formatter>().unwrap();

            let f = klass.as_ref().can_load_uri.ok_or_else(|| {
                glib::Error::new(gst::CoreError::Failed, "No `can_load_uri` method defined")
            })?;

            let mut err = std::ptr::null_mut();
            let res = f(
                self.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
                &mut err,
            );

            if res == glib::ffi::GTRUE {
                Ok(())
            } else {
                Err(from_glib_full(err))
            }
        }
    }

    #[doc(alias = "ges_formatter_class_register_metas")]
    fn register(
        type_: glib::types::Type,
        name: &str,
        description: Option<&str>,
        extensions: Option<&str>,
        caps: Option<&str>,
        version: f64,
        rank: gst::Rank,
    ) {
        skip_assert_initialized!();

        unsafe {
            let klass = mut_override(
                gst::glib::Class::<crate::Formatter>::from_type(type_)
                    .unwrap()
                    .as_ref(),
            );

            ffi::ges_formatter_class_register_metas(
                klass,
                name.to_glib_none().0,
                description.to_glib_none().0,
                extensions.to_glib_none().0,
                caps.to_glib_none().0,
                version,
                rank.into_glib(),
            )
        }
    }
}

impl<O: IsA<Formatter>> FormatterExtManual for O {}