gstreamer-rtsp-server 0.13.0

Rust bindings for GStreamer RTSP Server library
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use Error;
use RTSPAuth;
use RTSPClient;
use RTSPFilterResult;
use RTSPMountPoints;
use RTSPSessionPool;
use RTSPThreadPool;
use ffi;
use gio;
use glib;
use glib::GString;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_ffi;
use std::boxed::Box as Box_;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    pub struct RTSPServer(Object<ffi::GstRTSPServer, ffi::GstRTSPServerClass, RTSPServerClass>);

    match fn {
        get_type => || ffi::gst_rtsp_server_get_type(),
    }
}

impl RTSPServer {
    pub fn new() -> RTSPServer {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_new())
        }
    }

    pub fn io_func<P: IsA<gio::Socket>, Q: IsA<RTSPServer>>(socket: &P, condition: glib::IOCondition, server: &Q) -> Result<(), glib::error::BoolError> {
        skip_assert_initialized!();
        unsafe {
            glib_result_from_gboolean!(ffi::gst_rtsp_server_io_func(socket.as_ref().to_glib_none().0, condition.to_glib(), server.as_ref().to_glib_none().0), "Failed to connect the source")
        }
    }
}

impl Default for RTSPServer {
    fn default() -> Self {
        Self::new()
    }
}

unsafe impl Send for RTSPServer {}
unsafe impl Sync for RTSPServer {}

pub const NONE_RTSP_SERVER: Option<&RTSPServer> = None;

