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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;

use crate::{ffi, Plugin, PluginFeature, Registry};

impl Registry {
    #[doc(alias = "gst_registry_update")]
    pub fn update() -> Result<(), glib::BoolError> {
        crate::auto::functions::update_registry()
    }

    /// Runs a filter against all features of the plugins in the registry
    /// and returns a GList with the results.
    /// If the first flag is set, only the first match is
    /// returned (as a list with a single object).
    /// ## `filter`
    /// the filter to use
    /// ## `first`
    /// only return first match
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  [`PluginFeature`][crate::PluginFeature]. Use `gst_plugin_feature_list_free()` after usage.
    ///
    /// MT safe.
    #[doc(alias = "gst_registry_feature_filter")]
    pub fn features_filtered<P: FnMut(&PluginFeature) -> bool>(
        &self,
        filter: P,
        first: bool,
    ) -> glib::List<PluginFeature> {
        let filter_data: P = filter;
        unsafe extern "C" fn filter_func<P: FnMut(&PluginFeature) -> bool>(
            feature: *mut ffi::GstPluginFeature,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let feature = from_glib_borrow(feature);
            let callback = user_data as *mut P;
            let res = (*callback)(&feature);
            res.into_glib()
        }
        let filter = Some(filter_func::<P> as _);
        let super_callback0: &P = &filter_data;
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_feature_filter(
                self.to_glib_none().0,
                filter,
                first.into_glib(),
                super_callback0 as *const _ as *mut _,
            ))
        }
    }

    /// Retrieves a `GList` of [`PluginFeature`][crate::PluginFeature] of `type_`.
    /// ## `type_`
    /// a `GType`.
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  [`PluginFeature`][crate::PluginFeature] of `type_`. Use `gst_plugin_feature_list_free()` after use
    ///
    /// MT safe.
    #[doc(alias = "gst_registry_get_feature_list")]
    #[doc(alias = "get_feature_list")]
    pub fn features(&self, type_: glib::types::Type) -> glib::List<PluginFeature> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list(
                self.to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

    /// Retrieves a `GList` of features of the plugin with name `name`.
    /// ## `name`
    /// a plugin name.
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  [`PluginFeature`][crate::PluginFeature]. Use `gst_plugin_feature_list_free()` after usage.
    #[doc(alias = "gst_registry_get_feature_list_by_plugin")]
    #[doc(alias = "get_feature_list_by_plugin")]
    pub fn features_by_plugin(&self, name: &str) -> glib::List<PluginFeature> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_feature_list_by_plugin(
                self.to_glib_none().0,
                name.to_glib_none().0,
            ))
        }
    }

    /// Get a copy of all plugins registered in the given registry. The refcount
    /// of each element in the list in incremented.
    ///
    /// # Returns
    ///
    /// a `GList` of [`Plugin`][crate::Plugin].
    ///  Use `gst_plugin_list_free()` after usage.
    ///
    /// MT safe.
    #[doc(alias = "gst_registry_get_plugin_list")]
    #[doc(alias = "get_plugin_list")]
    pub fn plugins(&self) -> glib::List<Plugin> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_get_plugin_list(
                self.to_glib_none().0,
            ))
        }
    }

    /// Runs a filter against all plugins in the registry and returns a `GList` with
    /// the results. If the first flag is set, only the first match is
    /// returned (as a list with a single object).
    /// Every plugin is reffed; use `gst_plugin_list_free()` after use, which
    /// will unref again.
    /// ## `filter`
    /// the filter to use
    /// ## `first`
    /// only return first match
    ///
    /// # Returns
    ///
    /// a `GList` of [`Plugin`][crate::Plugin].
    ///  Use `gst_plugin_list_free()` after usage.
    ///
    /// MT safe.
    #[doc(alias = "gst_registry_plugin_filter")]
    pub fn plugins_filtered<P: FnMut(&Plugin) -> bool>(
        &self,
        filter: P,
        first: bool,
    ) -> glib::List<Plugin> {
        let filter_data: P = filter;
        unsafe extern "C" fn filter_func<P: FnMut(&Plugin) -> bool>(
            plugin: *mut ffi::GstPlugin,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let plugin = from_glib_borrow(plugin);
            let callback = user_data as *const _ as *mut P;
            let res = (*callback)(&plugin);
            res.into_glib()
        }
        let filter = Some(filter_func::<P> as _);
        let super_callback0: &P = &filter_data;
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_registry_plugin_filter(
                self.to_glib_none().0,
                filter,
                first.into_glib(),
                super_callback0 as *const _ as *mut _,
            ))
        }
    }
}