2018-02-09 02:30:08 +00:00
|
|
|
use glib;
|
|
|
|
use glib::object::IsA;
|
2018-06-24 11:44:38 +00:00
|
|
|
use glib::source::{Continue, Priority};
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib::translate::*;
|
2019-03-19 07:58:20 +00:00
|
|
|
use glib_sys;
|
|
|
|
use glib_sys::{gboolean, gpointer};
|
|
|
|
use gst_rtsp_server_sys;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::mem::transmute;
|
2018-04-25 08:10:06 +00:00
|
|
|
use RTSPSessionPool;
|
2018-02-09 02:30:08 +00:00
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(
|
2019-03-19 07:58:20 +00:00
|
|
|
pool: *mut gst_rtsp_server_sys::GstRTSPSessionPool,
|
2018-02-09 02:30:08 +00:00
|
|
|
func: gpointer,
|
|
|
|
) -> gboolean {
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &RefCell<F> = &*(func as *const RefCell<F>);
|
2018-02-09 02:30:08 +00:00
|
|
|
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
|
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn destroy_closure_watch<
|
|
|
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static,
|
|
|
|
>(
|
|
|
|
ptr: gpointer,
|
|
|
|
) {
|
|
|
|
Box::<RefCell<F>>::from_raw(ptr as *mut _);
|
2018-02-09 02:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn into_raw_watch<F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static>(func: F) -> gpointer {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2019-01-30 13:02:03 +00:00
|
|
|
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
|
2018-02-09 02:30:08 +00:00
|
|
|
Box::into_raw(func) as gpointer
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait RTSPSessionPoolExtManual: 'static {
|
2019-05-23 18:19:24 +00:00
|
|
|
fn create_watch<F>(&self, name: Option<&str>, priority: Priority, func: F) -> glib::Source
|
2018-02-09 02:30:08 +00:00
|
|
|
where
|
|
|
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExtManual for O {
|
2019-05-23 18:19:24 +00:00
|
|
|
fn create_watch<F>(&self, name: Option<&str>, priority: Priority, func: F) -> glib::Source
|
2018-02-09 02:30:08 +00:00
|
|
|
where
|
2018-02-22 10:18:37 +00:00
|
|
|
F: FnMut(&RTSPSessionPool) -> Continue + Send + 'static,
|
2018-02-09 02:30:08 +00:00
|
|
|
{
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
let source = gst_rtsp_server_sys::gst_rtsp_session_pool_create_watch(
|
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
);
|
|
|
|
glib_sys::g_source_set_callback(
|
2018-02-09 02:30:08 +00:00
|
|
|
source,
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(transmute(trampoline_watch::<F> as usize)),
|
2018-02-09 02:30:08 +00:00
|
|
|
into_raw_watch(func),
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(destroy_closure_watch::<F>),
|
2018-02-09 02:30:08 +00:00
|
|
|
);
|
2019-03-19 07:58:20 +00:00
|
|
|
glib_sys::g_source_set_priority(source, priority.to_glib());
|
2018-02-09 02:30:08 +00:00
|
|
|
|
|
|
|
if let Some(name) = name {
|
2019-03-19 07:58:20 +00:00
|
|
|
glib_sys::g_source_set_name(source, name.to_glib_none().0);
|
2018-02-09 02:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
from_glib_full(source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|