gstreamer_rtsp_server/auto/
rtsp_thread_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::{ffi, RTSPContext, RTSPThread, RTSPThreadType};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// The thread pool structure.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `max-threads`
21    ///  Readable | Writeable
22    ///
23    /// # Implements
24    ///
25    /// [`RTSPThreadPoolExt`][trait@crate::prelude::RTSPThreadPoolExt], [`trait@glib::ObjectExt`]
26    #[doc(alias = "GstRTSPThreadPool")]
27    pub struct RTSPThreadPool(Object<ffi::GstRTSPThreadPool, ffi::GstRTSPThreadPoolClass>);
28
29    match fn {
30        type_ => || ffi::gst_rtsp_thread_pool_get_type(),
31    }
32}
33
34impl RTSPThreadPool {
35    pub const NONE: Option<&'static RTSPThreadPool> = None;
36
37    /// Create a new [`RTSPThreadPool`][crate::RTSPThreadPool] instance.
38    ///
39    /// # Returns
40    ///
41    /// a new [`RTSPThreadPool`][crate::RTSPThreadPool]
42    #[doc(alias = "gst_rtsp_thread_pool_new")]
43    pub fn new() -> RTSPThreadPool {
44        assert_initialized_main_thread!();
45        unsafe { from_glib_full(ffi::gst_rtsp_thread_pool_new()) }
46    }
47
48    /// Wait for all tasks to be stopped and free all allocated resources. This is
49    /// mainly used in test suites to ensure proper cleanup of internal data
50    /// structures.
51    #[doc(alias = "gst_rtsp_thread_pool_cleanup")]
52    pub fn cleanup() {
53        assert_initialized_main_thread!();
54        unsafe {
55            ffi::gst_rtsp_thread_pool_cleanup();
56        }
57    }
58}
59
60impl Default for RTSPThreadPool {
61    fn default() -> Self {
62        Self::new()
63    }
64}
65
66unsafe impl Send for RTSPThreadPool {}
67unsafe impl Sync for RTSPThreadPool {}
68
69/// Trait containing all [`struct@RTSPThreadPool`] methods.
70///
71/// # Implementors
72///
73/// [`RTSPThreadPool`][struct@crate::RTSPThreadPool]
74pub trait RTSPThreadPoolExt: IsA<RTSPThreadPool> + 'static {
75    /// Get the maximum number of threads used for client connections.
76    /// See [`set_max_threads()`][Self::set_max_threads()].
77    ///
78    /// # Returns
79    ///
80    /// the maximum number of threads.
81    #[doc(alias = "gst_rtsp_thread_pool_get_max_threads")]
82    #[doc(alias = "get_max_threads")]
83    #[doc(alias = "max-threads")]
84    fn max_threads(&self) -> i32 {
85        unsafe { ffi::gst_rtsp_thread_pool_get_max_threads(self.as_ref().to_glib_none().0) }
86    }
87
88    /// Get a new [`RTSPThread`][crate::RTSPThread] for `type_` and `ctx`.
89    /// ## `type_`
90    /// the [`RTSPThreadType`][crate::RTSPThreadType]
91    /// ## `ctx`
92    /// a [`RTSPContext`][crate::RTSPContext]
93    ///
94    /// # Returns
95    ///
96    /// a new [`RTSPThread`][crate::RTSPThread],
97    /// `gst_rtsp_thread_stop()` after usage
98    #[doc(alias = "gst_rtsp_thread_pool_get_thread")]
99    #[doc(alias = "get_thread")]
100    fn thread(&self, type_: RTSPThreadType, ctx: &RTSPContext) -> Option<RTSPThread> {
101        unsafe {
102            from_glib_full(ffi::gst_rtsp_thread_pool_get_thread(
103                self.as_ref().to_glib_none().0,
104                type_.into_glib(),
105                ctx.to_glib_none().0,
106            ))
107        }
108    }
109
110    /// Set the maximum threads used by the pool to handle client requests.
111    /// A value of 0 will use the pool mainloop, a value of -1 will use an
112    /// unlimited number of threads.
113    /// ## `max_threads`
114    /// maximum threads
115    #[doc(alias = "gst_rtsp_thread_pool_set_max_threads")]
116    #[doc(alias = "max-threads")]
117    fn set_max_threads(&self, max_threads: i32) {
118        unsafe {
119            ffi::gst_rtsp_thread_pool_set_max_threads(self.as_ref().to_glib_none().0, max_threads);
120        }
121    }
122
123    #[doc(alias = "max-threads")]
124    fn connect_max_threads_notify<F: Fn(&Self) + Send + Sync + 'static>(
125        &self,
126        f: F,
127    ) -> SignalHandlerId {
128        unsafe extern "C" fn notify_max_threads_trampoline<
129            P: IsA<RTSPThreadPool>,
130            F: Fn(&P) + Send + Sync + 'static,
131        >(
132            this: *mut ffi::GstRTSPThreadPool,
133            _param_spec: glib::ffi::gpointer,
134            f: glib::ffi::gpointer,
135        ) {
136            let f: &F = &*(f as *const F);
137            f(RTSPThreadPool::from_glib_borrow(this).unsafe_cast_ref())
138        }
139        unsafe {
140            let f: Box_<F> = Box_::new(f);
141            connect_raw(
142                self.as_ptr() as *mut _,
143                c"notify::max-threads".as_ptr() as *const _,
144                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
145                    notify_max_threads_trampoline::<Self, F> as *const (),
146                )),
147                Box_::into_raw(f),
148            )
149        }
150    }
151}
152
153impl<O: IsA<RTSPThreadPool>> RTSPThreadPoolExt for O {}