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