1use crate::{ffi, Action, Reporter, Runner};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstValidateScenario")]
17 pub struct Scenario(Object<ffi::GstValidateScenario, ffi::GstValidateScenarioClass>) @extends gst::Object, @implements Reporter;
18
19 match fn {
20 type_ => || ffi::gst_validate_scenario_get_type(),
21 }
22}
23
24impl Scenario {
25 pub const NONE: Option<&'static Scenario> = None;
26
27 #[doc(alias = "gst_validate_scenario_deinit")]
28 pub fn deinit() {
29 assert_initialized_main_thread!();
30 unsafe {
31 ffi::gst_validate_scenario_deinit();
32 }
33 }
34
35 #[doc(alias = "gst_validate_scenario_factory_create")]
36 pub fn factory_create(
37 runner: &impl IsA<Runner>,
38 pipeline: &impl IsA<gst::Element>,
39 scenario_name: &str,
40 ) -> Option<Scenario> {
41 skip_assert_initialized!();
42 unsafe {
43 from_glib_full(ffi::gst_validate_scenario_factory_create(
44 runner.as_ref().to_glib_none().0,
45 pipeline.as_ref().to_glib_none().0,
46 scenario_name.to_glib_none().0,
47 ))
48 }
49 }
50}
51
52unsafe impl Send for Scenario {}
53unsafe impl Sync for Scenario {}
54
55pub trait ScenarioExt: IsA<Scenario> + 'static {
56 #[doc(alias = "gst_validate_scenario_get_actions")]
62 #[doc(alias = "get_actions")]
63 fn actions(&self) -> Vec<Action> {
64 unsafe {
65 FromGlibPtrContainer::from_glib_full(ffi::gst_validate_scenario_get_actions(
66 self.as_ref().to_glib_none().0,
67 ))
68 }
69 }
70
71 #[doc(alias = "gst_validate_scenario_get_pipeline")]
72 #[doc(alias = "get_pipeline")]
73 fn pipeline(&self) -> Option<gst::Element> {
74 unsafe {
75 from_glib_full(ffi::gst_validate_scenario_get_pipeline(
76 self.as_ref().to_glib_none().0,
77 ))
78 }
79 }
80
81 #[doc(alias = "gst_validate_scenario_get_target_state")]
82 #[doc(alias = "get_target_state")]
83 fn target_state(&self) -> gst::State {
84 unsafe {
85 from_glib(ffi::gst_validate_scenario_get_target_state(
86 self.as_ref().to_glib_none().0,
87 ))
88 }
89 }
90
91 #[doc(alias = "execute-on-idle")]
92 fn is_execute_on_idle(&self) -> bool {
93 ObjectExt::property(self.as_ref(), "execute-on-idle")
94 }
95
96 #[doc(alias = "execute-on-idle")]
97 fn set_execute_on_idle(&self, execute_on_idle: bool) {
98 ObjectExt::set_property(self.as_ref(), "execute-on-idle", execute_on_idle)
99 }
100
101 #[doc(alias = "handles-states")]
102 fn is_handles_states(&self) -> bool {
103 ObjectExt::property(self.as_ref(), "handles-states")
104 }
105
106 #[doc(alias = "action-done")]
107 fn connect_action_done<F: Fn(&Self, &Action) + Send + Sync + 'static>(
108 &self,
109 f: F,
110 ) -> SignalHandlerId {
111 unsafe extern "C" fn action_done_trampoline<
112 P: IsA<Scenario>,
113 F: Fn(&P, &Action) + Send + Sync + 'static,
114 >(
115 this: *mut ffi::GstValidateScenario,
116 action: *mut ffi::GstValidateAction,
117 f: glib::ffi::gpointer,
118 ) {
119 let f: &F = &*(f as *const F);
120 f(
121 Scenario::from_glib_borrow(this).unsafe_cast_ref(),
122 &from_glib_borrow(action),
123 )
124 }
125 unsafe {
126 let f: Box_<F> = Box_::new(f);
127 connect_raw(
128 self.as_ptr() as *mut _,
129 c"action-done".as_ptr() as *const _,
130 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
131 action_done_trampoline::<Self, F> as *const (),
132 )),
133 Box_::into_raw(f),
134 )
135 }
136 }
137
138 #[doc(alias = "done")]
139 fn connect_done<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
140 unsafe extern "C" fn done_trampoline<
141 P: IsA<Scenario>,
142 F: Fn(&P) + Send + Sync + 'static,
143 >(
144 this: *mut ffi::GstValidateScenario,
145 f: glib::ffi::gpointer,
146 ) {
147 let f: &F = &*(f as *const F);
148 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
149 }
150 unsafe {
151 let f: Box_<F> = Box_::new(f);
152 connect_raw(
153 self.as_ptr() as *mut _,
154 c"done".as_ptr() as *const _,
155 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
156 done_trampoline::<Self, F> as *const (),
157 )),
158 Box_::into_raw(f),
159 )
160 }
161 }
162
163 #[cfg(feature = "v1_26")]
164 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
165 #[doc(alias = "stopping")]
166 fn connect_stopping<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
167 unsafe extern "C" fn stopping_trampoline<
168 P: IsA<Scenario>,
169 F: Fn(&P) + Send + Sync + 'static,
170 >(
171 this: *mut ffi::GstValidateScenario,
172 f: glib::ffi::gpointer,
173 ) {
174 let f: &F = &*(f as *const F);
175 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
176 }
177 unsafe {
178 let f: Box_<F> = Box_::new(f);
179 connect_raw(
180 self.as_ptr() as *mut _,
181 c"stopping".as_ptr() as *const _,
182 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
183 stopping_trampoline::<Self, F> as *const (),
184 )),
185 Box_::into_raw(f),
186 )
187 }
188 }
189
190 #[doc(alias = "execute-on-idle")]
191 fn connect_execute_on_idle_notify<F: Fn(&Self) + Send + Sync + 'static>(
192 &self,
193 f: F,
194 ) -> SignalHandlerId {
195 unsafe extern "C" fn notify_execute_on_idle_trampoline<
196 P: IsA<Scenario>,
197 F: Fn(&P) + Send + Sync + 'static,
198 >(
199 this: *mut ffi::GstValidateScenario,
200 _param_spec: glib::ffi::gpointer,
201 f: glib::ffi::gpointer,
202 ) {
203 let f: &F = &*(f as *const F);
204 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
205 }
206 unsafe {
207 let f: Box_<F> = Box_::new(f);
208 connect_raw(
209 self.as_ptr() as *mut _,
210 c"notify::execute-on-idle".as_ptr() as *const _,
211 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
212 notify_execute_on_idle_trampoline::<Self, F> as *const (),
213 )),
214 Box_::into_raw(f),
215 )
216 }
217 }
218
219 #[doc(alias = "handles-states")]
220 fn connect_handles_states_notify<F: Fn(&Self) + Send + Sync + 'static>(
221 &self,
222 f: F,
223 ) -> SignalHandlerId {
224 unsafe extern "C" fn notify_handles_states_trampoline<
225 P: IsA<Scenario>,
226 F: Fn(&P) + Send + Sync + 'static,
227 >(
228 this: *mut ffi::GstValidateScenario,
229 _param_spec: glib::ffi::gpointer,
230 f: glib::ffi::gpointer,
231 ) {
232 let f: &F = &*(f as *const F);
233 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
234 }
235 unsafe {
236 let f: Box_<F> = Box_::new(f);
237 connect_raw(
238 self.as_ptr() as *mut _,
239 c"notify::handles-states".as_ptr() as *const _,
240 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241 notify_handles_states_trampoline::<Self, F> as *const (),
242 )),
243 Box_::into_raw(f),
244 )
245 }
246 }
247}
248
249impl<O: IsA<Scenario>> ScenarioExt for O {}