pub trait RTSPServerExt: 'static {
    fn client_filter(&self, func: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>) -> Vec<RTSPClient>;

    fn create_socket<'a, P: IsA<gio::Cancellable> + 'a, Q: Into<Option<&'a P>>>(&self, cancellable: Q) -> Result<gio::Socket, Error>;

    fn create_source<'a, P: IsA<gio::Cancellable> + 'a, Q: Into<Option<&'a P>>>(&self, cancellable: Q) -> Result<glib::Source, Error>;

    fn get_address(&self) -> Option<GString>;

    fn get_auth(&self) -> Option<RTSPAuth>;

    fn get_backlog(&self) -> i32;

    fn get_bound_port(&self) -> i32;

    fn get_mount_points(&self) -> Option<RTSPMountPoints>;

    fn get_service(&self) -> Option<GString>;

    fn get_session_pool(&self) -> Option<RTSPSessionPool>;

    fn get_thread_pool(&self) -> Option<RTSPThreadPool>;

    fn set_address(&self, address: &str);

    fn set_auth<'a, P: IsA<RTSPAuth> + 'a, Q: Into<Option<&'a P>>>(&self, auth: Q);

    fn set_backlog(&self, backlog: i32);

    fn set_mount_points<'a, P: IsA<RTSPMountPoints> + 'a, Q: Into<Option<&'a P>>>(&self, mounts: Q);

    fn set_service(&self, service: &str);

    fn set_session_pool<'a, P: IsA<RTSPSessionPool> + 'a, Q: Into<Option<&'a P>>>(&self, pool: Q);

    fn set_thread_pool<'a, P: IsA<RTSPThreadPool> + 'a, Q: Into<Option<&'a P>>>(&self, pool: Q);

    fn transfer_connection<'a, P: IsA<gio::Socket>, Q: Into<Option<&'a str>>>(&self, socket: &P, ip: &str, port: i32, initial_buffer: Q) -> Result<(), glib::error::BoolError>;

    fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_address_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_service_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<RTSPServer>> RTSPServerExt for O {
    fn client_filter(&self, func: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>) -> Vec<RTSPClient> {
        let func_data: Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)> = func;
        unsafe extern "C" fn func_func(server: *mut ffi::GstRTSPServer, client: *mut ffi::GstRTSPClient, user_data: glib_ffi::gpointer) -> ffi::GstRTSPFilterResult {
            let server = from_glib_borrow(server);
            let client = from_glib_borrow(client);
            let callback: *mut Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)> = user_data as *const _ as usize as *mut Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)>;
            let res = if let Some(ref mut callback) = *callback {
                callback(&server, &client)
            } else {
                panic!("cannot get closure...")
            };
            res.to_glib()
        }
        let func = Some(func_func as _);
        let super_callback0: &Option<&mut dyn (FnMut(&RTSPServer, &RTSPClient) -> RTSPFilterResult)> = &func_data;
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_server_client_filter(self.as_ref().to_glib_none().0, func, super_callback0 as *const _ as usize as *mut _))
        }
    }

    fn create_socket<'a, P: IsA<gio::Cancellable> + 'a, Q: Into<Option<&'a P>>>(&self, cancellable: Q) -> Result<gio::Socket, Error> {
        let cancellable = cancellable.into();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_rtsp_server_create_socket(self.as_ref().to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    fn create_source<'a, P: IsA<gio::Cancellable> + 'a, Q: Into<Option<&'a P>>>(&self, cancellable: Q) -> Result<glib::Source, Error> {
        let cancellable = cancellable.into();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_rtsp_server_create_source(self.as_ref().to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    fn get_address(&self) -> Option<GString> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_address(self.as_ref().to_glib_none().0))
        }
    }

    fn get_auth(&self) -> Option<RTSPAuth> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_auth(self.as_ref().to_glib_none().0))
        }
    }

    fn get_backlog(&self) -> i32 {
        unsafe {
            ffi::gst_rtsp_server_get_backlog(self.as_ref().to_glib_none().0)
        }
    }

    fn get_bound_port(&self) -> i32 {
        unsafe {
            ffi::gst_rtsp_server_get_bound_port(self.as_ref().to_glib_none().0)
        }
    }

    fn get_mount_points(&self) -> Option<RTSPMountPoints> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_mount_points(self.as_ref().to_glib_none().0))
        }
    }

    fn get_service(&self) -> Option<GString> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_service(self.as_ref().to_glib_none().0))
        }
    }

    fn get_session_pool(&self) -> Option<RTSPSessionPool> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_session_pool(self.as_ref().to_glib_none().0))
        }
    }

    fn get_thread_pool(&self) -> Option<RTSPThreadPool> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_thread_pool(self.as_ref().to_glib_none().0))
        }
    }

    fn set_address(&self, address: &str) {
        unsafe {
            ffi::gst_rtsp_server_set_address(self.as_ref().to_glib_none().0, address.to_glib_none().0);
        }
    }

    fn set_auth<'a, P: IsA<RTSPAuth> + 'a, Q: Into<Option<&'a P>>>(&self, auth: Q) {
        let auth = auth.into();
        unsafe {
            ffi::gst_rtsp_server_set_auth(self.as_ref().to_glib_none().0, auth.map(|p| p.as_ref()).to_glib_none().0);
        }
    }

    fn set_backlog(&self, backlog: i32) {
        unsafe {
            ffi::gst_rtsp_server_set_backlog(self.as_ref().to_glib_none().0, backlog);
        }
    }

    fn set_mount_points<'a, P: IsA<RTSPMountPoints> + 'a, Q: Into<Option<&'a P>>>(&self, mounts: Q) {
        let mounts = mounts.into();
        unsafe {
            ffi::gst_rtsp_server_set_mount_points(self.as_ref().to_glib_none().0, mounts.map(|p| p.as_ref()).to_glib_none().0);
        }
    }

    fn set_service(&self, service: &str) {
        unsafe {
            ffi::gst_rtsp_server_set_service(self.as_ref().to_glib_none().0, service.to_glib_none().0);
        }
    }

    fn set_session_pool<'a, P: IsA<RTSPSessionPool> + 'a, Q: Into<Option<&'a P>>>(&self, pool: Q) {
        let pool = pool.into();
        unsafe {
            ffi::gst_rtsp_server_set_session_pool(self.as_ref().to_glib_none().0, pool.map(|p| p.as_ref()).to_glib_none().0);
        }
    }

    fn set_thread_pool<'a, P: IsA<RTSPThreadPool> + 'a, Q: Into<Option<&'a P>>>(&self, pool: Q) {
        let pool = pool.into();
        unsafe {
            ffi::gst_rtsp_server_set_thread_pool(self.as_ref().to_glib_none().0, pool.map(|p| p.as_ref()).to_glib_none().0);
        }
    }

    fn transfer_connection<'a, P: IsA<gio::Socket>, Q: Into<Option<&'a str>>>(&self, socket: &P, ip: &str, port: i32, initial_buffer: Q) -> Result<(), glib::error::BoolError> {
        let initial_buffer = initial_buffer.into();
        unsafe {
            glib_result_from_gboolean!(ffi::gst_rtsp_server_transfer_connection(self.as_ref().to_glib_none().0, socket.as_ref().to_glib_full(), ip.to_glib_none().0, port, initial_buffer.to_glib_none().0), "Failed to transfer to the connection")
        }
    }

    fn connect_client_connected<F: Fn(&Self, &RTSPClient) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"client-connected\0".as_ptr() as *const _,
                Some(transmute(client_connected_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_address_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::address\0".as_ptr() as *const _,
                Some(transmute(notify_address_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_backlog_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::backlog\0".as_ptr() as *const _,
                Some(transmute(notify_backlog_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_bound_port_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::bound-port\0".as_ptr() as *const _,
                Some(transmute(notify_bound_port_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_mount_points_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::mount-points\0".as_ptr() as *const _,
                Some(transmute(notify_mount_points_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_service_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::service\0".as_ptr() as *const _,
                Some(transmute(notify_service_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_session_pool_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::session-pool\0".as_ptr() as *const _,
                Some(transmute(notify_session_pool_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }
}

unsafe extern "C" fn client_connected_trampoline<P, F: Fn(&P, &RTSPClient) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, object: *mut ffi::GstRTSPClient, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(object))
}

unsafe extern "C" fn notify_address_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast())
}

unsafe extern "C" fn notify_backlog_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast())
}

unsafe extern "C" fn notify_bound_port_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast())
}

unsafe extern "C" fn notify_mount_points_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast())
}

unsafe extern "C" fn notify_service_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast())
}

unsafe extern "C" fn notify_session_pool_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(this: *mut ffi::GstRTSPServer, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &F = &*(f as *const F);
    f(&RTSPServer::from_glib_borrow(this).unsafe_cast())
}