1use crate::{Action, Reporter, Runner, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
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 unsafe {
224 let f: &F = &*(f as *const F);
225 f(
226 Scenario::from_glib_borrow(this).unsafe_cast_ref(),
227 &from_glib_borrow(action),
228 )
229 }
230 }
231 unsafe {
232 let f: Box_<F> = Box_::new(f);
233 connect_raw(
234 self.as_ptr() as *mut _,
235 c"action-done".as_ptr(),
236 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
237 action_done_trampoline::<Self, F> as *const (),
238 )),
239 Box_::into_raw(f),
240 )
241 }
242 }
243
244 #[doc(alias = "done")]
246 fn connect_done<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
247 unsafe extern "C" fn done_trampoline<
248 P: IsA<Scenario>,
249 F: Fn(&P) + Send + Sync + 'static,
250 >(
251 this: *mut ffi::GstValidateScenario,
252 f: glib::ffi::gpointer,
253 ) {
254 unsafe {
255 let f: &F = &*(f as *const F);
256 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
257 }
258 }
259 unsafe {
260 let f: Box_<F> = Box_::new(f);
261 connect_raw(
262 self.as_ptr() as *mut _,
263 c"done".as_ptr(),
264 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265 done_trampoline::<Self, F> as *const (),
266 )),
267 Box_::into_raw(f),
268 )
269 }
270 }
271
272 #[cfg(feature = "v1_26")]
274 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
275 #[doc(alias = "stopping")]
276 fn connect_stopping<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
277 unsafe extern "C" fn stopping_trampoline<
278 P: IsA<Scenario>,
279 F: Fn(&P) + Send + Sync + 'static,
280 >(
281 this: *mut ffi::GstValidateScenario,
282 f: glib::ffi::gpointer,
283 ) {
284 unsafe {
285 let f: &F = &*(f as *const F);
286 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
287 }
288 }
289 unsafe {
290 let f: Box_<F> = Box_::new(f);
291 connect_raw(
292 self.as_ptr() as *mut _,
293 c"stopping".as_ptr(),
294 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
295 stopping_trampoline::<Self, F> as *const (),
296 )),
297 Box_::into_raw(f),
298 )
299 }
300 }
301
302 #[doc(alias = "execute-on-idle")]
303 fn connect_execute_on_idle_notify<F: Fn(&Self) + Send + Sync + 'static>(
304 &self,
305 f: F,
306 ) -> SignalHandlerId {
307 unsafe extern "C" fn notify_execute_on_idle_trampoline<
308 P: IsA<Scenario>,
309 F: Fn(&P) + Send + Sync + 'static,
310 >(
311 this: *mut ffi::GstValidateScenario,
312 _param_spec: glib::ffi::gpointer,
313 f: glib::ffi::gpointer,
314 ) {
315 unsafe {
316 let f: &F = &*(f as *const F);
317 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
318 }
319 }
320 unsafe {
321 let f: Box_<F> = Box_::new(f);
322 connect_raw(
323 self.as_ptr() as *mut _,
324 c"notify::execute-on-idle".as_ptr(),
325 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326 notify_execute_on_idle_trampoline::<Self, F> as *const (),
327 )),
328 Box_::into_raw(f),
329 )
330 }
331 }
332
333 #[doc(alias = "handles-states")]
334 fn connect_handles_states_notify<F: Fn(&Self) + Send + Sync + 'static>(
335 &self,
336 f: F,
337 ) -> SignalHandlerId {
338 unsafe extern "C" fn notify_handles_states_trampoline<
339 P: IsA<Scenario>,
340 F: Fn(&P) + Send + Sync + 'static,
341 >(
342 this: *mut ffi::GstValidateScenario,
343 _param_spec: glib::ffi::gpointer,
344 f: glib::ffi::gpointer,
345 ) {
346 unsafe {
347 let f: &F = &*(f as *const F);
348 f(Scenario::from_glib_borrow(this).unsafe_cast_ref())
349 }
350 }
351 unsafe {
352 let f: Box_<F> = Box_::new(f);
353 connect_raw(
354 self.as_ptr() as *mut _,
355 c"notify::handles-states".as_ptr(),
356 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
357 notify_handles_states_trampoline::<Self, F> as *const (),
358 )),
359 Box_::into_raw(f),
360 )
361 }
362 }
363}
364
365impl<O: IsA<Scenario>> ScenarioExt for O {}