gstreamer/auto/
registry.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, Object, Plugin, PluginFeature};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "GstRegistry")]
17    pub struct Registry(Object<ffi::GstRegistry, ffi::GstRegistryClass>) @extends Object;
18
19    match fn {
20        type_ => || ffi::gst_registry_get_type(),
21    }
22}
23
24impl Registry {
25    #[doc(alias = "gst_registry_add_feature")]
26    pub fn add_feature(
27        &self,
28        feature: &impl IsA<PluginFeature>,
29    ) -> Result<(), glib::error::BoolError> {
30        unsafe {
31            glib::result_from_gboolean!(
32                ffi::gst_registry_add_feature(
33                    self.to_glib_none().0,
34                    feature.as_ref().to_glib_none().0
35                ),
36                "Failed to add feature"
37            )
38        }
39    }
40
41    #[doc(alias = "gst_registry_add_plugin")]
42    pub fn add_plugin(&self, plugin: &Plugin) -> Result<(), glib::error::BoolError> {
43        unsafe {
44            glib::result_from_gboolean!(
45                ffi::gst_registry_add_plugin(self.to_glib_none().0, plugin.to_glib_none().0),
46                "Failed to add plugin"
47            )
48        }
49    }
50
51    #[doc(alias = "gst_registry_check_feature_version")]
52    pub fn check_feature_version(
53        &self,
54        feature_name: &str,
55        min_major: u32,
56        min_minor: u32,
57        min_micro: u32,
58    ) -> bool {
59        unsafe {
60            from_glib(ffi::gst_registry_check_feature_version(
61                self.to_glib_none().0,
62                feature_name.to_glib_none().0,
63                min_major,
64                min_minor,
65                min_micro,
66            ))
67        }
68    }
69
70    #[doc(alias = "gst_registry_find_feature")]
71    pub fn find_feature(&self, name: &str, type_: glib::types::Type) -> Option<PluginFeature> {
72        unsafe {
73            from_glib_full(ffi::gst_registry_find_feature(
74                self.to_glib_none().0,
75                name.to_glib_none().0,
76                type_.into_glib(),
77            ))
78        }
79    }
80
81    #[doc(alias = "gst_registry_find_plugin")]
82    pub fn find_plugin(&self, name: &str) -> Option<Plugin> {
83        unsafe {
84            from_glib_full(ffi::gst_registry_find_plugin(
85                self.to_glib_none().0,
86                name.to_glib_none().0,
87            ))
88        }
89    }
90
91    #[doc(alias = "gst_registry_get_feature_list_cookie")]
92    #[doc(alias = "get_feature_list_cookie")]
93    pub fn feature_list_cookie(&self) -> u32 {
94        unsafe { ffi::gst_registry_get_feature_list_cookie(self.to_glib_none().0) }
95    }
96
97    #[doc(alias = "gst_registry_lookup")]
98    pub fn lookup(&self, filename: &str) -> Option<Plugin> {
99        unsafe {
100            from_glib_full(ffi::gst_registry_lookup(
101                self.to_glib_none().0,
102                filename.to_glib_none().0,
103            ))
104        }
105    }
106
107    #[doc(alias = "gst_registry_lookup_feature")]
108    pub fn lookup_feature(&self, name: &str) -> Option<PluginFeature> {
109        unsafe {
110            from_glib_full(ffi::gst_registry_lookup_feature(
111                self.to_glib_none().0,
112                name.to_glib_none().0,
113            ))
114        }
115    }
116
117    #[doc(alias = "gst_registry_remove_feature")]
118    pub fn remove_feature(&self, feature: &impl IsA<PluginFeature>) {
119        unsafe {
120            ffi::gst_registry_remove_feature(
121                self.to_glib_none().0,
122                feature.as_ref().to_glib_none().0,
123            );
124        }
125    }
126
127    #[doc(alias = "gst_registry_remove_plugin")]
128    pub fn remove_plugin(&self, plugin: &Plugin) {
129        unsafe {
130            ffi::gst_registry_remove_plugin(self.to_glib_none().0, plugin.to_glib_none().0);
131        }
132    }
133
134    #[doc(alias = "gst_registry_scan_path")]
135    pub fn scan_path(&self, path: impl AsRef<std::path::Path>) -> bool {
136        unsafe {
137            from_glib(ffi::gst_registry_scan_path(
138                self.to_glib_none().0,
139                path.as_ref().to_glib_none().0,
140            ))
141        }
142    }
143
144    #[doc(alias = "gst_registry_get")]
145    pub fn get() -> Registry {
146        assert_initialized_main_thread!();
147        unsafe { from_glib_none(ffi::gst_registry_get()) }
148    }
149
150    #[doc(alias = "feature-added")]
151    pub fn connect_feature_added<F: Fn(&Self, &PluginFeature) + Send + Sync + 'static>(
152        &self,
153        f: F,
154    ) -> SignalHandlerId {
155        unsafe extern "C" fn feature_added_trampoline<
156            F: Fn(&Registry, &PluginFeature) + Send + Sync + 'static,
157        >(
158            this: *mut ffi::GstRegistry,
159            feature: *mut ffi::GstPluginFeature,
160            f: glib::ffi::gpointer,
161        ) {
162            let f: &F = &*(f as *const F);
163            f(&from_glib_borrow(this), &from_glib_borrow(feature))
164        }
165        unsafe {
166            let f: Box_<F> = Box_::new(f);
167            connect_raw(
168                self.as_ptr() as *mut _,
169                b"feature-added\0".as_ptr() as *const _,
170                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
171                    feature_added_trampoline::<F> as *const (),
172                )),
173                Box_::into_raw(f),
174            )
175        }
176    }
177
178    #[doc(alias = "plugin-added")]
179    pub fn connect_plugin_added<F: Fn(&Self, &Plugin) + Send + Sync + 'static>(
180        &self,
181        f: F,
182    ) -> SignalHandlerId {
183        unsafe extern "C" fn plugin_added_trampoline<
184            F: Fn(&Registry, &Plugin) + Send + Sync + 'static,
185        >(
186            this: *mut ffi::GstRegistry,
187            plugin: *mut ffi::GstPlugin,
188            f: glib::ffi::gpointer,
189        ) {
190            let f: &F = &*(f as *const F);
191            f(&from_glib_borrow(this), &from_glib_borrow(plugin))
192        }
193        unsafe {
194            let f: Box_<F> = Box_::new(f);
195            connect_raw(
196                self.as_ptr() as *mut _,
197                b"plugin-added\0".as_ptr() as *const _,
198                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
199                    plugin_added_trampoline::<F> as *const (),
200                )),
201                Box_::into_raw(f),
202            )
203        }
204    }
205}
206
207unsafe impl Send for Registry {}
208unsafe impl Sync for Registry {}