gstreamer_rtsp_server/auto/
rtsp_session_pool.rs1use 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
67pub trait RTSPSessionPoolExt: IsA<RTSPSessionPool> + 'static {
73 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 {}