alsatimer/
user_instance.rs

1// SPDX-License-Identifier: MIT
2use super::*;
3
4/// Trait containing the rest of [`struct@UserInstance`] methods.
5///
6/// # Implementors
7///
8/// [`UserInstance`][struct@crate::UserInstance]
9pub trait UserInstanceExtManual {
10    /// Get the version of timer protocol currently used. The version is expressed as the array with
11    /// three elements; major, minor, and micro version in the order. The length of major version is
12    /// 16 bit, the length of minor and micro version is 8 bit each.
13    ///
14    /// # Returns
15    ///
16    /// [`true`] when the overall operation finishes successfully, else [`false`].
17    ///
18    /// ## `proto_ver_triplet`
19    /// The version of protocol currently
20    ///                     used.
21    #[doc(alias = "alsatimer_user_instance_get_protocol_version")]
22    #[doc(alias = "get_protocol_version")]
23    fn protocol_version(&self) -> Result<&[u16; 3], glib::Error>;
24
25    /// Configure the instance with the parameters and return the latest parameters.
26    ///
27    /// The call of function executes `ioctl(2)` system call with `SNDRV_TIMER_IOCTL_PARAMS` command
28    /// for ALSA timer character device.
29    /// ## `instance_params`
30    /// A [`InstanceParams`][crate::InstanceParams].
31    ///
32    /// # Returns
33    ///
34    /// [`true`] when the overall operation finishes successfully, else [`false`].
35    #[doc(alias = "alsatimer_user_instance_set_params")]
36    fn set_params<P: IsA<InstanceParams>>(&self, params: &mut P) -> Result<(), glib::Error>;
37
38    /// Get the latest status of instance.
39    ///
40    /// The call of function executes `ioctl(2)` system call with `SNDRV_TIMER_IOCTL_STATUS` command
41    /// for ALSA timer character device.
42    /// ## `instance_status`
43    /// A [`InstanceStatus`][crate::InstanceStatus].
44    ///
45    /// # Returns
46    ///
47    /// [`true`] when the overall operation finishes successfully, else [`false`].
48    #[doc(alias = "alsatimer_user_instance_get_status")]
49    #[doc(alias = "get_status")]
50    fn status<P: IsA<InstanceStatus>>(&self, status: &mut P) -> Result<(), glib::Error>;
51}
52
53impl<O: IsA<UserInstance>> UserInstanceExtManual for O {
54    fn protocol_version(&self) -> Result<&[u16; 3], glib::Error> {
55        unsafe {
56            let mut triplet = std::ptr::null_mut() as *const [u16; 3];
57            let mut error = std::ptr::null_mut();
58
59            let is_ok = ffi::alsatimer_user_instance_get_protocol_version(
60                self.as_ref().to_glib_none().0,
61                &mut triplet as *mut *const [u16; 3],
62                &mut error,
63            );
64            assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
65
66            if error.is_null() {
67                Ok(&*triplet)
68            } else {
69                Err(from_glib_full(error))
70            }
71        }
72    }
73
74    fn set_params<P: IsA<InstanceParams>>(&self, params: &mut P) -> Result<(), glib::Error> {
75        unsafe {
76            let mut error = std::ptr::null_mut();
77
78            let is_ok = ffi::alsatimer_user_instance_set_params(
79                self.as_ref().to_glib_none().0,
80                &mut params.as_ref().to_glib_none().0,
81                &mut error,
82            );
83            assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
84
85            if error.is_null() {
86                Ok(())
87            } else {
88                Err(from_glib_full(error))
89            }
90        }
91    }
92
93    fn status<P: IsA<InstanceStatus>>(&self, status: &mut P) -> Result<(), glib::Error> {
94        unsafe {
95            let mut error = std::ptr::null_mut();
96            let is_ok = ffi::alsatimer_user_instance_get_status(
97                self.as_ref().to_glib_none().0,
98                &mut status.as_ref().to_glib_none().0,
99                &mut error,
100            );
101            assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
102
103            if error.is_null() {
104                Ok(())
105            } else {
106                Err(from_glib_full(error))
107            }
108        }
109    }
110}