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
use ::libc;
#[cfg(feature = "task")]
use super::task::BufProc;
use super::{In, Out, Sig};
use super::control::Control;
#[derive(Copy, Clone, Debug)]
pub enum DeviceState {
#[cfg(feature = "task")] Proc(BufProc),
Idle,
Sig(Sig),
OutText(Out, libc::size_t),
InText(Control),
}
impl DeviceState {
#[cfg(feature = "task")]
pub fn from_task(name: BufProc) -> Self {
DeviceState::Proc(name)
}
pub fn from_idle() -> Self {
DeviceState::Idle
}
pub fn from_out(buf: Out, len: libc::size_t) -> Self {
DeviceState::OutText(buf, len)
}
pub fn from_in(buf: In, len: libc::size_t) -> Self {
DeviceState::InText(Control::new(buf, len))
}
pub fn from_sig(sig: libc::c_int) -> Self {
DeviceState::Sig(sig)
}
#[cfg(feature = "task")]
pub fn is_task(self) -> Option<BufProc> {
match self {
DeviceState::Proc(name) => Some(name),
_ => None,
}
}
pub fn is_idle(&self) -> Option<()> {
match *self {
DeviceState::Idle => Some(()),
_ => None,
}
}
pub fn is_out_text(&self) -> Option<(Out, libc::size_t)> {
match *self {
DeviceState::OutText(buf, len) => Some((buf, len)),
_ => None,
}
}
pub fn is_input(&self) -> Option<Control> {
match *self {
DeviceState::InText(event) => Some(event),
_ => None,
}
}
pub fn is_signal(&self) -> Option<libc::c_int> {
match *self {
DeviceState::Sig(sig) => Some(sig),
_ => None,
}
}
}