Use dedicated type DeviceMonitorFilterId

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/174
This commit is contained in:
François Laignel 2019-01-19 12:59:46 +01:00
parent a99652f236
commit 84ba2d7971
4 changed files with 86 additions and 24 deletions

View file

@ -547,6 +547,11 @@ status = "generate"
# Work-around for 1.14 switch from transfer-floating to transfer-full # Work-around for 1.14 switch from transfer-floating to transfer-full
ignore = true ignore = true
[[object.function]]
name = "add_filter"
# Return Option<DeviceMonitorFilterId>
ignore = true
[[object.function]] [[object.function]]
name = "get_bus" name = "get_bus"
[object.function.return] [object.function.return]
@ -559,8 +564,8 @@ status = "generate"
[[object.function]] [[object.function]]
name = "remove_filter" name = "remove_filter"
[object.function.return] # Use DeviceMonitorFilterId and return Result<(), glib::BoolError>
bool_return_is_error = "Failed to remove the filter" ignore = true
[[object]] [[object]]
name = "Gst.Device" name = "Gst.Device"

View file

@ -3,7 +3,6 @@
// DO NOT EDIT // DO NOT EDIT
use Bus; use Bus;
use Caps;
use Device; use Device;
use Object; use Object;
use ffi; use ffi;
@ -35,8 +34,6 @@ unsafe impl Sync for DeviceMonitor {}
pub const NONE_DEVICE_MONITOR: Option<&DeviceMonitor> = None; pub const NONE_DEVICE_MONITOR: Option<&DeviceMonitor> = None;
pub trait DeviceMonitorExt: 'static { pub trait DeviceMonitorExt: 'static {
fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, classes: P, caps: Q) -> u32;
fn get_bus(&self) -> Bus; fn get_bus(&self) -> Bus;
fn get_devices(&self) -> Vec<Device>; fn get_devices(&self) -> Vec<Device>;
@ -45,8 +42,6 @@ pub trait DeviceMonitorExt: 'static {
fn get_show_all_devices(&self) -> bool; fn get_show_all_devices(&self) -> bool;
fn remove_filter(&self, filter_id: u32) -> Result<(), glib::error::BoolError>;
fn set_show_all_devices(&self, show_all: bool); fn set_show_all_devices(&self, show_all: bool);
fn start(&self) -> Result<(), glib::error::BoolError>; fn start(&self) -> Result<(), glib::error::BoolError>;
@ -61,14 +56,6 @@ pub trait DeviceMonitorExt: 'static {
} }
impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O { impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O {
fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, classes: P, caps: Q) -> u32 {
let classes = classes.into();
let caps = caps.into();
unsafe {
ffi::gst_device_monitor_add_filter(self.as_ref().to_glib_none().0, classes.to_glib_none().0, caps.to_glib_none().0)
}
}
fn get_bus(&self) -> Bus { fn get_bus(&self) -> Bus {
unsafe { unsafe {
from_glib_full(ffi::gst_device_monitor_get_bus(self.as_ref().to_glib_none().0)) from_glib_full(ffi::gst_device_monitor_get_bus(self.as_ref().to_glib_none().0))
@ -93,12 +80,6 @@ impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O {
} }
} }
fn remove_filter(&self, filter_id: u32) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(ffi::gst_device_monitor_remove_filter(self.as_ref().to_glib_none().0, filter_id), "Failed to remove the filter")
}
}
fn set_show_all_devices(&self, show_all: bool) { fn set_show_all_devices(&self, show_all: bool) {
unsafe { unsafe {
ffi::gst_device_monitor_set_show_all_devices(self.as_ref().to_glib_none().0, show_all.to_glib()); ffi::gst_device_monitor_set_show_all_devices(self.as_ref().to_glib_none().0, show_all.to_glib());

View file

@ -1,4 +1,4 @@
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com> // Copyright (C) 2018-2019 Sebastian Dröge <sebastian@centricular.com>
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
@ -6,10 +6,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use ffi; use Caps;
use glib::translate::*;
use DeviceMonitor; use DeviceMonitor;
use glib;
use glib::object::IsA;
use glib::translate::*;
use ffi;
impl DeviceMonitor { impl DeviceMonitor {
pub fn new() -> DeviceMonitor { pub fn new() -> DeviceMonitor {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
@ -28,3 +33,72 @@ impl Default for DeviceMonitor {
Self::new() Self::new()
} }
} }
#[derive(Debug, PartialEq, Eq)]
pub struct DeviceMonitorFilterId(libc::c_uint);
impl ToGlib for DeviceMonitorFilterId {
type GlibType = libc::c_uint;
fn to_glib(&self) -> libc::c_uint {
self.0
}
}
impl FromGlib<libc::c_uint> for DeviceMonitorFilterId {
fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId {
skip_assert_initialized!();
assert_ne!(val, 0);
DeviceMonitorFilterId(val)
}
}
pub trait DeviceMonitorExtManual: 'static {
fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(
&self,
classes: P,
caps: Q,
) -> Option<DeviceMonitorFilterId>;
fn remove_filter(&self, filter_id: DeviceMonitorFilterId)
-> Result<(), glib::error::BoolError>;
}
impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {
fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(
&self,
classes: P,
caps: Q,
) -> Option<DeviceMonitorFilterId> {
let classes = classes.into();
let caps = caps.into();
let id = unsafe {
ffi::gst_device_monitor_add_filter(
self.as_ref().to_glib_none().0,
classes.to_glib_none().0,
caps.to_glib_none().0,
)
};
if id == 0 {
None
} else {
Some(from_glib(id))
}
}
fn remove_filter(
&self,
filter_id: DeviceMonitorFilterId,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(
ffi::gst_device_monitor_remove_filter(
self.as_ref().to_glib_none().0,
filter_id.to_glib()
),
"Failed to remove the filter"
)
}
}
}

View file

@ -210,6 +210,7 @@ pub use self::iterator::{Iterator, IteratorError, IteratorImpl};
pub use bus::BusStream; pub use bus::BusStream;
pub use child_proxy::ChildProxyExtManual; pub use child_proxy::ChildProxyExtManual;
pub use clock_time::ClockTime; pub use clock_time::ClockTime;
pub use device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId};
pub use device_provider::DeviceProviderExtManual; pub use device_provider::DeviceProviderExtManual;
pub use enums::{ pub use enums::{
ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess, ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess,
@ -324,6 +325,7 @@ pub mod prelude {
pub use buffer_pool::BufferPoolExtManual; pub use buffer_pool::BufferPoolExtManual;
pub use child_proxy::ChildProxyExtManual; pub use child_proxy::ChildProxyExtManual;
pub use clock::ClockExtManual; pub use clock::ClockExtManual;
pub use device_monitor::DeviceMonitorExtManual;
pub use device_provider::DeviceProviderExtManual; pub use device_provider::DeviceProviderExtManual;
pub use gobject::GObjectExtManualGst; pub use gobject::GObjectExtManualGst;
pub use object::GstObjectExtManual; pub use object::GstObjectExtManual;