line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Udev::FFI - Copyright (C) 2017 Ilya Pavlov |
2
|
|
|
|
|
|
|
# Udev::FFI is licensed under the |
3
|
|
|
|
|
|
|
# GNU Lesser General Public License v2.1 |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Udev::FFI; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
157764
|
use strict; |
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
86
|
|
8
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
103
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
885
|
use Udev::FFI::Functions qw(:all); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
1167
|
|
11
|
2
|
|
|
2
|
|
862
|
use Udev::FFI::Device; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
66
|
|
12
|
2
|
|
|
2
|
|
611
|
use Udev::FFI::Monitor; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
62
|
|
13
|
2
|
|
|
2
|
|
605
|
use Udev::FFI::Enumerate; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1324
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$Udev::FFI::VERSION = '0.099001'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
*Udev::FFI::udev_version = \&Udev::FFI::Functions::udev_version; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
1
|
|
|
1
|
1
|
918
|
my $class = shift; |
26
|
1
|
|
|
|
|
4
|
my $self = {}; |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
14
|
if(0 == Udev::FFI::Functions->init()) { |
29
|
0
|
|
|
|
|
0
|
$@ = "Can't find udev library"; |
30
|
0
|
|
|
|
|
0
|
return undef; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
85
|
$self->{_context} = udev_new(); |
34
|
1
|
50
|
|
|
|
5
|
if(!defined($self->{_context})) { |
35
|
0
|
|
|
|
|
0
|
$@ = "Can't create udev context"; |
36
|
0
|
|
|
|
|
0
|
return undef; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
4
|
bless $self, $class; |
40
|
1
|
|
|
|
|
6
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new_device_from_syspath { |
46
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
47
|
0
|
|
|
|
|
0
|
my $syspath = shift; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
my $device = udev_device_new_from_syspath($self->{_context}, $syspath); |
50
|
0
|
0
|
|
|
|
0
|
if(defined($device)) { |
51
|
0
|
|
|
|
|
0
|
return Udev::FFI::Device->new( $device ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return undef; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new_device_from_devnum { |
60
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
61
|
0
|
|
|
|
|
0
|
my $type = shift; |
62
|
0
|
|
|
|
|
0
|
my $devnum = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my $device = udev_device_new_from_devnum($self->{_context}, ord($type), $devnum); |
65
|
0
|
0
|
|
|
|
0
|
if(defined($device)) { |
66
|
0
|
|
|
|
|
0
|
return Udev::FFI::Device->new( $device ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub new_device_from_subsystem_sysname { |
75
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
76
|
0
|
|
|
|
|
0
|
my $subsystem = shift; |
77
|
0
|
|
|
|
|
0
|
my $sysname = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
my $device = udev_device_new_from_subsystem_sysname($self->{_context}, $subsystem, $sysname); |
80
|
0
|
0
|
|
|
|
0
|
if(defined($device)) { |
81
|
0
|
|
|
|
|
0
|
return Udev::FFI::Device->new( $device ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub new_device_from_device_id { |
90
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
91
|
0
|
|
|
|
|
0
|
my $id = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
my $device = udev_device_new_from_device_id($self->{_context}, $id); |
94
|
0
|
0
|
|
|
|
0
|
if(defined($device)) { |
95
|
0
|
|
|
|
|
0
|
return Udev::FFI::Device->new( $device ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
return undef; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub new_device_from_environment { |
104
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
my $device = udev_device_new_from_environment($self->{_context}); |
107
|
0
|
0
|
|
|
|
0
|
if(defined($device)) { |
108
|
0
|
|
|
|
|
0
|
return Udev::FFI::Device->new( $device ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
return undef; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub new_monitor { |
117
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
118
|
0
|
|
0
|
|
|
0
|
my $source = shift || 'udev'; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
0
|
|
|
0
|
if($source ne 'udev' && $source ne 'kernel') { |
121
|
0
|
|
|
|
|
0
|
$@ = 'Valid sources identifiers are "udev" and "kernel"'; |
122
|
0
|
|
|
|
|
0
|
return undef; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
0
|
my $monitor = udev_monitor_new_from_netlink($self->{_context}, $source); |
126
|
0
|
0
|
|
|
|
0
|
unless(defined($monitor)) { |
127
|
0
|
|
|
|
|
0
|
$@ = "Can't create udev monitor from netlink"; |
128
|
0
|
|
|
|
|
0
|
return undef; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
0
|
return Udev::FFI::Monitor->new($monitor); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub new_enumerate { |
137
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
0
|
my $enumerate = udev_enumerate_new($self->{_context}); |
140
|
0
|
0
|
|
|
|
0
|
unless(defined($enumerate)) { |
141
|
0
|
|
|
|
|
0
|
$@ = "Can't create enumerate context"; |
142
|
0
|
|
|
|
|
0
|
return undef; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
return Udev::FFI::Enumerate->new($enumerate); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub DESTROY { |
151
|
1
|
|
|
1
|
|
534
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
59
|
udev_unref( $self->{_context} ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |