1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::prelude::*;
use glib::translate::*;

use crate::{ffi, ActionType, Scenario};

gst::mini_object_wrapper!(Action, ActionRef, ffi::GstValidateAction, || {
    ffi::gst_validate_action_get_type()
});

impl ActionRef {
    pub fn structure(&self) -> &gst::StructureRef {
        unsafe {
            let action = &self.0 as *const ffi::GstValidateAction;

            gst::StructureRef::from_glib_borrow((*action).structure)
        }
    }

    pub fn structure_mut(&mut self) -> &mut gst::StructureRef {
        unsafe {
            let action = &mut self.0 as *mut ffi::GstValidateAction;

            gst::StructureRef::from_glib_borrow_mut((*action).structure)
        }
    }
}

impl Action {
    /// ## `scenario`
    /// The scenario executing the action
    /// ## `action_type`
    /// The action type
    /// ## `structure`
    /// The structure containing the action arguments
    /// ## `add_to_lists`
    /// Weather the action should be added to the scenario action list
    ///
    /// # Returns
    ///
    /// A newly created [`Action`][crate::Action]
    #[doc(alias = "gst_validate_action_new")]
    pub fn new(
        scenario: Option<&impl IsA<Scenario>>,
        action_type: &ActionType,
        structure: &gst::StructureRef,
        add_to_lists: bool,
    ) -> Action {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_validate_action_new(
                scenario.map(|p| p.as_ref()).to_glib_none().0,
                action_type.to_glib_none().0,
                structure.as_mut_ptr(),
                add_to_lists.into_glib(),
            ))
        }
    }

    #[doc(alias = "gst_validate_execute_action")]
    pub fn execute(&self) -> Result<crate::ActionSuccess, crate::ActionError> {
        unsafe {
            let action: *mut ffi::GstValidateAction = self.to_glib_none().0;
            let action_type = ffi::gst_validate_get_action_type((*action).type_);

            let res = ffi::gst_validate_execute_action(action_type, action);

            if let Some(v) = crate::ActionSuccess::from_value(res) {
                Ok(v)
            } else {
                Err(crate::ActionError::from_value(res))
            }
        }
    }
}