use ClockTime;
use Error;
use ffi;
use glib;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;
glib_wrapper! {
pub struct Object(Object<ffi::GstObject, ffi::GstObjectClass>);
match fn {
get_type => || ffi::gst_object_get_type(),
}
}
impl Object {
pub fn check_uniqueness(list: &[Object], name: &str) -> bool {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::gst_object_check_uniqueness(list.to_glib_none().0, name.to_glib_none().0))
}
}
}
unsafe impl Send for Object {}
unsafe impl Sync for Object {}
pub trait GstObjectExt {
fn default_error<'a, P: Into<Option<&'a str>>>(&self, error: &Error, debug: P);
fn get_control_rate(&self) -> ClockTime;
fn get_name(&self) -> String;
fn get_parent(&self) -> Option<Object>;
fn get_path_string(&self) -> String;
fn has_active_control_bindings(&self) -> bool;
fn has_ancestor<P: IsA<Object>>(&self, ancestor: &P) -> bool;
fn has_as_ancestor<P: IsA<Object>>(&self, ancestor: &P) -> bool;
fn has_as_parent<P: IsA<Object>>(&self, parent: &P) -> bool;
fn set_control_binding_disabled(&self, property_name: &str, disabled: bool);
fn set_control_bindings_disabled(&self, disabled: bool);
fn set_control_rate(&self, control_rate: ClockTime);
fn set_name(&self, name: &str) -> Result<(), glib::error::BoolError>;
fn set_parent<P: IsA<Object>>(&self, parent: &P) -> Result<(), glib::error::BoolError>;
fn suggest_next_sync(&self) -> ClockTime;
fn sync_values(&self, timestamp: ClockTime) -> Result<(), glib::error::BoolError>;
fn unparent(&self);
fn connect_property_name_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_parent_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Object> + IsA<glib::object::Object>> GstObjectExt for O {
fn default_error<'a, P: Into<Option<&'a str>>>(&self, error: &Error, debug: P) {
let debug = debug.into();
let debug = debug.to_glib_none();
unsafe {
ffi::gst_object_default_error(self.to_glib_none().0, error.to_glib_none().0, debug.0);
}
}
fn get_control_rate(&self) -> ClockTime {
unsafe {
from_glib(ffi::gst_object_get_control_rate(self.to_glib_none().0))
}
}
fn get_name(&self) -> String {
unsafe {
from_glib_full(ffi::gst_object_get_name(self.to_glib_none().0))
}
}
fn get_parent(&self) -> Option<Object> {
unsafe {
from_glib_full(ffi::gst_object_get_parent(self.to_glib_none().0))
}
}
fn get_path_string(&self) -> String {
unsafe {
from_glib_full(ffi::gst_object_get_path_string(self.to_glib_none().0))
}
}
fn has_active_control_bindings(&self) -> bool {
unsafe {
from_glib(ffi::gst_object_has_active_control_bindings(self.to_glib_none().0))
}
}
fn has_ancestor<P: IsA<Object>>(&self, ancestor: &P) -> bool {
unsafe {
from_glib(ffi::gst_object_has_ancestor(self.to_glib_none().0, ancestor.to_glib_none().0))
}
}
fn has_as_ancestor<P: IsA<Object>>(&self, ancestor: &P) -> bool {
unsafe {
from_glib(ffi::gst_object_has_as_ancestor(self.to_glib_none().0, ancestor.to_glib_none().0))
}
}
fn has_as_parent<P: IsA<Object>>(&self, parent: &P) -> bool {
unsafe {
from_glib(ffi::gst_object_has_as_parent(self.to_glib_none().0, parent.to_glib_none().0))
}
}
fn set_control_binding_disabled(&self, property_name: &str, disabled: bool) {
unsafe {
ffi::gst_object_set_control_binding_disabled(self.to_glib_none().0, property_name.to_glib_none().0, disabled.to_glib());
}
}
fn set_control_bindings_disabled(&self, disabled: bool) {
unsafe {
ffi::gst_object_set_control_bindings_disabled(self.to_glib_none().0, disabled.to_glib());
}
}
fn set_control_rate(&self, control_rate: ClockTime) {
unsafe {
ffi::gst_object_set_control_rate(self.to_glib_none().0, control_rate.to_glib());
}
}
fn set_name(&self, name: &str) -> Result<(), glib::error::BoolError> {
unsafe {
glib::error::BoolError::from_glib(ffi::gst_object_set_name(self.to_glib_none().0, name.to_glib_none().0), "Failed to set object name")
}
}
fn set_parent<P: IsA<Object>>(&self, parent: &P) -> Result<(), glib::error::BoolError> {
unsafe {
glib::error::BoolError::from_glib(ffi::gst_object_set_parent(self.to_glib_none().0, parent.to_glib_none().0), "Failed to set parent object")
}
}
fn suggest_next_sync(&self) -> ClockTime {
unsafe {
from_glib(ffi::gst_object_suggest_next_sync(self.to_glib_none().0))
}
}
fn sync_values(&self, timestamp: ClockTime) -> Result<(), glib::error::BoolError> {
unsafe {
glib::error::BoolError::from_glib(ffi::gst_object_sync_values(self.to_glib_none().0, timestamp.to_glib()), "Failed to sync values")
}
}
fn unparent(&self) {
unsafe {
ffi::gst_object_unparent(self.to_glib_none().0);
}
}
fn connect_property_name_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::name",
transmute(notify_name_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
fn connect_property_parent_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::parent",
transmute(notify_parent_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn notify_name_trampoline<P>(this: *mut ffi::GstObject, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Object> {
let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
f(&Object::from_glib_borrow(this).downcast_unchecked())
}
unsafe extern "C" fn notify_parent_trampoline<P>(this: *mut ffi::GstObject, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Object> {
let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
f(&Object::from_glib_borrow(this).downcast_unchecked())
}