Skip to main content

gstreamer_editing_services/auto/
asset.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#![allow(deprecated)]
6
7use crate::{Extractable, MetaContainer, ffi};
8use glib::{
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
11    translate::*,
12};
13use std::{boxed::Box as Box_, pin::Pin};
14
15glib::wrapper! {
16    #[doc(alias = "GESAsset")]
17    pub struct Asset(Object<ffi::GESAsset, ffi::GESAssetClass>) @implements MetaContainer;
18
19    match fn {
20        type_ => || ffi::ges_asset_get_type(),
21    }
22}
23
24impl Asset {
25    pub const NONE: Option<&'static Asset> = None;
26
27    #[doc(alias = "ges_asset_needs_reload")]
28    #[doc(alias = "needs_reload")]
29    pub fn needs_reload_with_type(extractable_type: glib::types::Type, id: Option<&str>) -> bool {
30        assert_initialized_main_thread!();
31        unsafe {
32            from_glib(ffi::ges_asset_needs_reload(
33                extractable_type.into_glib(),
34                id.to_glib_none().0,
35            ))
36        }
37    }
38
39    #[doc(alias = "ges_asset_request")]
40    #[doc(alias = "request")]
41    pub fn request_with_type(
42        extractable_type: glib::types::Type,
43        id: Option<&str>,
44    ) -> Result<Option<Asset>, glib::Error> {
45        assert_initialized_main_thread!();
46        unsafe {
47            let mut error = std::ptr::null_mut();
48            let ret = ffi::ges_asset_request(
49                extractable_type.into_glib(),
50                id.to_glib_none().0,
51                &mut error,
52            );
53            if error.is_null() {
54                Ok(from_glib_full(ret))
55            } else {
56                Err(from_glib_full(error))
57            }
58        }
59    }
60
61    #[doc(alias = "ges_asset_request_async")]
62    #[doc(alias = "request_async")]
63    pub fn request_async_with_type<P: FnOnce(Result<Asset, glib::Error>) + 'static>(
64        extractable_type: glib::types::Type,
65        id: Option<&str>,
66        cancellable: Option<&impl IsA<gio::Cancellable>>,
67        callback: P,
68    ) {
69        assert_initialized_main_thread!();
70
71        let main_context = glib::MainContext::ref_thread_default();
72        let is_main_context_owner = main_context.is_owner();
73        let has_acquired_main_context = (!is_main_context_owner)
74            .then(|| main_context.acquire().ok())
75            .flatten();
76        assert!(
77            is_main_context_owner || has_acquired_main_context.is_some(),
78            "Async operations only allowed if the thread is owning the MainContext"
79        );
80
81        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
82            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
83        unsafe extern "C" fn request_async_with_type_trampoline<
84            P: FnOnce(Result<Asset, glib::Error>) + 'static,
85        >(
86            _source_object: *mut glib::gobject_ffi::GObject,
87            res: *mut gio::ffi::GAsyncResult,
88            user_data: glib::ffi::gpointer,
89        ) {
90            unsafe {
91                let mut error = std::ptr::null_mut();
92                let ret = ffi::ges_asset_request_finish(res, &mut error);
93                let result = if error.is_null() {
94                    Ok(from_glib_full(ret))
95                } else {
96                    Err(from_glib_full(error))
97                };
98                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
99                    Box_::from_raw(user_data as *mut _);
100                let callback: P = callback.into_inner();
101                callback(result);
102            }
103        }
104        let callback = request_async_with_type_trampoline::<P>;
105        unsafe {
106            ffi::ges_asset_request_async(
107                extractable_type.into_glib(),
108                id.to_glib_none().0,
109                cancellable.map(|p| p.as_ref()).to_glib_none().0,
110                Some(callback),
111                Box_::into_raw(user_data) as *mut _,
112            );
113        }
114    }
115
116    pub fn request_async_with_type_future(
117        extractable_type: glib::types::Type,
118        id: Option<&str>,
119    ) -> Pin<Box_<dyn std::future::Future<Output = Result<Asset, glib::Error>> + 'static>> {
120        skip_assert_initialized!();
121        let id = id.map(ToOwned::to_owned);
122        Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
123            Self::request_async_with_type(
124                extractable_type,
125                id.as_ref().map(::std::borrow::Borrow::borrow),
126                Some(cancellable),
127                move |res| {
128                    send.resolve(res);
129                },
130            );
131        }))
132    }
133}
134
135unsafe impl Send for Asset {}
136unsafe impl Sync for Asset {}
137
138pub trait AssetExt: IsA<Asset> + 'static {
139    #[doc(alias = "ges_asset_extract")]
140    fn extract(&self) -> Result<Extractable, glib::Error> {
141        unsafe {
142            let mut error = std::ptr::null_mut();
143            let ret = ffi::ges_asset_extract(self.as_ref().to_glib_none().0, &mut error);
144            if error.is_null() {
145                Ok(from_glib_none(ret))
146            } else {
147                Err(from_glib_full(error))
148            }
149        }
150    }
151
152    #[cfg_attr(feature = "v1_30", deprecated = "Since 1.30")]
153    #[allow(deprecated)]
154    #[doc(alias = "ges_asset_get_error")]
155    #[doc(alias = "get_error")]
156    fn error(&self) -> Option<glib::Error> {
157        unsafe { from_glib_none(ffi::ges_asset_get_error(self.as_ref().to_glib_none().0)) }
158    }
159
160    #[cfg(feature = "v1_30")]
161    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
162    #[doc(alias = "ges_asset_get_error_full")]
163    #[doc(alias = "get_error_full")]
164    fn error_full(&self) -> Option<glib::Error> {
165        unsafe {
166            from_glib_full(ffi::ges_asset_get_error_full(
167                self.as_ref().to_glib_none().0,
168            ))
169        }
170    }
171
172    #[doc(alias = "ges_asset_get_extractable_type")]
173    #[doc(alias = "get_extractable_type")]
174    #[doc(alias = "extractable-type")]
175    fn extractable_type(&self) -> glib::types::Type {
176        unsafe {
177            from_glib(ffi::ges_asset_get_extractable_type(
178                self.as_ref().to_glib_none().0,
179            ))
180        }
181    }
182
183    #[doc(alias = "ges_asset_get_id")]
184    #[doc(alias = "get_id")]
185    fn id(&self) -> glib::GString {
186        unsafe { from_glib_none(ffi::ges_asset_get_id(self.as_ref().to_glib_none().0)) }
187    }
188
189    #[cfg_attr(feature = "v1_30", deprecated = "Since 1.30")]
190    #[allow(deprecated)]
191    #[doc(alias = "ges_asset_get_proxy")]
192    #[doc(alias = "get_proxy")]
193    #[must_use]
194    fn proxy(&self) -> Option<Asset> {
195        unsafe { from_glib_none(ffi::ges_asset_get_proxy(self.as_ref().to_glib_none().0)) }
196    }
197
198    #[cfg(feature = "v1_30")]
199    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
200    #[doc(alias = "ges_asset_get_proxy_full")]
201    #[doc(alias = "get_proxy_full")]
202    #[must_use]
203    fn proxy_full(&self) -> Option<Asset> {
204        unsafe {
205            from_glib_full(ffi::ges_asset_get_proxy_full(
206                self.as_ref().to_glib_none().0,
207            ))
208        }
209    }
210
211    #[cfg_attr(feature = "v1_30", deprecated = "Since 1.30")]
212    #[allow(deprecated)]
213    #[doc(alias = "ges_asset_get_proxy_target")]
214    #[doc(alias = "get_proxy_target")]
215    #[doc(alias = "proxy-target")]
216    #[must_use]
217    fn proxy_target(&self) -> Option<Asset> {
218        unsafe {
219            from_glib_none(ffi::ges_asset_get_proxy_target(
220                self.as_ref().to_glib_none().0,
221            ))
222        }
223    }
224
225    #[cfg(feature = "v1_30")]
226    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
227    #[doc(alias = "ges_asset_get_proxy_target_full")]
228    #[doc(alias = "get_proxy_target_full")]
229    #[must_use]
230    fn proxy_target_full(&self) -> Option<Asset> {
231        unsafe {
232            from_glib_full(ffi::ges_asset_get_proxy_target_full(
233                self.as_ref().to_glib_none().0,
234            ))
235        }
236    }
237
238    #[cfg_attr(feature = "v1_30", deprecated = "Since 1.30")]
239    #[allow(deprecated)]
240    #[doc(alias = "ges_asset_list_proxies")]
241    fn list_proxies(&self) -> Vec<Asset> {
242        unsafe {
243            FromGlibPtrContainer::from_glib_none(ffi::ges_asset_list_proxies(
244                self.as_ref().to_glib_none().0,
245            ))
246        }
247    }
248
249    #[cfg(feature = "v1_30")]
250    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
251    #[doc(alias = "ges_asset_list_proxies_full")]
252    fn list_proxies_full(&self) -> Vec<Asset> {
253        unsafe {
254            FromGlibPtrContainer::from_glib_full(ffi::ges_asset_list_proxies_full(
255                self.as_ref().to_glib_none().0,
256            ))
257        }
258    }
259
260    #[doc(alias = "ges_asset_set_proxy")]
261    #[doc(alias = "proxy")]
262    fn set_proxy(&self, proxy: Option<&impl IsA<Asset>>) -> Result<(), glib::error::BoolError> {
263        unsafe {
264            glib::result_from_gboolean!(
265                ffi::ges_asset_set_proxy(
266                    self.as_ref().to_glib_none().0,
267                    proxy.map(|p| p.as_ref()).to_glib_none().0
268                ),
269                "Failed to set proxy"
270            )
271        }
272    }
273
274    #[doc(alias = "ges_asset_unproxy")]
275    fn unproxy(&self, proxy: &impl IsA<Asset>) -> Result<(), glib::error::BoolError> {
276        unsafe {
277            glib::result_from_gboolean!(
278                ffi::ges_asset_unproxy(
279                    self.as_ref().to_glib_none().0,
280                    proxy.as_ref().to_glib_none().0
281                ),
282                "Failed to unproxy asset"
283            )
284        }
285    }
286
287    #[doc(alias = "proxy")]
288    fn connect_proxy_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
289        unsafe extern "C" fn notify_proxy_trampoline<
290            P: IsA<Asset>,
291            F: Fn(&P) + Send + Sync + 'static,
292        >(
293            this: *mut ffi::GESAsset,
294            _param_spec: glib::ffi::gpointer,
295            f: glib::ffi::gpointer,
296        ) {
297            unsafe {
298                let f: &F = &*(f as *const F);
299                f(Asset::from_glib_borrow(this).unsafe_cast_ref())
300            }
301        }
302        unsafe {
303            let f: Box_<F> = Box_::new(f);
304            connect_raw(
305                self.as_ptr() as *mut _,
306                c"notify::proxy".as_ptr(),
307                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
308                    notify_proxy_trampoline::<Self, F> as *const (),
309                )),
310                Box_::into_raw(f),
311            )
312        }
313    }
314
315    #[doc(alias = "proxy-target")]
316    fn connect_proxy_target_notify<F: Fn(&Self) + Send + Sync + 'static>(
317        &self,
318        f: F,
319    ) -> SignalHandlerId {
320        unsafe extern "C" fn notify_proxy_target_trampoline<
321            P: IsA<Asset>,
322            F: Fn(&P) + Send + Sync + 'static,
323        >(
324            this: *mut ffi::GESAsset,
325            _param_spec: glib::ffi::gpointer,
326            f: glib::ffi::gpointer,
327        ) {
328            unsafe {
329                let f: &F = &*(f as *const F);
330                f(Asset::from_glib_borrow(this).unsafe_cast_ref())
331            }
332        }
333        unsafe {
334            let f: Box_<F> = Box_::new(f);
335            connect_raw(
336                self.as_ptr() as *mut _,
337                c"notify::proxy-target".as_ptr(),
338                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
339                    notify_proxy_target_trampoline::<Self, F> as *const (),
340                )),
341                Box_::into_raw(f),
342            )
343        }
344    }
345}
346
347impl<O: IsA<Asset>> AssetExt for O {}