1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::ChildProxy;
use glib::prelude::*;
use glib::translate::*;
use std::ptr;

pub trait ChildProxyExtManual: 'static {
    /// Looks up which object and `GParamSpec` would be effected by the given `name`.
    /// ## `name`
    /// name of the property to look up
    ///
    /// # Returns
    ///
    /// [`true`] if `target` and `pspec` could be found. [`false`] otherwise. In that
    /// case the values for `pspec` and `target` are not modified. Unref `target` after
    /// usage. For plain [`glib::Object`][crate::glib::Object] `target` is the same as `self`.
    ///
    /// ## `target`
    /// pointer to a [`glib::Object`][crate::glib::Object] that
    ///  takes the real object to set property on
    ///
    /// ## `pspec`
    /// pointer to take the `GParamSpec`
    ///  describing the property
    #[doc(alias = "gst_child_proxy_lookup")]
    fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError>;

    /// Gets a single property using the GstChildProxy mechanism.
    /// You are responsible for freeing it by calling [`glib::Value::unset()`][crate::glib::Value::unset()]
    /// ## `name`
    /// name of the property
    ///
    /// # Returns
    ///
    ///
    /// ## `value`
    /// a [`glib::Value`][crate::glib::Value] that should take the result.
    #[doc(alias = "get_child_property")]
    #[doc(alias = "gst_child_proxy_get")]
    fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V;
    #[doc(alias = "get_child_property")]
    #[doc(alias = "gst_child_proxy_get")]
    fn child_property_value(&self, name: &str) -> glib::Value;
    #[doc(alias = "get_child_property")]
    #[doc(alias = "gst_child_proxy_get")]
    fn try_child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(
        &self,
        name: &str,
    ) -> Result<V, glib::BoolError>;
    #[doc(alias = "get_child_property")]
    #[doc(alias = "gst_child_proxy_get")]
    fn try_child_property_value(&self, name: &str) -> Result<glib::Value, glib::BoolError>;

    /// Sets a single property using the GstChildProxy mechanism.
    /// ## `name`
    /// name of the property to set
    /// ## `value`
    /// new [`glib::Value`][crate::glib::Value] for the property
    #[doc(alias = "gst_child_proxy_set")]
    fn set_child_property<V: glib::ToValue>(&self, name: &str, value: V);
    #[doc(alias = "gst_child_proxy_set_property")]
    fn set_child_property_from_value(&self, name: &str, value: &glib::Value);
    #[doc(alias = "gst_child_proxy_set")]
    fn try_set_child_property<V: glib::ToValue>(
        &self,
        name: &str,
        value: V,
    ) -> Result<(), glib::BoolError>;
    #[doc(alias = "gst_child_proxy_set_property")]
    fn try_set_child_property_from_value(
        &self,
        name: &str,
        value: &glib::Value,
    ) -> Result<(), glib::BoolError>;
}

impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
    fn lookup(&self, name: &str) -> Result<(glib::Object, glib::ParamSpec), glib::BoolError> {
        unsafe {
            let mut target = ptr::null_mut();
            let mut pspec = ptr::null_mut();
            let ret = from_glib(ffi::gst_child_proxy_lookup(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                &mut target,
                &mut pspec,
            ));
            if ret {
                Ok((from_glib_full(target), from_glib_none(pspec)))
            } else {
                Err(glib::bool_error!("Failed to find child property"))
            }
        }
    }

    fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
        let (child, pspec) = self.lookup(name).unwrap();
        child.property(pspec.name())
    }

    fn child_property_value(&self, name: &str) -> glib::Value {
        let (child, pspec) = self.lookup(name).unwrap();
        child.property_value(pspec.name())
    }

    fn try_child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(
        &self,
        name: &str,
    ) -> Result<V, glib::BoolError> {
        let (child, pspec) = self.lookup(name)?;
        child.try_property(pspec.name())
    }

    fn try_child_property_value(&self, name: &str) -> Result<glib::Value, glib::BoolError> {
        let (child, pspec) = self.lookup(name)?;
        child.try_property_value(pspec.name())
    }

    fn set_child_property<V: glib::ToValue>(&self, name: &str, value: V) {
        let (child, pspec) = self.lookup(name).unwrap();
        child.set_property(pspec.name(), value)
    }

    fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
        let (child, pspec) = self.lookup(name).unwrap();
        child.set_property_from_value(pspec.name(), value)
    }

    fn try_set_child_property<V: glib::ToValue>(
        &self,
        name: &str,
        value: V,
    ) -> Result<(), glib::BoolError> {
        let (child, pspec) = self.lookup(name)?;
        child.try_set_property(pspec.name(), value)
    }

    fn try_set_child_property_from_value(
        &self,
        name: &str,
        value: &glib::Value,
    ) -> Result<(), glib::BoolError> {
        let (child, pspec) = self.lookup(name)?;
        child.try_set_property_from_value(pspec.name(), value)
    }
}