gstreamer_rtsp_server/auto/
rtsp_session_pool.rs1use 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")]
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 unsafe {
135 let pool = from_glib_borrow(pool);
136 let session = from_glib_borrow(session);
137 let callback = user_data
138 as *mut Option<
139 &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
140 >;
141 if let Some(ref mut callback) = *callback {
142 callback(&pool, &session)
143 } else {
144 panic!("cannot get closure...")
145 }
146 .into_glib()
147 }
148 }
149 let func = if func_data.is_some() {
150 Some(func_func as _)
151 } else {
152 None
153 };
154 let super_callback0: &mut Option<
155 &mut dyn FnMut(&RTSPSessionPool, &RTSPSession) -> RTSPFilterResult,
156 > = &mut func_data;
157 unsafe {
158 FromGlibPtrContainer::from_glib_full(ffi::gst_rtsp_session_pool_filter(
159 self.as_ref().to_glib_none().0,
160 func,
161 super_callback0 as *mut _ as *mut _,
162 ))
163 }
164 }
165
166 #[doc(alias = "gst_rtsp_session_pool_find")]
176 fn find(&self, sessionid: &str) -> Option<RTSPSession> {
177 unsafe {
178 from_glib_full(ffi::gst_rtsp_session_pool_find(
179 self.as_ref().to_glib_none().0,
180 sessionid.to_glib_none().0,
181 ))
182 }
183 }
184
185 #[doc(alias = "gst_rtsp_session_pool_get_max_sessions")]
192 #[doc(alias = "get_max_sessions")]
193 #[doc(alias = "max-sessions")]
194 fn max_sessions(&self) -> u32 {
195 unsafe { ffi::gst_rtsp_session_pool_get_max_sessions(self.as_ref().to_glib_none().0) }
196 }
197
198 #[doc(alias = "gst_rtsp_session_pool_get_n_sessions")]
204 #[doc(alias = "get_n_sessions")]
205 fn n_sessions(&self) -> u32 {
206 unsafe { ffi::gst_rtsp_session_pool_get_n_sessions(self.as_ref().to_glib_none().0) }
207 }
208
209 #[doc(alias = "gst_rtsp_session_pool_remove")]
217 fn remove(&self, sess: &impl IsA<RTSPSession>) -> Result<(), glib::error::BoolError> {
218 unsafe {
219 glib::result_from_gboolean!(
220 ffi::gst_rtsp_session_pool_remove(
221 self.as_ref().to_glib_none().0,
222 sess.as_ref().to_glib_none().0
223 ),
224 "Failed to remove session from pool"
225 )
226 }
227 }
228
229 #[doc(alias = "gst_rtsp_session_pool_set_max_sessions")]
234 #[doc(alias = "max-sessions")]
235 fn set_max_sessions(&self, max: u32) {
236 unsafe {
237 ffi::gst_rtsp_session_pool_set_max_sessions(self.as_ref().to_glib_none().0, max);
238 }
239 }
240
241 #[doc(alias = "session-removed")]
242 fn connect_session_removed<F: Fn(&Self, &RTSPSession) + Send + Sync + 'static>(
243 &self,
244 f: F,
245 ) -> SignalHandlerId {
246 unsafe extern "C" fn session_removed_trampoline<
247 P: IsA<RTSPSessionPool>,
248 F: Fn(&P, &RTSPSession) + Send + Sync + 'static,
249 >(
250 this: *mut ffi::GstRTSPSessionPool,
251 object: *mut ffi::GstRTSPSession,
252 f: glib::ffi::gpointer,
253 ) {
254 unsafe {
255 let f: &F = &*(f as *const F);
256 f(
257 RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref(),
258 &from_glib_borrow(object),
259 )
260 }
261 }
262 unsafe {
263 let f: Box_<F> = Box_::new(f);
264 connect_raw(
265 self.as_ptr() as *mut _,
266 c"session-removed".as_ptr(),
267 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268 session_removed_trampoline::<Self, F> as *const (),
269 )),
270 Box_::into_raw(f),
271 )
272 }
273 }
274
275 #[doc(alias = "max-sessions")]
276 fn connect_max_sessions_notify<F: Fn(&Self) + Send + Sync + 'static>(
277 &self,
278 f: F,
279 ) -> SignalHandlerId {
280 unsafe extern "C" fn notify_max_sessions_trampoline<
281 P: IsA<RTSPSessionPool>,
282 F: Fn(&P) + Send + Sync + 'static,
283 >(
284 this: *mut ffi::GstRTSPSessionPool,
285 _param_spec: glib::ffi::gpointer,
286 f: glib::ffi::gpointer,
287 ) {
288 unsafe {
289 let f: &F = &*(f as *const F);
290 f(RTSPSessionPool::from_glib_borrow(this).unsafe_cast_ref())
291 }
292 }
293 unsafe {
294 let f: Box_<F> = Box_::new(f);
295 connect_raw(
296 self.as_ptr() as *mut _,
297 c"notify::max-sessions".as_ptr(),
298 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299 notify_max_sessions_trampoline::<Self, F> as *const (),
300 )),
301 Box_::into_raw(f),
302 )
303 }
304 }
305}
306
307impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExt for O {}