rubdev 0.0.1a → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rubdev/c.rb +102 -19
- data/lib/rubdev/context.rb +46 -0
- data/lib/rubdev/device.rb +115 -22
- data/lib/rubdev/enumerate.rb +104 -0
- data/lib/rubdev/list.rb +71 -0
- data/lib/rubdev/monitor.rb +34 -13
- data/lib/rubdev/queue.rb +80 -0
- data/lib/rubdev.rb +4 -1
- metadata +10 -9
data/lib/rubdev/c.rb
CHANGED
@@ -19,6 +19,18 @@
|
|
19
19
|
|
20
20
|
require 'ffi'
|
21
21
|
|
22
|
+
module FFI
|
23
|
+
module Library
|
24
|
+
def attach_function! (*args, &block)
|
25
|
+
begin
|
26
|
+
attach_function(*args, &block)
|
27
|
+
rescue Exception => e
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
22
34
|
module RubDev
|
23
35
|
module C
|
24
36
|
extend FFI::Library
|
@@ -27,39 +39,110 @@ module RubDev
|
|
27
39
|
|
28
40
|
FFI.typedef(:ulong, :dev_t)
|
29
41
|
|
42
|
+
callback :logger, [:pointer, :int, :string, :int, :string, :string, :pointer], :void
|
43
|
+
|
30
44
|
# context {{{
|
45
|
+
attach_function :udev_ref, [:pointer], :pointer
|
46
|
+
attach_function :udev_unref, [:pointer], :void
|
31
47
|
attach_function :udev_new, [], :pointer
|
48
|
+
attach_function :udev_set_log_fn, [:pointer, :logger], :void
|
49
|
+
attach_function :udev_get_log_priority, [:pointer], :int
|
50
|
+
attach_function :udev_set_log_priority, [:pointer, :int], :void
|
51
|
+
attach_function :udev_get_sys_path, [:pointer], :string
|
52
|
+
attach_function :udev_get_dev_path, [:pointer], :string
|
53
|
+
attach_function!:udev_get_run_path, [:pointer], :string
|
54
|
+
attach_function :udev_get_userdata, [:pointer], :pointer
|
55
|
+
attach_function :udev_set_userdata, [:pointer, :pointer], :void
|
32
56
|
# }}}
|
33
57
|
|
34
|
-
#
|
35
|
-
attach_function :
|
36
|
-
attach_function :
|
37
|
-
attach_function :
|
38
|
-
attach_function :
|
39
|
-
attach_function :udev_monitor_filter_remove, [:pointer], :int
|
40
|
-
attach_function :udev_monitor_enable_receiving, [:pointer], :int
|
41
|
-
attach_function :udev_monitor_get_fd, [:pointer], :int
|
42
|
-
attach_function :udev_monitor_receive_device, [:pointer], :pointer
|
43
|
-
attach_function :udev_monitor_get_udev, [:pointer], :pointer
|
44
|
-
attach_function :udev_monitor_ref, [:pointer], :void
|
45
|
-
attach_function :udev_monitor_unref, [:pointer], :void
|
58
|
+
# list {{{
|
59
|
+
attach_function :udev_list_entry_get_next, [:pointer], :pointer
|
60
|
+
attach_function :udev_list_entry_get_by_name, [:pointer, :string], :pointer
|
61
|
+
attach_function :udev_list_entry_get_name, [:pointer], :string
|
62
|
+
attach_function :udev_list_entry_get_value, [:pointer], :string
|
46
63
|
# }}}
|
47
64
|
|
48
65
|
# device {{{
|
49
|
-
attach_function :
|
50
|
-
attach_function :
|
51
|
-
attach_function :
|
52
|
-
attach_function :
|
66
|
+
attach_function :udev_device_ref, [:pointer], :void
|
67
|
+
attach_function :udev_device_unref, [:pointer], :void
|
68
|
+
attach_function :udev_device_get_udev, [:pointer], :pointer
|
69
|
+
attach_function :udev_device_new_from_syspath, [:pointer, :string], :pointer
|
70
|
+
attach_function :udev_device_new_from_devnum, [:pointer, :char, :dev_t], :pointer
|
71
|
+
attach_function :udev_device_new_from_subsystem_sysname, [:pointer, :string, :string], :pointer
|
72
|
+
attach_function :udev_device_new_from_environment, [:pointer], :pointer
|
53
73
|
attach_function :udev_device_get_parent, [:pointer], :pointer
|
74
|
+
attach_function :udev_device_get_parent_with_subsystem_devtype, [:pointer, :string, :string], :pointer
|
54
75
|
attach_function :udev_device_get_devpath, [:pointer], :string
|
76
|
+
attach_function :udev_device_get_subsystem, [:pointer], :string
|
77
|
+
attach_function :udev_device_get_devtype, [:pointer], :string
|
55
78
|
attach_function :udev_device_get_syspath, [:pointer], :string
|
56
79
|
attach_function :udev_device_get_sysname, [:pointer], :string
|
57
80
|
attach_function :udev_device_get_sysnum, [:pointer], :string
|
81
|
+
attach_function :udev_device_get_devnode, [:pointer], :string
|
82
|
+
attach_function!:udev_device_get_is_initialized, [:pointer], :int
|
83
|
+
attach_function :udev_device_get_devlinks_list_entry, [:pointer], :pointer
|
84
|
+
attach_function :udev_device_get_properties_list_entry, [:pointer], :pointer
|
85
|
+
attach_function :udev_device_get_tags_list_entry, [:pointer], :pointer
|
86
|
+
attach_function :udev_device_get_property_value, [:pointer, :string], :string
|
58
87
|
attach_function :udev_device_get_driver, [:pointer], :string
|
59
88
|
attach_function :udev_device_get_devnum, [:pointer], :dev_t
|
60
|
-
attach_function :
|
61
|
-
attach_function :
|
62
|
-
attach_function
|
89
|
+
attach_function :udev_device_get_action, [:pointer], :string
|
90
|
+
attach_function :udev_device_get_sysattr_value, [:pointer, :string], :string
|
91
|
+
attach_function!:udev_device_get_sysattr_list_entry, [:pointer], :pointer
|
92
|
+
attach_function :udev_device_get_seqnum, [:pointer], :long_long
|
93
|
+
attach_function!:udev_device_get_usec_since_initialized, [:pointer], :long_long
|
94
|
+
attach_function!:udev_device_has_tag, [:pointer, :string], :int
|
95
|
+
# }}}
|
96
|
+
|
97
|
+
# monitor {{{
|
98
|
+
attach_function :udev_monitor_ref, [:pointer], :pointer
|
99
|
+
attach_function :udev_monitor_unref, [:pointer], :void
|
100
|
+
attach_function :udev_monitor_get_udev, [:pointer], :pointer
|
101
|
+
attach_function :udev_monitor_new_from_netlink, [:pointer, :string], :pointer
|
102
|
+
attach_function :udev_monitor_new_from_socket, [:pointer, :string], :pointer
|
103
|
+
attach_function :udev_monitor_enable_receiving, [:pointer], :int
|
104
|
+
attach_function :udev_monitor_set_receive_buffer_size, [:pointer, :int], :int
|
105
|
+
attach_function :udev_monitor_get_fd, [:pointer], :int
|
106
|
+
attach_function :udev_monitor_receive_device, [:pointer], :pointer
|
107
|
+
attach_function :udev_monitor_filter_add_match_subsystem_devtype, [:pointer, :string, :string], :int
|
108
|
+
attach_function :udev_monitor_filter_add_match_tag, [:pointer, :string], :int
|
109
|
+
attach_function :udev_monitor_filter_update, [:pointer], :int
|
110
|
+
attach_function :udev_monitor_filter_remove, [:pointer], :int
|
111
|
+
# }}}
|
112
|
+
|
113
|
+
# enumerate {{{
|
114
|
+
attach_function :udev_enumerate_ref, [:pointer], :pointer
|
115
|
+
attach_function :udev_enumerate_unref, [:pointer], :void
|
116
|
+
attach_function :udev_enumerate_get_udev, [:pointer], :pointer
|
117
|
+
attach_function :udev_enumerate_new, [:pointer], :pointer
|
118
|
+
attach_function :udev_enumerate_add_match_subsystem, [:pointer, :string], :int
|
119
|
+
attach_function :udev_enumerate_add_nomatch_subsystem, [:pointer, :string], :int
|
120
|
+
attach_function :udev_enumerate_add_match_sysattr, [:pointer, :string, :string], :int
|
121
|
+
attach_function :udev_enumerate_add_nomatch_sysattr, [:pointer, :string, :string], :int
|
122
|
+
attach_function :udev_enumerate_add_match_property, [:pointer, :string, :string], :int
|
123
|
+
attach_function :udev_enumerate_add_match_tag, [:pointer, :string], :int
|
124
|
+
attach_function!:udev_enumerate_add_match_parent, [:pointer, :pointer], :int
|
125
|
+
attach_function!:udev_enumerate_add_match_is_initialized, [:pointer], :int
|
126
|
+
attach_function :udev_enumerate_add_match_sysname, [:pointer, :string], :int
|
127
|
+
attach_function :udev_enumerate_add_syspath, [:pointer, :string], :int
|
128
|
+
attach_function :udev_enumerate_scan_devices, [:pointer], :int
|
129
|
+
attach_function :udev_enumerate_scan_subsystems, [:pointer], :int
|
130
|
+
attach_function :udev_enumerate_get_list_entry, [:pointer], :pointer
|
131
|
+
# }}}
|
132
|
+
|
133
|
+
# queue {{{
|
134
|
+
attach_function :udev_queue_ref, [:pointer], :pointer
|
135
|
+
attach_function :udev_queue_unref, [:pointer], :void
|
136
|
+
attach_function :udev_queue_get_udev, [:pointer], :pointer
|
137
|
+
attach_function :udev_queue_new, [:pointer], :pointer
|
138
|
+
attach_function :udev_queue_get_udev_is_active, [:pointer], :int
|
139
|
+
attach_function :udev_queue_get_queue_is_empty, [:pointer], :int
|
140
|
+
attach_function :udev_queue_get_seqnum_is_finished, [:pointer, :ulong_long], :int
|
141
|
+
attach_function :udev_queue_get_seqnum_sequence_is_finished, [:pointer, :ulong_long, :ulong_long], :int
|
142
|
+
attach_function :udev_queue_get_queued_list_entry, [:pointer], :pointer
|
143
|
+
attach_function :udev_queue_get_failed_list_entry, [:pointer], :pointer
|
144
|
+
attach_function :udev_queue_get_kernel_seqnum, [:pointer], :ulong_long
|
145
|
+
attach_function :udev_queue_get_udev_seqnum, [:pointer], :ulong_long
|
63
146
|
# }}}
|
64
147
|
end
|
65
148
|
end
|
data/lib/rubdev/context.rb
CHANGED
@@ -25,6 +25,52 @@ module RubDev
|
|
25
25
|
@pointer = RubDev::C.udev_new
|
26
26
|
end
|
27
27
|
|
28
|
+
def ref
|
29
|
+
RubDev::C.udev_ref(@pointer)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def unref
|
34
|
+
RubDev::C.udev_unref(@pointer)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def log_fn= (fn)
|
39
|
+
return false unless fn.is_a?(Proc)
|
40
|
+
RubDev::C.udev_set_log_fn(@pointer, fn)
|
41
|
+
end
|
42
|
+
|
43
|
+
def log_priority
|
44
|
+
RubDev::C.udev_get_log_priority(@pointer)
|
45
|
+
end
|
46
|
+
|
47
|
+
def log_priority= (p)
|
48
|
+
return false unless p.is_a?(Integer)
|
49
|
+
RubDev::C.udev_set_log_priority(@pointer, p)
|
50
|
+
end
|
51
|
+
|
52
|
+
def sys_path
|
53
|
+
RubDev::C.udev_get_sys_path(@pointer)
|
54
|
+
end
|
55
|
+
|
56
|
+
def dev_path
|
57
|
+
RubDev::C.udev_get_dev_path(@pointer)
|
58
|
+
end
|
59
|
+
|
60
|
+
if RubDev::C.respond_to?(:udev_get_run_path)
|
61
|
+
def run_path
|
62
|
+
RubDev::C.udev_get_run_path(@pointer)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def userdata
|
67
|
+
RubDev::C.udev_get_userdata(@pointer)
|
68
|
+
end
|
69
|
+
|
70
|
+
def userdata= (data)
|
71
|
+
RubDev::C.udev_get_userdata(@pointer, data)
|
72
|
+
end
|
73
|
+
|
28
74
|
def to_c
|
29
75
|
@pointer
|
30
76
|
end
|
data/lib/rubdev/device.rb
CHANGED
@@ -18,33 +18,89 @@
|
|
18
18
|
#++
|
19
19
|
|
20
20
|
require 'rubdev/c'
|
21
|
+
require 'rubdev/context'
|
22
|
+
require 'rubdev/device'
|
23
|
+
require 'rubdev/list'
|
21
24
|
|
22
25
|
module RubDev
|
23
26
|
class Device
|
24
|
-
|
25
|
-
|
27
|
+
def ref
|
28
|
+
RubDev::C.udev_device_ref(@pointer)
|
29
|
+
self
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
29
|
-
RubDev::C.
|
32
|
+
def unref
|
33
|
+
RubDev::C.udev_device_unref(@pointer)
|
34
|
+
self
|
30
35
|
end
|
31
36
|
|
32
|
-
def
|
33
|
-
|
37
|
+
def context
|
38
|
+
Context.allocate.tap {|c|
|
39
|
+
c.instance_variable_set(:@pointer, RubDev::C.udev_device_get_udev(@pointer))
|
40
|
+
}
|
34
41
|
end
|
35
42
|
|
36
|
-
|
37
|
-
|
43
|
+
class << self
|
44
|
+
private :new
|
45
|
+
|
46
|
+
def from_syspath (context, syspath)
|
47
|
+
return nil unless context.is_a?(Context) and syspath.is_a?(String)
|
48
|
+
|
49
|
+
self.allocate.tap {|d|
|
50
|
+
d.instance_variable_set(:@pointer, RubDev::C.udev_device_new_from_syspath(context.to_c, syspath))
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def from_devnum (context, type, devnum)
|
55
|
+
return nil unless context.is_a?(Context) and type.is_a?(String) and
|
56
|
+
type.bytesize == 1 and devnum.is_a?(Integer)
|
57
|
+
|
58
|
+
self.allocate.tap {|d|
|
59
|
+
d.instance_variable_set(:@pointer, RubDev::C.udev_device_new_from_devnum(context.to_c, type, devnum))
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def from_subsystem_sysname (context, subsystem, sysname)
|
64
|
+
return nil unless context.is_a?(Context) and subsystem.is_a?(String) and sysname.is_a?(String)
|
65
|
+
|
66
|
+
self.allocate.tap {|d|
|
67
|
+
d.instance_variable_set(:@pointer, RubDev::C.udev_device_new_from_subsystem_sysname(context.to_c, subsystem, sysname))
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def from_environment (context)
|
72
|
+
return nil unless context.is_a?(Context)
|
73
|
+
|
74
|
+
self.allocate.tap {|d|
|
75
|
+
d.instance_variable_set(:@pointer, RubDev::C.udev_device_new_from_environment(context.to_c))
|
76
|
+
}
|
77
|
+
end
|
38
78
|
end
|
39
79
|
|
40
|
-
def
|
41
|
-
|
80
|
+
def parent
|
81
|
+
Device.allocate.tap {|i|
|
82
|
+
i.instance_variable_set(:@pointer, RubDev::C.udev_device_get_parent(@pointer))
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def parent_with_subsystem_devtype (subsystem, devtype)
|
87
|
+
Device.allocate.tap {|i|
|
88
|
+
i.instance_variable_set(:@pointer, RubDev::C.udev_device_get_parent_with_subsytem_devtype(@pointer, subsystem, devtype))
|
89
|
+
}
|
42
90
|
end
|
43
91
|
|
44
92
|
def devpath
|
45
93
|
RubDev::C.udev_device_get_devpath(@pointer)
|
46
94
|
end
|
47
95
|
|
96
|
+
def subsystem
|
97
|
+
RubDev::C.udev_device_get_subsystem(@pointer)
|
98
|
+
end
|
99
|
+
|
100
|
+
def devtype
|
101
|
+
RubDev::C.udev_device_get_devtype(@pointer)
|
102
|
+
end
|
103
|
+
|
48
104
|
def syspath
|
49
105
|
RubDev::C.udev_device_get_syspath(@pointer)
|
50
106
|
end
|
@@ -57,6 +113,33 @@ module RubDev
|
|
57
113
|
RubDev::C.udev_device_get_sysnum(@pointer)
|
58
114
|
end
|
59
115
|
|
116
|
+
def devnode
|
117
|
+
RubDev::C.udev_device_get_devnode(@pointer)
|
118
|
+
end
|
119
|
+
|
120
|
+
if RubDev::C.respond_to?(:udev_device_get_is_initialized)
|
121
|
+
def initialized?
|
122
|
+
!RubDev::C.udev_device_get_is_initialized(@pointer).zero?
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def devlinks
|
127
|
+
List.new(RubDev::C.udev_device_get_devlinks_list_entry(@pointer))
|
128
|
+
end
|
129
|
+
|
130
|
+
def properties
|
131
|
+
List.new(RubDev::C.udev_device_get_properties_list_entry(@pointer))
|
132
|
+
end
|
133
|
+
|
134
|
+
def tags
|
135
|
+
List.new(RubDev::C.udev_device_get_tags_list_entry(@pointer))
|
136
|
+
end
|
137
|
+
|
138
|
+
def property (what)
|
139
|
+
RubDev::C.udev_device_get_property_value(@pointer, what.to_s)
|
140
|
+
end
|
141
|
+
alias [] property
|
142
|
+
|
60
143
|
def driver
|
61
144
|
RubDev::C.udev_device_get_driver(@pointer)
|
62
145
|
end
|
@@ -65,24 +148,34 @@ module RubDev
|
|
65
148
|
RubDev::C.udev_device_get_devnum(@pointer)
|
66
149
|
end
|
67
150
|
|
68
|
-
def
|
69
|
-
RubDev::C.
|
151
|
+
def action
|
152
|
+
RubDev::C.udev_device_get_action(@pointer)
|
70
153
|
end
|
71
154
|
|
72
|
-
def
|
73
|
-
RubDev::C.
|
74
|
-
self
|
155
|
+
def sysattr (what)
|
156
|
+
RubDev::C.udev_device_get_sysattr_value(@pointer, what)
|
75
157
|
end
|
76
158
|
|
77
|
-
|
78
|
-
|
79
|
-
|
159
|
+
if RubDev::C.respond_to?(:udev_device_get_sysattr_list_entry)
|
160
|
+
def sysattrs
|
161
|
+
List.new(RubDev::C.udev_device_get_sysattr_list_entry(@pointer))
|
162
|
+
end
|
80
163
|
end
|
81
164
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
165
|
+
def seqnum
|
166
|
+
RubDev::C.udev_device_get_seqnum(@pointer)
|
167
|
+
end
|
168
|
+
|
169
|
+
if RubDev::C.respond_to?(:udev_device_get_usec_since_initialized)
|
170
|
+
def usec
|
171
|
+
RubDev::C.udev_device_get_usec_since_initialized(@pointer)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
if RubDev::C.respond_to?(:udev_device_has_tag)
|
176
|
+
def tag? (tag)
|
177
|
+
!RubDev::C.udev_device_has_tag(tag).zero?
|
178
|
+
end
|
86
179
|
end
|
87
180
|
end
|
88
181
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of rubdev.
|
5
|
+
#
|
6
|
+
# rubdev is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# rubdev is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with rubdev. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'rubdev/c'
|
21
|
+
require 'rubdev/context'
|
22
|
+
require 'rubdev/list'
|
23
|
+
|
24
|
+
module RubDev
|
25
|
+
class Enumerate
|
26
|
+
def ref
|
27
|
+
RubDev::C.udev_enumerate_ref(@pointer)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def unref
|
32
|
+
RubDev::C.udev_enumerate_unref(@pointer)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def context
|
37
|
+
Context.allocate.tap {|i|
|
38
|
+
i.instance_variable_set(:@pointer, RubDev::C.udev_enumerate_get_udev(@pointer))
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize (context)
|
43
|
+
raise ArgumentError, "argument is NOT a RubDev::Context" unless context.is_a?(Context)
|
44
|
+
|
45
|
+
@pointer = RubDev::C.udev_enumerate_new(context.to_c)
|
46
|
+
end
|
47
|
+
|
48
|
+
def match_subsystem (subsystem)
|
49
|
+
!RubDev::C.udev_enumerate_add_match_subsystem(@pointer, subsystem).zero?
|
50
|
+
end
|
51
|
+
|
52
|
+
def nomatch_subsystem (subsystem)
|
53
|
+
!RubDev::C.udev_enumerate_add_nomatch_subsystem(@pointer, subsystem).zero?
|
54
|
+
end
|
55
|
+
|
56
|
+
def match_sysattr (sysattr, value)
|
57
|
+
!RubDev::C.udev_enumerate_add_match_sysattr(@pointer, sysattr, value).zero?
|
58
|
+
end
|
59
|
+
|
60
|
+
def nomatch_sysattr (sysattr, value)
|
61
|
+
!RubDev::C.udev_enumerate_add_nomatch_sysattr(@pointer, sysattr, value).zero?
|
62
|
+
end
|
63
|
+
|
64
|
+
def match_property (property, value)
|
65
|
+
!RubDev::C.udev_enumerate_add_match_property(@pointer, property, value).zero?
|
66
|
+
end
|
67
|
+
|
68
|
+
def match_tag (tag)
|
69
|
+
!RubDev::C.udev_enumerate_add_match_tag(@pointer, tag).zero?
|
70
|
+
end
|
71
|
+
|
72
|
+
if RubDev::C.respond_to?(:udev_enumerate_add_match_parent)
|
73
|
+
def match_parent (parent)
|
74
|
+
!RubDev::C.udev_enumerate_add_match_parent(@pointer, parent).zero?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if RubDev::C.respond_to?(:udev_enumerate_add_match_is_initialized)
|
79
|
+
def match_initialized
|
80
|
+
!RubDev::C.udev_enumerate_add_match_is_initialized(@pointer).zero?
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def match_sysname (sysname)
|
85
|
+
!RubDev::C.udev_enumerate_add_match_sysname(@pointer, sysname).zero?
|
86
|
+
end
|
87
|
+
|
88
|
+
def syspath= (syspath)
|
89
|
+
!RubDev::C.udev_enumerate_add_syspath(syspath).zero?
|
90
|
+
end
|
91
|
+
|
92
|
+
def scan_devices
|
93
|
+
!RubDev::C.udev_enumerate_scan_devices(@pointer).zero?
|
94
|
+
end
|
95
|
+
|
96
|
+
def scan_subsystems
|
97
|
+
!RubDev::C.udev_enumerate_scan_subsystems(@pointer).zero?
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_list
|
101
|
+
List.new(RubDev::C.udev_enumerate_get_list_entry(@pointer))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/rubdev/list.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of rubdev.
|
5
|
+
#
|
6
|
+
# rubdev is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# rubdev is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with rubdev. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'rubdev/c'
|
21
|
+
|
22
|
+
module RubDev
|
23
|
+
class List
|
24
|
+
include Enumerable
|
25
|
+
|
26
|
+
def initialize (list)
|
27
|
+
@top = list
|
28
|
+
rewind
|
29
|
+
end
|
30
|
+
|
31
|
+
def rewind
|
32
|
+
@pointer = @top
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def next
|
37
|
+
@pointer = RubDev::C.udev_list_entry_get_next(@pointer)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def by_name (name)
|
42
|
+
RubDev::C.udev_list_entry_get_by_name(@pointer, name)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def name
|
47
|
+
RubDev::C.udev_list_entry_get_name(@pointer)
|
48
|
+
end
|
49
|
+
|
50
|
+
def value
|
51
|
+
RubDev::C.udev_list_entry_get_value(@pointer)
|
52
|
+
end
|
53
|
+
|
54
|
+
def [] (name)
|
55
|
+
by_name(name).value
|
56
|
+
end
|
57
|
+
|
58
|
+
def each(&blk)
|
59
|
+
array = []
|
60
|
+
pointer = @pointer
|
61
|
+
rewind
|
62
|
+
unless @pointer.null?
|
63
|
+
blk.call(name, value) if blk
|
64
|
+
array << [name, value]
|
65
|
+
self.next
|
66
|
+
end
|
67
|
+
@pointer = pointer
|
68
|
+
blk ? array : Enumerator.new(array)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/rubdev/monitor.rb
CHANGED
@@ -23,6 +23,22 @@ require 'rubdev/device'
|
|
23
23
|
|
24
24
|
module RubDev
|
25
25
|
class Monitor
|
26
|
+
def ref
|
27
|
+
RubDev::C.udev_monitor_ref(@pointer)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def unref
|
32
|
+
RubDev::C.udev_monitor_unref(@pointer)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def context
|
37
|
+
Context.allocate.tap {|i|
|
38
|
+
i.instance_variable_set(:@pointer, RubDev::C.udev_monitor_get_udev(@pointer))
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
26
42
|
class << self
|
27
43
|
private :new
|
28
44
|
|
@@ -43,8 +59,13 @@ module RubDev
|
|
43
59
|
RubDev::C.udev_monitor_enable_receiving(@pointer)
|
44
60
|
end
|
45
61
|
|
46
|
-
def
|
47
|
-
|
62
|
+
def buffer_size= (size)
|
63
|
+
return false unless size.is_a?(Integer)
|
64
|
+
RubDev::C.udev_monitor_set_receive_buffer_size(@pointer, size)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fd
|
68
|
+
RubDev::C.udev_monitor_get_fd(@pointer)
|
48
69
|
end
|
49
70
|
|
50
71
|
def receive_device
|
@@ -53,24 +74,24 @@ module RubDev
|
|
53
74
|
}
|
54
75
|
end
|
55
76
|
|
56
|
-
def
|
57
|
-
|
58
|
-
i.instance_variable_set(:@pointer, RubDev::C.udev_monitor_get_udev(@pointer))
|
59
|
-
}
|
77
|
+
def filter_add_match_subsystem_devtype (subsystem, devtype=nil)
|
78
|
+
RubDev::C.udev_monitor_filter_add_match_subsystem_devtype(@pointer, subsystem, devtype)
|
60
79
|
end
|
61
80
|
|
62
|
-
def
|
63
|
-
RubDev::C.
|
64
|
-
self
|
81
|
+
def filter_add_match_tag (tag)
|
82
|
+
RubDev::C.udev_monitor_filter_add_match_tag(@pointer, tag)
|
65
83
|
end
|
66
84
|
|
67
|
-
def
|
68
|
-
RubDev::C.
|
69
|
-
|
85
|
+
def filter_update
|
86
|
+
RubDev::C.udev_monitor_filter_update(@pointer)
|
87
|
+
end
|
88
|
+
|
89
|
+
def filter_remove
|
90
|
+
RubDev::C.udev_monitor_filter_remove(@pointer)
|
70
91
|
end
|
71
92
|
|
72
93
|
def to_io
|
73
|
-
IO.for_fd(
|
94
|
+
IO.for_fd(fd)
|
74
95
|
end
|
75
96
|
end
|
76
97
|
end
|
data/lib/rubdev/queue.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of rubdev.
|
5
|
+
#
|
6
|
+
# rubdev is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# rubdev is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with rubdev. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'rubdev/c'
|
21
|
+
require 'rubdev/context'
|
22
|
+
require 'rubdev/list'
|
23
|
+
|
24
|
+
module RubDev
|
25
|
+
class Queue
|
26
|
+
def ref
|
27
|
+
RubDev::C.udev_queue_ref(@pointer)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def unref
|
32
|
+
RubDev::C.udev_queue_unref(@pointer)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def context
|
37
|
+
Context.allocate.tap {|i|
|
38
|
+
i.instance_variable_set(:@pointer, RubDev::C.udev_queue_get_udev(@pointer))
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize (context)
|
43
|
+
raise ArgumentError, "argument is NOT a RubDev::Context" unless context.is_a?(Context)
|
44
|
+
|
45
|
+
@pointer = RubDev::C.udev_queue_new(context.to_c)
|
46
|
+
end
|
47
|
+
|
48
|
+
def active?
|
49
|
+
!RubDev::C.udev_queue_get_udev_is_active(@pointer).zero?
|
50
|
+
end
|
51
|
+
|
52
|
+
def empty?
|
53
|
+
!RubDev::C.udev_queue_get_queue_is_empty(@pointer).zero?
|
54
|
+
end
|
55
|
+
|
56
|
+
def seqnum_finished? (seqnum)
|
57
|
+
!RubDev::C.udev_queue_get_seqnum_is_finished(@pointer, seqnum).zero?
|
58
|
+
end
|
59
|
+
|
60
|
+
def seqnum_sequence_finished? (start, stop)
|
61
|
+
!RubDev::C.udev_queue_get_seqnum_sequence_is_finished(@pointer, start, stop).zero?
|
62
|
+
end
|
63
|
+
|
64
|
+
def queued
|
65
|
+
List.new(RubDev::C.udev_queue_get_queued_list_entry(@pointer))
|
66
|
+
end
|
67
|
+
|
68
|
+
def failed
|
69
|
+
List.new(RubDev::C.udev_queue_get_failed_list_entry(@pointer))
|
70
|
+
end
|
71
|
+
|
72
|
+
def kernel_seqnum
|
73
|
+
RubDev::C.udev_queue_get_kernel_seqnum(@pointer)
|
74
|
+
end
|
75
|
+
|
76
|
+
def udev_seqnum
|
77
|
+
RubDev::C.udev_queue_get_udev_seqnum(@pointer)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/rubdev.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubdev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- shura
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-29 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -40,8 +40,11 @@ extra_rdoc_files: []
|
|
40
40
|
|
41
41
|
files:
|
42
42
|
- lib/rubdev/c.rb
|
43
|
+
- lib/rubdev/list.rb
|
43
44
|
- lib/rubdev/monitor.rb
|
44
45
|
- lib/rubdev/context.rb
|
46
|
+
- lib/rubdev/enumerate.rb
|
47
|
+
- lib/rubdev/queue.rb
|
45
48
|
- lib/rubdev/device.rb
|
46
49
|
- lib/rubdev.rb
|
47
50
|
has_rdoc: true
|
@@ -64,13 +67,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
68
|
none: false
|
66
69
|
requirements:
|
67
|
-
- - "
|
70
|
+
- - ">="
|
68
71
|
- !ruby/object:Gem::Version
|
69
72
|
segments:
|
70
|
-
-
|
71
|
-
|
72
|
-
- 1
|
73
|
-
version: 1.3.1
|
73
|
+
- 0
|
74
|
+
version: "0"
|
74
75
|
requirements: []
|
75
76
|
|
76
77
|
rubyforge_project:
|