Skip to main content

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::{RTSPFilterResult, RTSPSession, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
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            unsafe {
73                let pool = from_glib_borrow(pool);
74                let session = from_glib_borrow(session);
75                let callback = user_data
76                    as *mut Option<
77                        &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
78                    >;
79                if let Some(ref mut callback) = *callback {
80                    callback(&pool, &session)
81                } else {
82                    panic!("cannot get closure...")
83                }
84                .into_glib()
85            }
86        }
87        let func = if func_data.is_some() {
88            Some(func_func as _)
89        } else {
90            None
91        };
92        let super_callback0: &mut Option<
93            &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
94        > = &mut func_data;
95        unsafe {
96            FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_session_pool_filter(
97                self.as_ref().to_glib_none().0,
98                func,
99                super_callback0 as *mut _ as *mut _,
100            ))
101        }
102    }
103
104    #[doc(alias = "gst_rtsp_session_pool_find")]
105    fn find(&self, sessionid: &str) -> Option<RTSPSession> {
106        unsafe {
107            from_glib_full(ffi::gst_rtsp_session_pool_find(
108                self.as_ref().to_glib_none().0,
109                sessionid.to_glib_none().0,
110            ))
111        }
112    }
113
114    #[doc(alias = "gst_rtsp_session_pool_get_max_sessions")]
115    #[doc(alias = "get_max_sessions")]
116    #[doc(alias = "max-sessions")]
117    fn max_sessions(&self) -> u32 {
118        unsafe { ffi::gst_rtsp_session_pool_get_max_sessions(self.as_ref().to_glib_none().0) }
119    }
120
121    #[doc(alias = "gst_rtsp_session_pool_get_n_sessions")]
122    #[doc(alias = "get_n_sessions")]
123    fn n_sessions(&self) -> u32 {
124        unsafe { ffi::gst_rtsp_session_pool_get_n_sessions(self.as_ref().to_glib_none().0) }
125    }
126
127    #[doc(alias = "gst_rtsp_session_pool_remove")]
128    fn remove(&self, sess: &impl IsA<RTSPSession>) -> Result<(), glib::error::BoolError> {
129        unsafe {
130            glib::result_from_gboolean!(
131                ffi::gst_rtsp_session_pool_remove(
132                    self.as_ref().to_glib_none().0,
133                    sess.as_ref().to_glib_none().0
134                ),
135                "Failed to remove session from pool"
136            )
137        }
138    }
139
140    #[doc(alias = "gst_rtsp_session_pool_set_max_sessions")]
141    #[doc(alias = "max-sessions")]
142    fn set_max_sessions(&self, max: u32) {
143        unsafe {
144            ffi::gst_rtsp_session_pool_set_max_sessions(self.as_ref().to_glib_none().0, max);
145        }
146    }
147
148    #[doc(alias = "session-removed")]
149    fn connect_session_removed<F: Fn(&Self, &RTSPSession) + Send + Sync + 'static>(
150        &self,
151        f: F,
152    ) -> SignalHandlerId {
153        unsafe extern "C" fn session_removed_trampoline<
154            P: IsA<RTSPSessionPool>,
155            F: Fn(&P, &RTSPSession) + Send + Sync + 'static,
156        >(
157            this: *mut ffi::GstRTSPSessionPool,
158            object: *mut ffi::GstRTSPSession,
159            f: glib::ffi::gpointer,
160        ) {
161            unsafe {
162                let f: &F = &*(f as *const F);
163                f(
164                    RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref(),
165                    &from_glib_borrow(object),
166                )
167            }
168        }
169        unsafe {
170            let f: Box_<F> = Box_::new(f);
171            connect_raw(
172                self.as_ptr() as *mut _,
173                c"session-removed".as_ptr(),
174                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175                    session_removed_trampoline::<Self, F> as *const (),
176                )),
177                Box_::into_raw(f),
178            )
179        }
180    }
181
182    #[doc(alias = "max-sessions")]
183    fn connect_max_sessions_notify<F: Fn(&Self) + Send + Sync + 'static>(
184        &self,
185        f: F,
186    ) -> SignalHandlerId {
187        unsafe extern "C" fn notify_max_sessions_trampoline<
188            P: IsA<RTSPSessionPool>,
189            F: Fn(&P) + Send + Sync + 'static,
190        >(
191            this: *mut ffi::GstRTSPSessionPool,
192            _param_spec: glib::ffi::gpointer,
193            f: glib::ffi::gpointer,
194        ) {
195            unsafe {
196                let f: &F = &*(f as *const F);
197                f(RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref())
198            }
199        }
200        unsafe {
201            let f: Box_<F> = Box_::new(f);
202            connect_raw(
203                self.as_ptr() as *mut _,
204                c"notify::max-sessions".as_ptr(),
205                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
206                    notify_max_sessions_trampoline::<Self, F> as *const (),
207                )),
208                Box_::into_raw(f),
209            )
210        }
211    }
212}
213
214impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExt for O {}