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::ChildProxy;
8
9mod sealed {
10    pub trait Sealed {}
11    impl<T: super::IsA<super::ChildProxy>> Sealed for T {}
12}
13
14pub trait ChildProxyExtManual: sealed::Sealed + IsA<ChildProxy> + 'static {
15    /// Looks up which object and `GParamSpec` would be effected by the given `name`.
16    /// ## `name`
17    /// name of the property to look up
18    ///
19    /// # Returns
20    ///
21    /// [`true`] if `target` and `pspec` could be found. [`false`] otherwise. In that
22    /// case the values for `pspec` and `target` are not modified. Unref `target` after
23    /// usage. For plain [`glib::Object`][crate::glib::Object] `target` is the same as `self`.
24    ///
25    /// ## `target`
26    /// pointer to a [`glib::Object`][crate::glib::Object] that
27    ///  takes the real object to set property on
28    ///
29    /// ## `pspec`
30    /// pointer to take the `GParamSpec`
31    ///  describing the property
32    #[doc(alias = "gst_child_proxy_lookup")]
33    fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError> {
34        unsafe {
35            let mut target = ptr::null_mut();
36            let mut pspec = ptr::null_mut();
37            let ret = from_glib(crate::ffi::gst_child_proxy_lookup(
38                self.as_ref().to_glib_none().0,
39                name.to_glib_none().0,
40                &mut target,
41                &mut pspec,
42            ));
43            if ret {
44                Ok((from_glib_full(target), from_glib_none(pspec)))
45            } else {
46                Err(glib::bool_error!("Failed to find child property '{name}'"))
47            }
48        }
49    }
50
51    /// Gets a single property using the GstChildProxy mechanism.
52    /// You are responsible for freeing it by calling [`glib::Value::unset()`][crate::glib::Value::unset()]
53    /// ## `name`
54    /// name of the property
55    ///
56    /// # Returns
57    ///
58    ///
59    /// ## `value`
60    /// a [`glib::Value`][crate::glib::Value] that should take the result.
61    #[doc(alias = "get_child_property")]
62    #[doc(alias = "gst_child_proxy_get")]
63    #[track_caller]
64    fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
65        let (child, pspec) = self.lookup(name).unwrap();
66        child.property(pspec.name())
67    }
68
69    #[doc(alias = "get_child_property")]
70    #[doc(alias = "gst_child_proxy_get")]
71    #[track_caller]
72    fn child_property_value(&self, name: &str) -> glib::Value {
73        let (child, pspec) = self.lookup(name).unwrap();
74        child.property_value(pspec.name())
75    }
76
77    /// Sets a single property using the GstChildProxy mechanism.
78    /// ## `name`
79    /// name of the property to set
80    /// ## `value`
81    /// new [`glib::Value`][crate::glib::Value] for the property
82    #[doc(alias = "gst_child_proxy_set")]
83    #[track_caller]
84    fn set_child_property(&self, name: &str, value: impl Into<glib::Value>) {
85        let (child, pspec) = self.lookup(name).unwrap();
86        child.set_property(pspec.name(), value)
87    }
88
89    #[doc(alias = "gst_child_proxy_set_property")]
90    #[track_caller]
91    fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
92        let (child, pspec) = self.lookup(name).unwrap();
93        child.set_property_from_value(pspec.name(), value)
94    }
95}
96
97impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {}