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
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{prelude::*, subclass::prelude::*, translate::*};
use gst_rtsp::ffi::GstRTSPUrl;

use crate::{ffi, RTSPMountPoints};

pub trait RTSPMountPointsImpl: RTSPMountPointsImplExt + ObjectImpl + Send + Sync {
    /// Make a path string from `url`.
    /// ## `url`
    /// a [`gst_rtsp::RTSPUrl`][crate::gst_rtsp::RTSPUrl]
    ///
    /// # Returns
    ///
    /// a path string for `url`, `g_free()` after usage.
    fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
        self.parent_make_path(url)
    }
}

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

pub trait RTSPMountPointsImplExt: sealed::Sealed + ObjectSubclass {
    fn parent_make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMountPointsClass;
            let f = (*parent_class)
                .make_path
                .expect("No `make_path` virtual method implementation in parent class");
            from_glib_full(f(
                self.obj()
                    .unsafe_cast_ref::<RTSPMountPoints>()
                    .to_glib_none()
                    .0,
                url.to_glib_none().0,
            ))
        }
    }
}

impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T {}

unsafe impl<T: RTSPMountPointsImpl> IsSubclassable<T> for RTSPMountPoints {
    fn class_init(klass: &mut glib::Class<Self>) {
        Self::parent_class_init::<T>(klass);
        let klass = klass.as_mut();
        klass.make_path = Some(mount_points_make_path::<T>);
    }
}

unsafe extern "C" fn mount_points_make_path<T: RTSPMountPointsImpl>(
    ptr: *mut ffi::GstRTSPMountPoints,
    url: *const GstRTSPUrl,
) -> *mut std::os::raw::c_char {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.make_path(&from_glib_borrow(url)).into_glib_ptr()
}