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<&mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult>;
138            if let Some(ref mut callback) = *callback {
139                callback(&pool, &session)
140            } else {
141                panic!("cannot get closure...")
142            }
143            .into_glib()
144        }
145        let func = if func_data.is_some() {
146            Some(func_func as _)
147        } else {
148            None
149        };
150        let super_callback0: &mut Option<
151            &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
152        > = &mut func_data;
153        unsafe {
154            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_session_pool_filter(
155                self.as_ref().to_glib_none().0,
156                func,
157                super_callback0 as *mut _ as *mut _,
158            ))
159        }
160    }
161
162    /// Find the session with `sessionid` in `self`. The access time of the session
163    /// will be updated with [`RTSPSessionExt::touch()`][crate::prelude::RTSPSessionExt::touch()].
164    /// ## `sessionid`
165    /// the session id
166    ///
167    /// # Returns
168    ///
169    /// the [`RTSPSession`][crate::RTSPSession] with `sessionid`
170    /// or [`None`] when the session did not exist. `g_object_unref()` after usage.
171    #[doc(alias = "gst_rtsp_session_pool_find")]
172    fn find(&self, sessionid: &str) -> Option<RTSPSession> {
173        unsafe {
174            from_glib_full(ffi::gst_rtsp_session_pool_find(
175                self.as_ref().to_glib_none().0,
176                sessionid.to_glib_none().0,
177            ))
178        }
179    }
180
181    /// Get the maximum allowed number of sessions in `self`. 0 means an unlimited
182    /// amount of sessions.
183    ///
184    /// # Returns
185    ///
186    /// the maximum allowed number of sessions.
187    #[doc(alias = "gst_rtsp_session_pool_get_max_sessions")]
188    #[doc(alias = "get_max_sessions")]
189    #[doc(alias = "max-sessions")]
190    fn max_sessions(&self) -> u32 {
191        unsafe { ffi::gst_rtsp_session_pool_get_max_sessions(self.as_ref().to_glib_none().0) }
192    }
193
194    /// Get the amount of active sessions in `self`.
195    ///
196    /// # Returns
197    ///
198    /// the amount of active sessions in `self`.
199    #[doc(alias = "gst_rtsp_session_pool_get_n_sessions")]
200    #[doc(alias = "get_n_sessions")]
201    fn n_sessions(&self) -> u32 {
202        unsafe { ffi::gst_rtsp_session_pool_get_n_sessions(self.as_ref().to_glib_none().0) }
203    }
204
205    /// Remove `sess` from `self`, releasing the ref that the pool has on `sess`.
206    /// ## `sess`
207    /// a [`RTSPSession`][crate::RTSPSession]
208    ///
209    /// # Returns
210    ///
211    /// [`true`] if the session was found and removed.
212    #[doc(alias = "gst_rtsp_session_pool_remove")]
213    fn remove(&self, sess: &impl IsA<RTSPSession>) -> Result<(), glib::error::BoolError> {
214        unsafe {
215            glib::result_from_gboolean!(
216                ffi::gst_rtsp_session_pool_remove(
217                    self.as_ref().to_glib_none().0,
218                    sess.as_ref().to_glib_none().0
219                ),
220                "Failed to remove session from pool"
221            )
222        }
223    }
224
225    /// Configure the maximum allowed number of sessions in `self` to `max`.
226    /// A value of 0 means an unlimited amount of sessions.
227    /// ## `max`
228    /// the maximum number of sessions
229    #[doc(alias = "gst_rtsp_session_pool_set_max_sessions")]
230    #[doc(alias = "max-sessions")]
231    fn set_max_sessions(&self, max: u32) {
232        unsafe {
233            ffi::gst_rtsp_session_pool_set_max_sessions(self.as_ref().to_glib_none().0, max);
234        }
235    }
236
237    #[doc(alias = "session-removed")]
238    fn connect_session_removed<F: Fn(&Self, &RTSPSession) + Send + Sync + 'static>(
239        &self,
240        f: F,
241    ) -> SignalHandlerId {
242        unsafe extern "C" fn session_removed_trampoline<
243            P: IsA<RTSPSessionPool>,
244            F: Fn(&P, &RTSPSession) + Send + Sync + 'static,
245        >(
246            this: *mut ffi::GstRTSPSessionPool,
247            object: *mut ffi::GstRTSPSession,
248            f: glib::ffi::gpointer,
249        ) {
250            let f: &F = &*(f as *const F);
251            f(
252                RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref(),
253                &from_glib_borrow(object),
254            )
255        }
256        unsafe {
257            let f: Box_<F> = Box_::new(f);
258            connect_raw(
259                self.as_ptr() as *mut _,
260                c"session-removed".as_ptr() as *const _,
261                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
262                    session_removed_trampoline::<Self, F> as *const (),
263                )),
264                Box_::into_raw(f),
265            )
266        }
267    }
268
269    #[doc(alias = "max-sessions")]
270    fn connect_max_sessions_notify<F: Fn(&Self) + Send + Sync + 'static>(
271        &self,
272        f: F,
273    ) -> SignalHandlerId {
274        unsafe extern "C" fn notify_max_sessions_trampoline<
275            P: IsA<RTSPSessionPool>,
276            F: Fn(&P) + Send + Sync + 'static,
277        >(
278            this: *mut ffi::GstRTSPSessionPool,
279            _param_spec: glib::ffi::gpointer,
280            f: glib::ffi::gpointer,
281        ) {
282            let f: &F = &*(f as *const F);
283            f(RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref())
284        }
285        unsafe {
286            let f: Box_<F> = Box_::new(f);
287            connect_raw(
288                self.as_ptr() as *mut _,
289                c"notify::max-sessions".as_ptr() as *const _,
290                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291                    notify_max_sessions_trampoline::<Self, F> as *const (),
292                )),
293                Box_::into_raw(f),
294            )
295        }
296    }
297}
298
299impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExt for O {}