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