line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Udev::FFI::Monitor; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
488
|
use IO::Select; |
|
2
|
|
|
|
|
2431
|
|
|
2
|
|
|
|
|
80
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use Udev::FFI::FFIFunctions; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
376
|
|
9
|
2
|
|
|
2
|
|
12
|
use Udev::FFI::Device; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
808
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $self = { |
16
|
|
|
|
|
|
|
_monitor => shift, |
17
|
|
|
|
|
|
|
_is_started => 0 |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
bless $self, $class; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get_udev { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return udev_monitor_get_udev($self->{_monitor}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub set_receive_buffer_size { |
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
37
|
0
|
|
|
|
|
|
my $bytes = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if(0 != udev_monitor_set_receive_buffer_size($self->{_monitor}, $bytes)) { |
40
|
0
|
|
|
|
|
|
return 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub filter_by_subsystem_devtype { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
my $subsystem = shift; |
51
|
0
|
|
|
|
|
|
my $devtype = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return 0 |
54
|
0
|
0
|
|
|
|
|
if 1 == $self->{_is_started}; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if(0 != udev_monitor_filter_add_match_subsystem_devtype($self->{_monitor}, $subsystem, $devtype)) { |
57
|
0
|
|
|
|
|
|
return 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return 1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub filter_by_tag { |
66
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my $tag = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return 0 |
70
|
0
|
0
|
|
|
|
|
if 1 == $self->{_is_started}; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if(0 != udev_monitor_filter_add_match_tag($self->{_monitor}, $tag)) { |
73
|
0
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub filter_update { |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if(0 != udev_monitor_filter_update($self->{_monitor})) { |
85
|
0
|
|
|
|
|
|
return 0; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub filter_remove { |
94
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if(0 != udev_monitor_filter_remove($self->{_monitor})) { |
97
|
0
|
|
|
|
|
|
return 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub start { |
106
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return 1 |
109
|
0
|
0
|
|
|
|
|
if $self->{_is_started}; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if(0 != udev_monitor_enable_receiving( $self->{_monitor} )) { |
112
|
0
|
|
|
|
|
|
return 0; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $fd = udev_monitor_get_fd($self->{_monitor}); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $fdh; |
118
|
0
|
0
|
|
|
|
|
if(!open($fdh, "<&=", $fd)) { |
119
|
0
|
|
|
|
|
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->{_select} = IO::Select->new(); |
123
|
0
|
|
|
|
|
|
$self->{_select}->add($fdh); |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$self->{_is_started} = 1; |
126
|
0
|
|
|
|
|
|
return 1; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub poll { |
132
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
133
|
0
|
|
|
|
|
|
my $timeout = shift; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
unless($self->{_is_started}) { |
136
|
0
|
|
|
|
|
|
die "udev monitor is not running"; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if($self->{_select}->can_read($timeout)) { |
140
|
0
|
|
|
|
|
|
my $device = udev_monitor_receive_device( $self->{_monitor} ); |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return Udev::FFI::Device->new( $device ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return undef; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub is_started { |
151
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return $self->{_is_started}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub DESTROY { |
159
|
0
|
|
|
0
|
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
udev_monitor_unref( $self->{_monitor} ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |