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
133unsafe impl Send for Scenario {}
134unsafe impl Sync for Scenario {}
135
136pub trait ScenarioExt: IsA<Scenario> + 'static {
142    #[doc(alias = "gst_validate_scenario_get_actions")]
153    #[doc(alias = "get_actions")]
154    fn actions(&self) -> Vec<Action> {
155        unsafe {
156            FromGlibPtrContainer::from_glib_full(ffi::gst_validate_scenario_get_actions(
157                self.as_ref().to_glib_none().0,
158            ))
159        }
160    }
161
162    #[doc(alias = "gst_validate_scenario_get_pipeline")]
168    #[doc(alias = "get_pipeline")]
169    fn pipeline(&self) -> Option<gst::Element> {
170        unsafe {
171            from_glib_full(ffi::gst_validate_scenario_get_pipeline(
172                self.as_ref().to_glib_none().0,
173            ))
174        }
175    }
176
177    #[doc(alias = "gst_validate_scenario_get_target_state")]
183    #[doc(alias = "get_target_state")]
184    fn target_state(&self) -> gst::State {
185        unsafe {
186            from_glib(ffi::gst_validate_scenario_get_target_state(
187                self.as_ref().to_glib_none().0,
188            ))
189        }
190    }
191
192    #[doc(alias = "execute-on-idle")]
193    fn is_execute_on_idle(&self) -> bool {
194        ObjectExt::property(self.as_ref(), "execute-on-idle")
195    }
196
197    #[doc(alias = "execute-on-idle")]
198    fn set_execute_on_idle(&self, execute_on_idle: bool) {
199        ObjectExt::set_property(self.as_ref(), "execute-on-idle", execute_on_idle)
200    }
201
202    #[doc(alias = "handles-states")]
203    fn is_handles_states(&self) -> bool {
204        ObjectExt::property(self.as_ref(), "handles-states")
205    }
206
207    #[doc(alias = "action-done")]
211    fn connect_action_done<F: Fn(&Self, &Action) + Send + Sync + 'static>(
212        &self,
213        f: F,
214    ) -> SignalHandlerId {
215        unsafe extern "C" fn action_done_trampoline<
216            P: IsA<Scenario>,
217            F: Fn(&P, &Action) + Send + Sync + 'static,
218        >(
219            this: *mut ffi::GstValidateScenario,
220            action: *mut ffi::GstValidateAction,
221            f: glib::ffi::gpointer,
222        ) {
223            let f: &F = &*(f as *const F);
224            f(
225                Scenario::from_glib_borrow(this).unsafe_cast_ref(),
226                &from_glib_borrow(action),
227            )
228        }
229        unsafe {
230            let f: Box_<F> = Box_::new(f);
231            connect_raw(
232                self.as_ptr() as *mut _,
233                c"action-done".as_ptr() as *const _,
234                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235                    action_done_trampoline::<Self, F> as *const (),
236                )),
237                Box_::into_raw(f),
238            )
239        }
240    }
241
242    #[doc(alias = "done")]
244    fn connect_done<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
245        unsafe extern "C" fn done_trampoline<
246            P: IsA<Scenario>,
247            F: Fn(&P) + Send + Sync + 'static,
248        >(
249            this: *mut ffi::GstValidateScenario,
250            f: glib::ffi::gpointer,
251        ) {
252            let f: &F = &*(f as *const F);
253            f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
254        }
255        unsafe {
256            let f: Box_<F> = Box_::new(f);
257            connect_raw(
258                self.as_ptr() as *mut _,
259                c"done".as_ptr() as *const _,
260                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261                    done_trampoline::<Self, F> as *const (),
262                )),
263                Box_::into_raw(f),
264            )
265        }
266    }
267
268    #[cfg(feature = "v1_26")]
270    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
271    #[doc(alias = "stopping")]
272    fn connect_stopping<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
273        unsafe extern "C" fn stopping_trampoline<
274            P: IsA<Scenario>,
275            F: Fn(&P) + Send + Sync + 'static,
276        >(
277            this: *mut ffi::GstValidateScenario,
278            f: glib::ffi::gpointer,
279        ) {
280            let f: &F = &*(f as *const F);
281            f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
282        }
283        unsafe {
284            let f: Box_<F> = Box_::new(f);
285            connect_raw(
286                self.as_ptr() as *mut _,
287                c"stopping".as_ptr() as *const _,
288                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289                    stopping_trampoline::<Self, F> as *const (),
290                )),
291                Box_::into_raw(f),
292            )
293        }
294    }
295
296    #[doc(alias = "execute-on-idle")]
297    fn connect_execute_on_idle_notify<F: Fn(&Self) + Send + Sync + 'static>(
298        &self,
299        f: F,
300    ) -> SignalHandlerId {
301        unsafe extern "C" fn notify_execute_on_idle_trampoline<
302            P: IsA<Scenario>,
303            F: Fn(&P) + Send + Sync + 'static,
304        >(
305            this: *mut ffi::GstValidateScenario,
306            _param_spec: glib::ffi::gpointer,
307            f: glib::ffi::gpointer,
308        ) {
309            let f: &F = &*(f as *const F);
310            f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
311        }
312        unsafe {
313            let f: Box_<F> = Box_::new(f);
314            connect_raw(
315                self.as_ptr() as *mut _,
316                c"notify::execute-on-idle".as_ptr() as *const _,
317                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
318                    notify_execute_on_idle_trampoline::<Self, F> as *const (),
319                )),
320                Box_::into_raw(f),
321            )
322        }
323    }
324
325    #[doc(alias = "handles-states")]
326    fn connect_handles_states_notify<F: Fn(&Self) + Send + Sync + 'static>(
327        &self,
328        f: F,
329    ) -> SignalHandlerId {
330        unsafe extern "C" fn notify_handles_states_trampoline<
331            P: IsA<Scenario>,
332            F: Fn(&P) + Send + Sync + 'static,
333        >(
334            this: *mut ffi::GstValidateScenario,
335            _param_spec: glib::ffi::gpointer,
336            f: glib::ffi::gpointer,
337        ) {
338            let f: &F = &*(f as *const F);
339            f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
340        }
341        unsafe {
342            let f: Box_<F> = Box_::new(f);
343            connect_raw(
344                self.as_ptr() as *mut _,
345                c"notify::handles-states".as_ptr() as *const _,
346                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
347                    notify_handles_states_trampoline::<Self, F> as *const (),
348                )),
349                Box_::into_raw(f),
350            )
351        }
352    }
353}
354
355impl<O: IsA<Scenario>> ScenarioExt for O {}