gstreamer_rtsp_server/auto/
rtsp_session_pool.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, RTSPFilterResult, RTSPSession};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "GstRTSPSessionPool")]
17    pub struct RTSPSessionPool(Object<ffi::GstRTSPSessionPool, ffi::GstRTSPSessionPoolClass>);
18
19    match fn {
20        type_ => || ffi::gst_rtsp_session_pool_get_type(),
21    }
22}
23
24impl RTSPSessionPool {
25    pub const NONE: Option<&'static RTSPSessionPool> = None;
26
27    #[doc(alias = "gst_rtsp_session_pool_new")]
28    pub fn new() -> RTSPSessionPool {
29        assert_initialized_main_thread!();
30        unsafe { from_glib_full(ffi::gst_rtsp_session_pool_new()) }
31    }
32}
33
34impl Default for RTSPSessionPool {
35    fn default() -> Self {
36        Self::new()
37    }
38}
39
40unsafe impl Send for RTSPSessionPool {}
41unsafe impl Sync for RTSPSessionPool {}
42
43pub trait RTSPSessionPoolExt: IsA<RTSPSessionPool> + 'static {
44    #[doc(alias = "gst_rtsp_session_pool_cleanup")]
45    fn cleanup(&self) -> u32 {
46        unsafe { ffi::gst_rtsp_session_pool_cleanup(self.as_ref().to_glib_none().0) }
47    }
48
49    #[doc(alias = "gst_rtsp_session_pool_create")]
50    fn create(&self) -> Result<RTSPSession, glib::BoolError> {
51        unsafe {
52            Option::<_>::from_glib_full(ffi::gst_rtsp_session_pool_create(
53                self.as_ref().to_glib_none().0,
54            ))
55            .ok_or_else(|| glib::bool_error!("Failed to create session pool"))
56        }
57    }
58
59    #[doc(alias = "gst_rtsp_session_pool_filter")]
60    fn filter(
61        &self,
62        func: Option<&mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult>,
63    ) -> Vec<RTSPSession> {
64        let mut func_data: Option<
65            &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
66        > = func;
67        unsafe extern "C" fn func_func(
68            pool: *mut ffi::GstRTSPSessionPool,
69            session: *mut ffi::GstRTSPSession,
70            user_data: glib::ffi::gpointer,
71        ) -> ffi::GstRTSPFilterResult {
72            let pool = from_glib_borrow(pool);
73            let session = from_glib_borrow(session);
74            let callback = user_data
75                as *mut Option<&mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult>;
76            if let Some(ref mut callback) = *callback {
77                callback(&pool, &session)
78            } else {
79                panic!("cannot get closure...")
80            }
81            .into_glib()
82        }
83        let func = if func_data.is_some() {
84            Some(func_func as _)
85        } else {
86            None
87        };
88        let super_callback0: &mut Option<
89            &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
90        > = &mut func_data;
91        unsafe {
92            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_session_pool_filter(
93                self.as_ref().to_glib_none().0,
94                func,
95                super_callback0 as *mut _ as *mut _,
96            ))
97        }
98    }
99
100    #[doc(alias = "gst_rtsp_session_pool_find")]
101    fn find(&self, sessionid: &str) -> Option<RTSPSession> {
102        unsafe {
103            from_glib_full(ffi::gst_rtsp_session_pool_find(
104                self.as_ref().to_glib_none().0,
105                sessionid.to_glib_none().0,
106            ))
107        }
108    }
109
110    #[doc(alias = "gst_rtsp_session_pool_get_max_sessions")]
111    #[doc(alias = "get_max_sessions")]
112    #[doc(alias = "max-sessions")]
113    fn max_sessions(&self) -> u32 {
114        unsafe { ffi::gst_rtsp_session_pool_get_max_sessions(self.as_ref().to_glib_none().0) }
115    }
116
117    #[doc(alias = "gst_rtsp_session_pool_get_n_sessions")]
118    #[doc(alias = "get_n_sessions")]
119    fn n_sessions(&self) -> u32 {
120        unsafe { ffi::gst_rtsp_session_pool_get_n_sessions(self.as_ref().to_glib_none().0) }
121    }
122
123    #[doc(alias = "gst_rtsp_session_pool_remove")]
124    fn remove(&self, sess: &impl IsA<RTSPSession>) -> Result<(), glib::error::BoolError> {
125        unsafe {
126            glib::result_from_gboolean!(
127                ffi::gst_rtsp_session_pool_remove(
128                    self.as_ref().to_glib_none().0,
129                    sess.as_ref().to_glib_none().0
130                ),
131                "Failed to remove session from pool"
132            )
133        }
134    }
135
136    #[doc(alias = "gst_rtsp_session_pool_set_max_sessions")]
137    #[doc(alias = "max-sessions")]
138    fn set_max_sessions(&self, max: u32) {
139        unsafe {
140            ffi::gst_rtsp_session_pool_set_max_sessions(self.as_ref().to_glib_none().0, max);
141        }
142    }
143
144    #[doc(alias = "session-removed")]
145    fn connect_session_removed<F: Fn(&Self, &RTSPSession) + Send + Sync + 'static>(
146        &self,
147        f: F,
148    ) -> SignalHandlerId {
149        unsafe extern "C" fn session_removed_trampoline<
150            P: IsA<RTSPSessionPool>,
151            F: Fn(&P, &RTSPSession) + Send + Sync + 'static,
152        >(
153            this: *mut ffi::GstRTSPSessionPool,
154            object: *mut ffi::GstRTSPSession,
155            f: glib::ffi::gpointer,
156        ) {
157            let f: &F = &*(f as *const F);
158            f(
159                RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref(),
160                &from_glib_borrow(object),
161            )
162        }
163        unsafe {
164            let f: Box_<F> = Box_::new(f);
165            connect_raw(
166                self.as_ptr() as *mut _,
167                c"session-removed".as_ptr() as *const _,
168                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
169                    session_removed_trampoline::<Self, F> as *const (),
170                )),
171                Box_::into_raw(f),
172            )
173        }
174    }
175
176    #[doc(alias = "max-sessions")]
177    fn connect_max_sessions_notify<F: Fn(&Self) + Send + Sync + 'static>(
178        &self,
179        f: F,
180    ) -> SignalHandlerId {
181        unsafe extern "C" fn notify_max_sessions_trampoline<
182            P: IsA<RTSPSessionPool>,
183            F: Fn(&P) + Send + Sync + 'static,
184        >(
185            this: *mut ffi::GstRTSPSessionPool,
186            _param_spec: glib::ffi::gpointer,
187            f: glib::ffi::gpointer,
188        ) {
189            let f: &F = &*(f as *const F);
190            f(RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref())
191        }
192        unsafe {
193            let f: Box_<F> = Box_::new(f);
194            connect_raw(
195                self.as_ptr() as *mut _,
196                c"notify::max-sessions".as_ptr() as *const _,
197                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
198                    notify_max_sessions_trampoline::<Self, F> as *const (),
199                )),
200                Box_::into_raw(f),
201            )
202        }
203    }
204}
205
206impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExt for O {}