1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use glib::{prelude::*, subclass::prelude::*, translate::*}; |
4 | |
5 | use crate::Navigation; |
6 | |
7 | pub trait NavigationImpl: ObjectImpl { |
8 | fn send_event(&self, structure: gst::Structure); |
9 | |
10 | #[cfg (feature = "v1_22" )] |
11 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
12 | fn send_event_simple(&self, event: gst::Event) { |
13 | if let Some(structure) = event.structure() { |
14 | self.send_event(structure.to_owned()); |
15 | } |
16 | } |
17 | } |
18 | |
19 | mod sealed { |
20 | pub trait Sealed {} |
21 | impl<T: super::NavigationImplExt> Sealed for T {} |
22 | } |
23 | |
24 | pub trait NavigationImplExt: sealed::Sealed + ObjectSubclass { |
25 | fn parent_send_event(&self, structure: gst::Structure) { |
26 | unsafe { |
27 | let type_data = Self::type_data(); |
28 | let parent_iface = type_data.as_ref().parent_interface::<Navigation>() |
29 | as *const ffi::GstNavigationInterface; |
30 | |
31 | let func = match (*parent_iface).send_event { |
32 | Some(func) => func, |
33 | None => return, |
34 | }; |
35 | |
36 | func( |
37 | self.obj().unsafe_cast_ref::<Navigation>().to_glib_none().0, |
38 | structure.into_glib_ptr(), |
39 | ); |
40 | } |
41 | } |
42 | |
43 | #[cfg (feature = "v1_22" )] |
44 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
45 | fn parent_send_event_simple(&self, event: gst::Event) { |
46 | unsafe { |
47 | let type_data = Self::type_data(); |
48 | let parent_iface = type_data.as_ref().parent_interface::<Navigation>() |
49 | as *const ffi::GstNavigationInterface; |
50 | |
51 | let func = match (*parent_iface).send_event_simple { |
52 | Some(func) => func, |
53 | None => return, |
54 | }; |
55 | |
56 | func( |
57 | self.obj().unsafe_cast_ref::<Navigation>().to_glib_none().0, |
58 | event.into_glib_ptr(), |
59 | ); |
60 | } |
61 | } |
62 | } |
63 | |
64 | impl<T: NavigationImpl> NavigationImplExt for T {} |
65 | |
66 | unsafe impl<T: NavigationImpl> IsImplementable<T> for Navigation { |
67 | #[cfg (not(any(feature = "v1_22" , docsrs)))] |
68 | fn interface_init(iface: &mut glib::Interface<Self>) { |
69 | let iface: &mut GstNavigationInterface = iface.as_mut(); |
70 | |
71 | iface.send_event = Some(navigation_send_event::<T>); |
72 | } |
73 | |
74 | #[cfg (feature = "v1_22" )] |
75 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
76 | fn interface_init(iface: &mut glib::Interface<Self>) { |
77 | let iface = iface.as_mut(); |
78 | |
79 | iface.send_event = Some(navigation_send_event::<T>); |
80 | iface.send_event_simple = Some(navigation_send_event_simple::<T>); |
81 | } |
82 | } |
83 | |
84 | unsafe extern "C" fn navigation_send_event<T: NavigationImpl>( |
85 | nav: *mut ffi::GstNavigation, |
86 | structure: *mut gst::ffi::GstStructure, |
87 | ) { |
88 | let instance: &::Instance = &*(nav as *mut T::Instance); |
89 | let imp: &T = instance.imp(); |
90 | |
91 | imp.send_event(structure:from_glib_full(ptr:structure)); |
92 | } |
93 | |
94 | #[cfg (feature = "v1_22" )] |
95 | #[cfg_attr (docsrs, doc(cfg(feature = "v1_22" )))] |
96 | unsafe extern "C" fn navigation_send_event_simple<T: NavigationImpl>( |
97 | nav: *mut ffi::GstNavigation, |
98 | event: *mut gst::ffi::GstEvent, |
99 | ) { |
100 | let instance = &*(nav as *mut T::Instance); |
101 | let imp = instance.imp(); |
102 | |
103 | imp.send_event_simple(from_glib_full(event)); |
104 | } |
105 | |