gstreamer/
child_proxy.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ptr;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{gobject::GObjectExtManualGst, ChildProxy};
8
9pub trait ChildProxyExtManual: IsA<ChildProxy> + 'static {
10    #[doc(alias = "gst_child_proxy_lookup")]
11    fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError> {
12        unsafe {
13            let mut target = ptr::null_mut();
14            let mut pspec = ptr::null_mut();
15            let ret = from_glib(crate::ffi::gst_child_proxy_lookup(
16                self.as_ref().to_glib_none().0,
17                name.to_glib_none().0,
18                &mut target,
19                &mut pspec,
20            ));
21            if ret {
22                Ok((from_glib_full(target), from_glib_none(pspec)))
23            } else {
24                Err(glib::bool_error!("Failed to find child property '{name}'"))
25            }
26        }
27    }
28
29    #[doc(alias = "get_child_property")]
30    #[doc(alias = "gst_child_proxy_get")]
31    #[track_caller]
32    fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
33        let (child, pspec) = self.lookup(name).unwrap();
34        child.property(pspec.name())
35    }
36
37    #[doc(alias = "get_child_property")]
38    #[doc(alias = "gst_child_proxy_get")]
39    #[track_caller]
40    fn child_property_value(&self, name: &str) -> glib::Value {
41        let (child, pspec) = self.lookup(name).unwrap();
42        child.property_value(pspec.name())
43    }
44
45    #[doc(alias = "gst_child_proxy_set")]
46    #[track_caller]
47    fn set_child_property(&self, name: &str, value: impl Into<glib::Value>) {
48        let (child, pspec) = self.lookup(name).unwrap();
49        child.set_property(pspec.name(), value)
50    }
51
52    #[doc(alias = "gst_child_proxy_set")]
53    #[track_caller]
54    fn set_child_property_from_str(&self, name: &str, value: &str) {
55        let (child, pspec) = self.lookup(name).unwrap();
56        child.set_property_from_str(pspec.name(), value)
57    }
58
59    #[doc(alias = "gst_child_proxy_set_property")]
60    #[track_caller]
61    fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
62        let (child, pspec) = self.lookup(name).unwrap();
63        child.set_property_from_value(pspec.name(), value)
64    }
65}
66
67impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {}