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