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