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::ChildProxy;
89mod sealed {
10pub trait Sealed {}
11impl<T: super::IsA<super::ChildProxy>> Sealed for T {}
12}
1314pub 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")]
33fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError> {
34unsafe {
35let mut target = ptr::null_mut();
36let mut pspec = ptr::null_mut();
37let ret = from_glib(crate::ffi::gst_child_proxy_lookup(
38self.as_ref().to_glib_none().0,
39 name.to_glib_none().0,
40&mut target,
41&mut pspec,
42 ));
43if ret {
44Ok((from_glib_full(target), from_glib_none(pspec)))
45 } else {
46Err(glib::bool_error!("Failed to find child property '{name}'"))
47 }
48 }
49 }
5051/// 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]
64fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
65let (child, pspec) = self.lookup(name).unwrap();
66 child.property(pspec.name())
67 }
6869#[doc(alias = "get_child_property")]
70 #[doc(alias = "gst_child_proxy_get")]
71 #[track_caller]
72fn child_property_value(&self, name: &str) -> glib::Value {
73let (child, pspec) = self.lookup(name).unwrap();
74 child.property_value(pspec.name())
75 }
7677/// 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]
84fn set_child_property(&self, name: &str, value: impl Into<glib::Value>) {
85let (child, pspec) = self.lookup(name).unwrap();
86 child.set_property(pspec.name(), value)
87 }
8889#[doc(alias = "gst_child_proxy_set_property")]
90 #[track_caller]
91fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
92let (child, pspec) = self.lookup(name).unwrap();
93 child.set_property_from_value(pspec.name(), value)
94 }
95}
9697impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {}