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    /// An object that keeps track of the active sessions. This object is usually
17    /// attached to a [`RTSPServer`][crate::RTSPServer] object to manage the sessions in that server.
18    ///
19    /// ## Properties
20    ///
21    ///
22    /// #### `max-sessions`
23    ///  Readable | Writeable
24    ///
25    /// ## Signals
26    ///
27    ///
28    /// #### `session-removed`
29    ///
30    ///
31    /// # Implements
32    ///
33    /// [`RTSPSessionPoolExt`][trait@crate::prelude::RTSPSessionPoolExt], [`trait@glib::ObjectExt`], [`RTSPSessionPoolExtManual`][trait@crate::prelude::RTSPSessionPoolExtManual]
34    #[doc(alias = "GstRTSPSessionPool")]
35    pub struct RTSPSessionPool(Object<ffi::GstRTSPSessionPool, ffi::GstRTSPSessionPoolClass>);
36
37    match fn {
38        type_ => || ffi::gst_rtsp_session_pool_get_type(),
39    }
40}
41
42impl RTSPSessionPool {
43    pub const NONE: Option<&'static RTSPSessionPool> = None;
44
45    /// Create a new [`RTSPSessionPool`][crate::RTSPSessionPool] instance.
46    ///
47    /// # Returns
48    ///
49    /// A new [`RTSPSessionPool`][crate::RTSPSessionPool]. `g_object_unref()` after
50    /// usage.
51    #[doc(alias = "gst_rtsp_session_pool_new")]
52    pub fn new() -> RTSPSessionPool {
53        assert_initialized_main_thread!();
54        unsafe { from_glib_full(ffi::gst_rtsp_session_pool_new()) }
55    }
56}
57
58impl Default for RTSPSessionPool {
59    fn default() -> Self {
60        Self::new()
61    }
62}
63
64unsafe impl Send for RTSPSessionPool {}
65unsafe impl Sync for RTSPSessionPool {}
66
67mod sealed {
68    pub trait Sealed {}
69    impl<T: super::IsA<super::RTSPSessionPool>> Sealed for T {}
70}
71
72/// Trait containing all [`struct@RTSPSessionPool`] methods.
73///
74/// # Implementors
75///
76/// [`RTSPSessionPool`][struct@crate::RTSPSessionPool]
77pub trait RTSPSessionPoolExt: IsA<RTSPSessionPool> + sealed::Sealed + 'static {
78    /// Inspect all the sessions in `self` and remove the sessions that are inactive
79    /// for more than their timeout.
80    ///
81    /// # Returns
82    ///
83    /// the amount of sessions that got removed.
84    #[doc(alias = "gst_rtsp_session_pool_cleanup")]
85    fn cleanup(&self) -> u32 {
86        unsafe { ffi::gst_rtsp_session_pool_cleanup(self.as_ref().to_glib_none().0) }
87    }
88
89    /// Create a new [`RTSPSession`][crate::RTSPSession] object in `self`.
90    ///
91    /// # Returns
92    ///
93    /// a new [`RTSPSession`][crate::RTSPSession].
94    #[doc(alias = "gst_rtsp_session_pool_create")]
95    fn create(&self) -> Result<RTSPSession, glib::BoolError> {
96        unsafe {
97            Option::<_>::from_glib_full(ffi::gst_rtsp_session_pool_create(
98                self.as_ref().to_glib_none().0,
99            ))
100            .ok_or_else(|| glib::bool_error!("Failed to create session pool"))
101        }
102    }
103
104    /// Call `func` for each session in `self`. The result value of `func` determines
105    /// what happens to the session. `func` will be called with the session pool
106    /// locked so no further actions on `self` can be performed from `func`.
107    ///
108    /// If `func` returns [`RTSPFilterResult::Remove`][crate::RTSPFilterResult::Remove], the session will be set to the
109    /// expired state and removed from `self`.
110    ///
111    /// If `func` returns [`RTSPFilterResult::Keep`][crate::RTSPFilterResult::Keep], the session will remain in `self`.
112    ///
113    /// If `func` returns [`RTSPFilterResult::Ref`][crate::RTSPFilterResult::Ref], the session will remain in `self` but
114    /// will also be added with an additional ref to the result GList of this
115    /// function..
116    ///
117    /// When `func` is [`None`], [`RTSPFilterResult::Ref`][crate::RTSPFilterResult::Ref] will be assumed for all sessions.
118    /// ## `func`
119    /// a callback
120    ///
121    /// # Returns
122    ///
123    /// a GList with all
124    /// sessions for which `func` returned [`RTSPFilterResult::Ref`][crate::RTSPFilterResult::Ref]. After usage, each
125    /// element in the GList should be unreffed before the list is freed.
126    #[doc(alias = "gst_rtsp_session_pool_filter")]
127    fn filter(
128        &self,
129        func: Option<&mut dyn (FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult)>,
130    ) -> Vec<RTSPSession> {
131        let mut func_data: Option<
132            &mut dyn (FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult),
133        > = func;
134        unsafe extern "C" fn func_func(
135            pool: *mut ffi::GstRTSPSessionPool,
136            session: *mut ffi::GstRTSPSession,
137            user_data: glib::ffi::gpointer,
138        ) -> ffi::GstRTSPFilterResult {
139            let pool = from_glib_borrow(pool);
140            let session = from_glib_borrow(session);
141            let callback = user_data
142                as *mut Option<
143                    &mut dyn (FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult),
144                >;
145            if let Some(ref mut callback) = *callback {
146                callback(&pool, &session)
147            } else {
148                panic!("cannot get closure...")
149            }
150            .into_glib()
151        }
152        let func = if func_data.is_some() {
153            Some(func_func as _)
154        } else {
155            None
156        };
157        let super_callback0: &mut Option<
158            &mut dyn (FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult),
159        > = &mut func_data;
160        unsafe {
161            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_session_pool_filter(
162                self.as_ref().to_glib_none().0,
163                func,
164                super_callback0 as *mut _ as *mut _,
165            ))
166        }
167    }
168
169    /// Find the session with `sessionid` in `self`. The access time of the session
170    /// will be updated with [`RTSPSessionExt::touch()`][crate::prelude::RTSPSessionExt::touch()].
171    /// ## `sessionid`
172    /// the session id
173    ///
174    /// # Returns
175    ///
176    /// the [`RTSPSession`][crate::RTSPSession] with `sessionid`
177    /// or [`None`] when the session did not exist. `g_object_unref()` after usage.
178    #[doc(alias = "gst_rtsp_session_pool_find")]
179    fn find(&self, sessionid: &str) -> Option<RTSPSession> {
180        unsafe {
181            from_glib_full(ffi::gst_rtsp_session_pool_find(
182                self.as_ref().to_glib_none().0,
183                sessionid.to_glib_none().0,
184            ))
185        }
186    }
187
188    /// Get the maximum allowed number of sessions in `self`. 0 means an unlimited
189    /// amount of sessions.
190    ///
191    /// # Returns
192    ///
193    /// the maximum allowed number of sessions.
194    #[doc(alias = "gst_rtsp_session_pool_get_max_sessions")]
195    #[doc(alias = "get_max_sessions")]
196    #[doc(alias = "max-sessions")]
197    fn max_sessions(&self) -> u32 {
198        unsafe { ffi::gst_rtsp_session_pool_get_max_sessions(self.as_ref().to_glib_none().0) }
199    }
200
201    /// Get the amount of active sessions in `self`.
202    ///
203    /// # Returns
204    ///
205    /// the amount of active sessions in `self`.
206    #[doc(alias = "gst_rtsp_session_pool_get_n_sessions")]
207    #[doc(alias = "get_n_sessions")]
208    fn n_sessions(&self) -> u32 {
209        unsafe { ffi::gst_rtsp_session_pool_get_n_sessions(self.as_ref().to_glib_none().0) }
210    }
211
212    /// Remove `sess` from `self`, releasing the ref that the pool has on `sess`.
213    /// ## `sess`
214    /// a [`RTSPSession`][crate::RTSPSession]
215    ///
216    /// # Returns
217    ///
218    /// [`true`] if the session was found and removed.
219    #[doc(alias = "gst_rtsp_session_pool_remove")]
220    fn remove(&self, sess: &impl IsA<RTSPSession>) -> Result<(), glib::error::BoolError> {
221        unsafe {
222            glib::result_from_gboolean!(
223                ffi::gst_rtsp_session_pool_remove(
224                    self.as_ref().to_glib_none().0,
225                    sess.as_ref().to_glib_none().0
226                ),
227                "Failed to remove session from pool"
228            )
229        }
230    }
231
232    /// Configure the maximum allowed number of sessions in `self` to `max`.
233    /// A value of 0 means an unlimited amount of sessions.
234    /// ## `max`
235    /// the maximum number of sessions
236    #[doc(alias = "gst_rtsp_session_pool_set_max_sessions")]
237    #[doc(alias = "max-sessions")]
238    fn set_max_sessions(&self, max: u32) {
239        unsafe {
240            ffi::gst_rtsp_session_pool_set_max_sessions(self.as_ref().to_glib_none().0, max);
241        }
242    }
243
244    #[doc(alias = "session-removed")]
245    fn connect_session_removed<F: Fn(&Self, &RTSPSession) + Send + Sync + 'static>(
246        &self,
247        f: F,
248    ) -> SignalHandlerId {
249        unsafe extern "C" fn session_removed_trampoline<
250            P: IsA<RTSPSessionPool>,
251            F: Fn(&P, &RTSPSession) + Send + Sync + 'static,
252        >(
253            this: *mut ffi::GstRTSPSessionPool,
254            object: *mut ffi::GstRTSPSession,
255            f: glib::ffi::gpointer,
256        ) {
257            let f: &F = &*(f as *const F);
258            f(
259                RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref(),
260                &from_glib_borrow(object),
261            )
262        }
263        unsafe {
264            let f: Box_<F> = Box_::new(f);
265            connect_raw(
266                self.as_ptr() as *mut _,
267                b"session-removed\0".as_ptr() as *const _,
268                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
269                    session_removed_trampoline::<Self, F> as *const (),
270                )),
271                Box_::into_raw(f),
272            )
273        }
274    }
275
276    #[doc(alias = "max-sessions")]
277    fn connect_max_sessions_notify<F: Fn(&Self) + Send + Sync + 'static>(
278        &self,
279        f: F,
280    ) -> SignalHandlerId {
281        unsafe extern "C" fn notify_max_sessions_trampoline<
282            P: IsA<RTSPSessionPool>,
283            F: Fn(&P) + Send + Sync + 'static,
284        >(
285            this: *mut ffi::GstRTSPSessionPool,
286            _param_spec: glib::ffi::gpointer,
287            f: glib::ffi::gpointer,
288        ) {
289            let f: &F = &*(f as *const F);
290            f(RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref())
291        }
292        unsafe {
293            let f: Box_<F> = Box_::new(f);
294            connect_raw(
295                self.as_ptr() as *mut _,
296                b"notify::max-sessions\0".as_ptr() as *const _,
297                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298                    notify_max_sessions_trampoline::<Self, F> as *const (),
299                )),
300                Box_::into_raw(f),
301            )
302        }
303    }
304}
305
306impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExt for O {}