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
69mod sealed {
70    pub trait Sealed {}
71    impl<T: super::IsA<super::RTSPThreadPool>> Sealed for T {}
72}
73
74/// Trait containing all [`struct@RTSPThreadPool`] methods.
75///
76/// # Implementors
77///
78/// [`RTSPThreadPool`][struct@crate::RTSPThreadPool]
79pub trait RTSPThreadPoolExt: IsA<RTSPThreadPool> + sealed::Sealed + 'static {
80    /// Get the maximum number of threads used for client connections.
81    /// See [`set_max_threads()`][Self::set_max_threads()].
82    ///
83    /// # Returns
84    ///
85    /// the maximum number of threads.
86    #[doc(alias = "gst_rtsp_thread_pool_get_max_threads")]
87    #[doc(alias = "get_max_threads")]
88    #[doc(alias = "max-threads")]
89    fn max_threads(&self) -> i32 {
90        unsafe { ffi::gst_rtsp_thread_pool_get_max_threads(self.as_ref().to_glib_none().0) }
91    }
92
93    /// Get a new [`RTSPThread`][crate::RTSPThread] for `type_` and `ctx`.
94    /// ## `type_`
95    /// the [`RTSPThreadType`][crate::RTSPThreadType]
96    /// ## `ctx`
97    /// a [`RTSPContext`][crate::RTSPContext]
98    ///
99    /// # Returns
100    ///
101    /// a new [`RTSPThread`][crate::RTSPThread],
102    /// `gst_rtsp_thread_stop()` after usage
103    #[doc(alias = "gst_rtsp_thread_pool_get_thread")]
104    #[doc(alias = "get_thread")]
105    fn thread(&self, type_: RTSPThreadType, ctx: &RTSPContext) -> Option<RTSPThread> {
106        unsafe {
107            from_glib_full(ffi::gst_rtsp_thread_pool_get_thread(
108                self.as_ref().to_glib_none().0,
109                type_.into_glib(),
110                ctx.to_glib_none().0,
111            ))
112        }
113    }
114
115    /// Set the maximum threads used by the pool to handle client requests.
116    /// A value of 0 will use the pool mainloop, a value of -1 will use an
117    /// unlimited number of threads.
118    /// ## `max_threads`
119    /// maximum threads
120    #[doc(alias = "gst_rtsp_thread_pool_set_max_threads")]
121    #[doc(alias = "max-threads")]
122    fn set_max_threads(&self, max_threads: i32) {
123        unsafe {
124            ffi::gst_rtsp_thread_pool_set_max_threads(self.as_ref().to_glib_none().0, max_threads);
125        }
126    }
127
128    #[doc(alias = "max-threads")]
129    fn connect_max_threads_notify<F: Fn(&Self) + Send + Sync + 'static>(
130        &self,
131        f: F,
132    ) -> SignalHandlerId {
133        unsafe extern "C" fn notify_max_threads_trampoline<
134            P: IsA<RTSPThreadPool>,
135            F: Fn(&P) + Send + Sync + 'static,
136        >(
137            this: *mut ffi::GstRTSPThreadPool,
138            _param_spec: glib::ffi::gpointer,
139            f: glib::ffi::gpointer,
140        ) {
141            let f: &F = &*(f as *const F);
142            f(RTSPThreadPool::from_glib_borrow(this).unsafe_cast_ref())
143        }
144        unsafe {
145            let f: Box_<F> = Box_::new(f);
146            connect_raw(
147                self.as_ptr() as *mut _,
148                b"notify::max-threads\0".as_ptr() as *const _,
149                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
150                    notify_max_threads_trampoline::<Self, F> as *const (),
151                )),
152                Box_::into_raw(f),
153            )
154        }
155    }
156}
157
158impl<O: IsA<RTSPThreadPool>> RTSPThreadPoolExt for O {}