gstreamer_rtsp_server/auto/
rtsp_session_pool.rs
1use 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")]
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 #[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
72pub trait RTSPSessionPoolExt: IsA<RTSPSessionPool> + sealed::Sealed + 'static {
78 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 {}