1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::{RTSPAddress, RTSPAddressFlags};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "GstRTSPAddressPool")]
    pub struct RTSPAddressPool(Object<ffi::GstRTSPAddressPool, ffi::GstRTSPAddressPoolClass>);

    match fn {
        type_ => || ffi::gst_rtsp_address_pool_get_type(),
    }
}

impl RTSPAddressPool {
    pub const NONE: Option<&'static RTSPAddressPool> = None;

    #[doc(alias = "gst_rtsp_address_pool_new")]
    pub fn new() -> RTSPAddressPool {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gst_rtsp_address_pool_new()) }
    }
}

impl Default for RTSPAddressPool {
    fn default() -> Self {
        Self::new()
    }
}

unsafe impl Send for RTSPAddressPool {}
unsafe impl Sync for RTSPAddressPool {}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::RTSPAddressPool>> Sealed for T {}
}

pub trait RTSPAddressPoolExt: IsA<RTSPAddressPool> + sealed::Sealed + 'static {
    #[doc(alias = "gst_rtsp_address_pool_acquire_address")]
    fn acquire_address(
        &self,
        flags: RTSPAddressFlags,
        n_ports: i32,
    ) -> Result<RTSPAddress, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_rtsp_address_pool_acquire_address(
                self.as_ref().to_glib_none().0,
                flags.into_glib(),
                n_ports,
            ))
            .ok_or_else(|| glib::bool_error!("Failed to acquire address"))
        }
    }

    #[doc(alias = "gst_rtsp_address_pool_add_range")]
    fn add_range(
        &self,
        min_address: &str,
        max_address: &str,
        min_port: u16,
        max_port: u16,
        ttl: u8,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_rtsp_address_pool_add_range(
                    self.as_ref().to_glib_none().0,
                    min_address.to_glib_none().0,
                    max_address.to_glib_none().0,
                    min_port,
                    max_port,
                    ttl
                ),
                "Failed to add address range"
            )
        }
    }

    #[doc(alias = "gst_rtsp_address_pool_clear")]
    fn clear(&self) {
        unsafe {
            ffi::gst_rtsp_address_pool_clear(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "gst_rtsp_address_pool_dump")]
    fn dump(&self) {
        unsafe {
            ffi::gst_rtsp_address_pool_dump(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "gst_rtsp_address_pool_has_unicast_addresses")]
    fn has_unicast_addresses(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_rtsp_address_pool_has_unicast_addresses(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExt for O {}