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
132mod sealed {
133    pub trait Sealed {}
134    impl<T: super::IsA<super::Asset>> Sealed for T {}
135}
136
137pub trait AssetExt: IsA<Asset> + sealed::Sealed + 'static {
138    #[doc(alias = "ges_asset_extract")]
139    fn extract(&self) -> Result<Extractable, glib::Error> {
140        unsafe {
141            let mut error = std::ptr::null_mut();
142            let ret = ffi::ges_asset_extract(self.as_ref().to_glib_none().0, &mut error);
143            if error.is_null() {
144                Ok(from_glib_none(ret))
145            } else {
146                Err(from_glib_full(error))
147            }
148        }
149    }
150
151    #[doc(alias = "ges_asset_get_error")]
152    #[doc(alias = "get_error")]
153    fn error(&self) -> Option<glib::Error> {
154        unsafe { from_glib_none(ffi::ges_asset_get_error(self.as_ref().to_glib_none().0)) }
155    }
156
157    #[doc(alias = "ges_asset_get_extractable_type")]
158    #[doc(alias = "get_extractable_type")]
159    #[doc(alias = "extractable-type")]
160    fn extractable_type(&self) -> glib::types::Type {
161        unsafe {
162            from_glib(ffi::ges_asset_get_extractable_type(
163                self.as_ref().to_glib_none().0,
164            ))
165        }
166    }
167
168    #[doc(alias = "ges_asset_get_id")]
169    #[doc(alias = "get_id")]
170    fn id(&self) -> glib::GString {
171        unsafe { from_glib_none(ffi::ges_asset_get_id(self.as_ref().to_glib_none().0)) }
172    }
173
174    #[doc(alias = "ges_asset_get_proxy")]
175    #[doc(alias = "get_proxy")]
176    #[must_use]
177    fn proxy(&self) -> Option<Asset> {
178        unsafe { from_glib_none(ffi::ges_asset_get_proxy(self.as_ref().to_glib_none().0)) }
179    }
180
181    #[doc(alias = "ges_asset_get_proxy_target")]
182    #[doc(alias = "get_proxy_target")]
183    #[doc(alias = "proxy-target")]
184    #[must_use]
185    fn proxy_target(&self) -> Option<Asset> {
186        unsafe {
187            from_glib_none(ffi::ges_asset_get_proxy_target(
188                self.as_ref().to_glib_none().0,
189            ))
190        }
191    }
192
193    #[doc(alias = "ges_asset_list_proxies")]
194    fn list_proxies(&self) -> Vec<Asset> {
195        unsafe {
196            FromGlibPtrContainer::from_glib_none(ffi::ges_asset_list_proxies(
197                self.as_ref().to_glib_none().0,
198            ))
199        }
200    }
201
202    #[doc(alias = "ges_asset_set_proxy")]
203    #[doc(alias = "proxy")]
204    fn set_proxy(&self, proxy: Option<&impl IsA<Asset>>) -> Result<(), glib::error::BoolError> {
205        unsafe {
206            glib::result_from_gboolean!(
207                ffi::ges_asset_set_proxy(
208                    self.as_ref().to_glib_none().0,
209                    proxy.map(|p| p.as_ref()).to_glib_none().0
210                ),
211                "Failed to set proxy"
212            )
213        }
214    }
215
216    #[doc(alias = "ges_asset_unproxy")]
217    fn unproxy(&self, proxy: &impl IsA<Asset>) -> Result<(), glib::error::BoolError> {
218        unsafe {
219            glib::result_from_gboolean!(
220                ffi::ges_asset_unproxy(
221                    self.as_ref().to_glib_none().0,
222                    proxy.as_ref().to_glib_none().0
223                ),
224                "Failed to unproxy asset"
225            )
226        }
227    }
228
229    #[doc(alias = "proxy")]
230    fn connect_proxy_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
231        unsafe extern "C" fn notify_proxy_trampoline<
232            P: IsA<Asset>,
233            F: Fn(&P) + Send + Sync + 'static,
234        >(
235            this: *mut ffi::GESAsset,
236            _param_spec: glib::ffi::gpointer,
237            f: glib::ffi::gpointer,
238        ) {
239            let f: &F = &*(f as *const F);
240            f(Asset::from_glib_borrow(this).unsafe_cast_ref())
241        }
242        unsafe {
243            let f: Box_<F> = Box_::new(f);
244            connect_raw(
245                self.as_ptr() as *mut _,
246                b"notify::proxy\0".as_ptr() as *const _,
247                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
248                    notify_proxy_trampoline::<Self, F> as *const (),
249                )),
250                Box_::into_raw(f),
251            )
252        }
253    }
254
255    #[doc(alias = "proxy-target")]
256    fn connect_proxy_target_notify<F: Fn(&Self) + Send + Sync + 'static>(
257        &self,
258        f: F,
259    ) -> SignalHandlerId {
260        unsafe extern "C" fn notify_proxy_target_trampoline<
261            P: IsA<Asset>,
262            F: Fn(&P) + Send + Sync + 'static,
263        >(
264            this: *mut ffi::GESAsset,
265            _param_spec: glib::ffi::gpointer,
266            f: glib::ffi::gpointer,
267        ) {
268            let f: &F = &*(f as *const F);
269            f(Asset::from_glib_borrow(this).unsafe_cast_ref())
270        }
271        unsafe {
272            let f: Box_<F> = Box_::new(f);
273            connect_raw(
274                self.as_ptr() as *mut _,
275                b"notify::proxy-target\0".as_ptr() as *const _,
276                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
277                    notify_proxy_target_trampoline::<Self, F> as *const (),
278                )),
279                Box_::into_raw(f),
280            )
281        }
282    }
283}
284
285impl<O: IsA<Asset>> AssetExt for O {}