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")]
88 pub struct Scenario(Object<ffi::GstValidateScenario, ffi::GstValidateScenarioClass>) @extends gst::Object, @implements Reporter;
89
90 match fn {
91 type_ => || ffi::gst_validate_scenario_get_type(),
92 }
93}
94
95impl Scenario {
96 pub const NONE: Option<&'static Scenario> = None;
97
98 #[doc(alias = "gst_validate_scenario_deinit")]
99 pub fn deinit() {
100 assert_initialized_main_thread!();
101 unsafe {
102 ffi::gst_validate_scenario_deinit();
103 }
104 }
105
106 #[doc(alias = "gst_validate_scenario_factory_create")]
117 pub fn factory_create(
118 runner: &impl IsA<Runner>,
119 pipeline: &impl IsA<gst::Element>,
120 scenario_name: &str,
121 ) -> Option<Scenario> {
122 skip_assert_initialized!();
123 unsafe {
124 from_glib_full(ffi::gst_validate_scenario_factory_create(
125 runner.as_ref().to_glib_none().0,
126 pipeline.as_ref().to_glib_none().0,
127 scenario_name.to_glib_none().0,
128 ))
129 }
130 }
131}
132
133mod sealed {
134 pub trait Sealed {}
135 impl<T: super::IsA<super::Scenario>> Sealed for T {}
136}
137
138pub trait ScenarioExt: IsA<Scenario> + sealed::Sealed + 'static {
144 #[doc(alias = "gst_validate_scenario_get_actions")]
155 #[doc(alias = "get_actions")]
156 fn actions(&self) -> Vec<Action> {
157 unsafe {
158 FromGlibPtrContainer::from_glib_full(ffi::gst_validate_scenario_get_actions(
159 self.as_ref().to_glib_none().0,
160 ))
161 }
162 }
163
164 #[doc(alias = "gst_validate_scenario_get_pipeline")]
170 #[doc(alias = "get_pipeline")]
171 fn pipeline(&self) -> Option<gst::Element> {
172 unsafe {
173 from_glib_full(ffi::gst_validate_scenario_get_pipeline(
174 self.as_ref().to_glib_none().0,
175 ))
176 }
177 }
178
179 #[doc(alias = "gst_validate_scenario_get_target_state")]
185 #[doc(alias = "get_target_state")]
186 fn target_state(&self) -> gst::State {
187 unsafe {
188 from_glib(ffi::gst_validate_scenario_get_target_state(
189 self.as_ref().to_glib_none().0,
190 ))
191 }
192 }
193
194 #[doc(alias = "execute-on-idle")]
195 fn is_execute_on_idle(&self) -> bool {
196 ObjectExt::property(self.as_ref(), "execute-on-idle")
197 }
198
199 #[doc(alias = "execute-on-idle")]
200 fn set_execute_on_idle(&self, execute_on_idle: bool) {
201 ObjectExt::set_property(self.as_ref(), "execute-on-idle", execute_on_idle)
202 }
203
204 #[doc(alias = "handles-states")]
205 fn is_handles_states(&self) -> bool {
206 ObjectExt::property(self.as_ref(), "handles-states")
207 }
208
209 #[doc(alias = "action-done")]
213 fn connect_action_done<F: Fn(&Self, &Action) + 'static>(&self, f: F) -> SignalHandlerId {
214 unsafe extern "C" fn action_done_trampoline<
215 P: IsA<Scenario>,
216 F: Fn(&P, &Action) + 'static,
217 >(
218 this: *mut ffi::GstValidateScenario,
219 action: *mut ffi::GstValidateAction,
220 f: glib::ffi::gpointer,
221 ) {
222 let f: &F = &*(f as *const F);
223 f(
224 Scenario::from_glib_borrow(this).unsafe_cast_ref(),
225 &from_glib_borrow(action),
226 )
227 }
228 unsafe {
229 let f: Box_<F> = Box_::new(f);
230 connect_raw(
231 self.as_ptr() as *mut _,
232 b"action-done\0".as_ptr() as *const _,
233 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234 action_done_trampoline::<Self, F> as *const (),
235 )),
236 Box_::into_raw(f),
237 )
238 }
239 }
240
241 #[doc(alias = "done")]
243 fn connect_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244 unsafe extern "C" fn done_trampoline<P: IsA<Scenario>, F: Fn(&P) + 'static>(
245 this: *mut ffi::GstValidateScenario,
246 f: glib::ffi::gpointer,
247 ) {
248 let f: &F = &*(f as *const F);
249 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 connect_raw(
254 self.as_ptr() as *mut _,
255 b"done\0".as_ptr() as *const _,
256 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257 done_trampoline::<Self, F> as *const (),
258 )),
259 Box_::into_raw(f),
260 )
261 }
262 }
263
264 #[cfg(feature = "v1_26")]
266 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
267 #[doc(alias = "stopping")]
268 fn connect_stopping<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
269 unsafe extern "C" fn stopping_trampoline<P: IsA<Scenario>, F: Fn(&P) + 'static>(
270 this: *mut ffi::GstValidateScenario,
271 f: glib::ffi::gpointer,
272 ) {
273 let f: &F = &*(f as *const F);
274 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
275 }
276 unsafe {
277 let f: Box_<F> = Box_::new(f);
278 connect_raw(
279 self.as_ptr() as *mut _,
280 b"stopping\0".as_ptr() as *const _,
281 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
282 stopping_trampoline::<Self, F> as *const (),
283 )),
284 Box_::into_raw(f),
285 )
286 }
287 }
288
289 #[doc(alias = "execute-on-idle")]
290 fn connect_execute_on_idle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
291 unsafe extern "C" fn notify_execute_on_idle_trampoline<
292 P: IsA<Scenario>,
293 F: Fn(&P) + 'static,
294 >(
295 this: *mut ffi::GstValidateScenario,
296 _param_spec: glib::ffi::gpointer,
297 f: glib::ffi::gpointer,
298 ) {
299 let f: &F = &*(f as *const F);
300 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
301 }
302 unsafe {
303 let f: Box_<F> = Box_::new(f);
304 connect_raw(
305 self.as_ptr() as *mut _,
306 b"notify::execute-on-idle\0".as_ptr() as *const _,
307 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
308 notify_execute_on_idle_trampoline::<Self, F> as *const (),
309 )),
310 Box_::into_raw(f),
311 )
312 }
313 }
314
315 #[doc(alias = "handles-states")]
316 fn connect_handles_states_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
317 unsafe extern "C" fn notify_handles_states_trampoline<
318 P: IsA<Scenario>,
319 F: Fn(&P) + 'static,
320 >(
321 this: *mut ffi::GstValidateScenario,
322 _param_spec: glib::ffi::gpointer,
323 f: glib::ffi::gpointer,
324 ) {
325 let f: &F = &*(f as *const F);
326 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
327 }
328 unsafe {
329 let f: Box_<F> = Box_::new(f);
330 connect_raw(
331 self.as_ptr() as *mut _,
332 b"notify::handles-states\0".as_ptr() as *const _,
333 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
334 notify_handles_states_trampoline::<Self, F> as *const (),
335 )),
336 Box_::into_raw(f),
337 )
338 }
339 }
340}
341
342impl<O: IsA<Scenario>> ScenarioExt for O {}