1 // Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8 
9 use glib;
10 use glib::object::IsA;
11 use glib::translate::*;
12 use gst_sys;
13 use std::ptr;
14 use ChildProxy;
15 
16 pub trait ChildProxyExtManual: 'static {
get_child_property(&self, name: &str) -> Option<glib::Value>17     fn get_child_property(&self, name: &str) -> Option<glib::Value>;
set_child_property( &self, name: &str, value: &dyn glib::ToValue, ) -> Result<(), glib::BoolError>18     fn set_child_property(
19         &self,
20         name: &str,
21         value: &dyn glib::ToValue,
22     ) -> Result<(), glib::BoolError>;
23 }
24 
25 impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
get_child_property(&self, name: &str) -> Option<glib::Value>26     fn get_child_property(&self, name: &str) -> Option<glib::Value> {
27         unsafe {
28             let found: bool = from_glib(gst_sys::gst_child_proxy_lookup(
29                 self.as_ref().to_glib_none().0,
30                 name.to_glib_none().0,
31                 ptr::null_mut(),
32                 ptr::null_mut(),
33             ));
34             if !found {
35                 return None;
36             }
37 
38             let mut value = glib::Value::uninitialized();
39             gst_sys::gst_child_proxy_get_property(
40                 self.as_ref().to_glib_none().0,
41                 name.to_glib_none().0,
42                 value.to_glib_none_mut().0,
43             );
44             Some(value)
45         }
46     }
47 
set_child_property( &self, name: &str, value: &dyn glib::ToValue, ) -> Result<(), glib::BoolError>48     fn set_child_property(
49         &self,
50         name: &str,
51         value: &dyn glib::ToValue,
52     ) -> Result<(), glib::BoolError> {
53         unsafe {
54             let found: bool = from_glib(gst_sys::gst_child_proxy_lookup(
55                 self.as_ref().to_glib_none().0,
56                 name.to_glib_none().0,
57                 ptr::null_mut(),
58                 ptr::null_mut(),
59             ));
60             if !found {
61                 return Err(glib_bool_error!("Child property not found"));
62             }
63 
64             let value = value.to_value();
65             gst_sys::gst_child_proxy_set_property(
66                 self.as_ref().to_glib_none().0,
67                 name.to_glib_none().0,
68                 value.to_glib_none().0,
69             );
70 
71             Ok(())
72         }
73     }
74 }
75