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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::{Object, TaskPool, TaskState};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "GstTask")]
    pub struct Task(Object<ffi::GstTask, ffi::GstTaskClass>) @extends Object;

    match fn {
        type_ => || ffi::gst_task_get_type(),
    }
}

impl Task {
    pub const NONE: Option<&'static Task> = None;

    #[doc(alias = "gst_task_cleanup_all")]
    pub fn cleanup_all() {
        assert_initialized_main_thread!();
        unsafe {
            ffi::gst_task_cleanup_all();
        }
    }
}

unsafe impl Send for Task {}
unsafe impl Sync for Task {}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Task>> Sealed for T {}
}

pub trait TaskExt: IsA<Task> + sealed::Sealed + 'static {
    #[doc(alias = "gst_task_get_pool")]
    #[doc(alias = "get_pool")]
    fn pool(&self) -> TaskPool {
        unsafe { from_glib_full(ffi::gst_task_get_pool(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "gst_task_get_state")]
    #[doc(alias = "get_state")]
    fn state(&self) -> TaskState {
        unsafe { from_glib(ffi::gst_task_get_state(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "gst_task_join")]
    fn join(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_task_join(self.as_ref().to_glib_none().0),
                "Failed to join task"
            )
        }
    }

    #[doc(alias = "gst_task_pause")]
    fn pause(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_task_pause(self.as_ref().to_glib_none().0),
                "Failed to pause task"
            )
        }
    }

    #[cfg(feature = "v1_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
    #[doc(alias = "gst_task_resume")]
    fn resume(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_task_resume(self.as_ref().to_glib_none().0),
                "Failed to resume task"
            )
        }
    }

    #[doc(alias = "gst_task_set_pool")]
    fn set_pool(&self, pool: &impl IsA<TaskPool>) {
        unsafe {
            ffi::gst_task_set_pool(
                self.as_ref().to_glib_none().0,
                pool.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "gst_task_set_state")]
    fn set_state(&self, state: TaskState) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_task_set_state(self.as_ref().to_glib_none().0, state.into_glib()),
                "Failed to set task state"
            )
        }
    }

    #[doc(alias = "gst_task_start")]
    fn start(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_task_start(self.as_ref().to_glib_none().0),
                "Failed to start task"
            )
        }
    }

    #[doc(alias = "gst_task_stop")]
    fn stop(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_task_stop(self.as_ref().to_glib_none().0),
                "Failed to stop task"
            )
        }
    }
}

impl<O: IsA<Task>> TaskExt for O {}