1// Take a look at the license at the top of the repository in the LICENSE file.
23use std::ptr;
45use glib::{prelude::*, translate::*};
67use crate::{gobject::GObjectExtManualGst, ChildProxy};
89pub 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")]
28fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError> {
29unsafe {
30let mut target = ptr::null_mut();
31let mut pspec = ptr::null_mut();
32let ret = from_glib(crate::ffi::gst_child_proxy_lookup(
33self.as_ref().to_glib_none().0,
34 name.to_glib_none().0,
35&mut target,
36&mut pspec,
37 ));
38if ret {
39Ok((from_glib_full(target), from_glib_none(pspec)))
40 } else {
41Err(glib::bool_error!("Failed to find child property '{name}'"))
42 }
43 }
44 }
4546/// 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]
59fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
60let (child, pspec) = self.lookup(name).unwrap();
61 child.property(pspec.name())
62 }
6364#[doc(alias = "get_child_property")]
65 #[doc(alias = "gst_child_proxy_get")]
66 #[track_caller]
67fn child_property_value(&self, name: &str) -> glib::Value {
68let (child, pspec) = self.lookup(name).unwrap();
69 child.property_value(pspec.name())
70 }
7172/// 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]
79fn set_child_property(&self, name: &str, value: impl Into<glib::Value>) {
80let (child, pspec) = self.lookup(name).unwrap();
81 child.set_property(pspec.name(), value)
82 }
8384#[doc(alias = "gst_child_proxy_set")]
85 #[track_caller]
86fn set_child_property_from_str(&self, name: &str, value: &str) {
87let (child, pspec) = self.lookup(name).unwrap();
88 child.set_property_from_str(pspec.name(), value)
89 }
9091#[doc(alias = "gst_child_proxy_set_property")]
92 #[track_caller]
93fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
94let (child, pspec) = self.lookup(name).unwrap();
95 child.set_property_from_value(pspec.name(), value)
96 }
97}
9899impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {}