rubdev 0.0.1a

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rubdev.rb ADDED
@@ -0,0 +1,22 @@
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/context'
21
+ require 'rubdev/monitor'
22
+ require 'rubdev/device'
data/lib/rubdev/c.rb ADDED
@@ -0,0 +1,65 @@
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 'ffi'
21
+
22
+ module RubDev
23
+ module C
24
+ extend FFI::Library
25
+
26
+ ffi_lib 'udev'
27
+
28
+ FFI.typedef(:ulong, :dev_t)
29
+
30
+ # context {{{
31
+ attach_function :udev_new, [], :pointer
32
+ # }}}
33
+
34
+ # monitor {{{
35
+ attach_function :udev_monitor_new_from_socket, [:pointer, :string], :pointer
36
+ attach_function :udev_monitor_new_from_netlink, [:pointer, :string], :pointer
37
+ attach_function :udev_monitor_filter_add_match_subsystem_devtype, [:pointer, :string, :string], :int
38
+ attach_function :udev_monitor_filter_add_match_tag, [:pointer, :string], :int
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
46
+ # }}}
47
+
48
+ # device {{{
49
+ attach_function :udev_device_get_devnode, [:pointer], :string
50
+ attach_function :udev_device_get_subsystem, [:pointer], :string
51
+ attach_function :udev_device_get_devtype, [:pointer], :string
52
+ attach_function :udev_device_get_action, [:pointer], :string
53
+ attach_function :udev_device_get_parent, [:pointer], :pointer
54
+ attach_function :udev_device_get_devpath, [:pointer], :string
55
+ attach_function :udev_device_get_syspath, [:pointer], :string
56
+ attach_function :udev_device_get_sysname, [:pointer], :string
57
+ attach_function :udev_device_get_sysnum, [:pointer], :string
58
+ attach_function :udev_device_get_driver, [:pointer], :string
59
+ attach_function :udev_device_get_devnum, [:pointer], :dev_t
60
+ attach_function :udev_device_get_property_value, [:pointer, :string], :string
61
+ attach_function :udev_device_ref, [:pointer], :void
62
+ attach_function :udev_device_unref, [:pointer], :void
63
+ # }}}
64
+ end
65
+ end
@@ -0,0 +1,32 @@
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 Context
24
+ def initialize
25
+ @pointer = RubDev::C.udev_new
26
+ end
27
+
28
+ def to_c
29
+ @pointer
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,88 @@
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 Device
24
+ class << self
25
+ private :new
26
+ end
27
+
28
+ def devnode
29
+ RubDev::C.udev_device_get_devnode(@pointer)
30
+ end
31
+
32
+ def subsystem
33
+ RubDev::C.udev_device_get_subsystem(@pointer)
34
+ end
35
+
36
+ def devtype
37
+ RubDev::C.udev_device_get_devtype(@pointer)
38
+ end
39
+
40
+ def action
41
+ RubDev::C.udev_device_get_action(@pointer)
42
+ end
43
+
44
+ def devpath
45
+ RubDev::C.udev_device_get_devpath(@pointer)
46
+ end
47
+
48
+ def syspath
49
+ RubDev::C.udev_device_get_syspath(@pointer)
50
+ end
51
+
52
+ def sysname
53
+ RubDev::C.udev_device_get_sysname(@pointer)
54
+ end
55
+
56
+ def sysnum
57
+ RubDev::C.udev_device_get_sysnum(@pointer)
58
+ end
59
+
60
+ def driver
61
+ RubDev::C.udev_device_get_driver(@pointer)
62
+ end
63
+
64
+ def devnum
65
+ RubDev::C.udev_device_get_devnum(@pointer)
66
+ end
67
+
68
+ def [] (what)
69
+ RubDev::C.udev_device_get_property_value(@pointer, what.to_s)
70
+ end
71
+
72
+ def ref
73
+ RubDev::C.udev_device_ref(@pointer)
74
+ self
75
+ end
76
+
77
+ def unref
78
+ RubDev::C.udev_device_unref(@pointer)
79
+ self
80
+ end
81
+
82
+ def parent
83
+ Device.allocate.tap {|i|
84
+ i.instance_variable_set(:@pointer, RubDev::C.udev_device_get_parent(@pointer))
85
+ }
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,76 @@
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/device'
23
+
24
+ module RubDev
25
+ class Monitor
26
+ class << self
27
+ private :new
28
+
29
+ def from_netlink (context, name)
30
+ self.allocate.tap {|i|
31
+ i.instance_variable_set(:@pointer, RubDev::C.udev_monitor_new_from_netlink(context.to_c, name))
32
+ }
33
+ end
34
+
35
+ def from_socket (context, path)
36
+ self.allocate.tap {|i|
37
+ i.instance_variable_set(:@pointer, RubDev::C.udev_monitor_new_from_socket(context.to_c, path))
38
+ }
39
+ end
40
+ end
41
+
42
+ def enable_receiving
43
+ RubDev::C.udev_monitor_enable_receiving(@pointer)
44
+ end
45
+
46
+ def filter_add_match_subsystem_devtype (subsystem, devtype=nil)
47
+ RubDev::C.udev_monitor_filter_add_match_subsystem_devtype(@pointer, subsystem, devtype)
48
+ end
49
+
50
+ def receive_device
51
+ Device.allocate.tap {|i|
52
+ i.instance_variable_set(:@pointer, RubDev::C.udev_monitor_receive_device(@pointer))
53
+ }
54
+ end
55
+
56
+ def context
57
+ Context.allocate.tap {|i|
58
+ i.instance_variable_set(:@pointer, RubDev::C.udev_monitor_get_udev(@pointer))
59
+ }
60
+ end
61
+
62
+ def ref
63
+ RubDev::C.udev_monitor_ref(@pointer)
64
+ self
65
+ end
66
+
67
+ def unref
68
+ RubDev::C.udev_monitor_unref(@pointer)
69
+ self
70
+ end
71
+
72
+ def to_io
73
+ IO.for_fd(RubDev::C.udev_monitor_get_fd(@pointer))
74
+ end
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubdev
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1a
9
+ version: 0.0.1a
10
+ platform: ruby
11
+ authors:
12
+ - shura
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-24 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ffi
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: libudev bindings
34
+ email: shura1991@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - lib/rubdev/c.rb
43
+ - lib/rubdev/monitor.rb
44
+ - lib/rubdev/context.rb
45
+ - lib/rubdev/device.rb
46
+ - lib/rubdev.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/shurizzle/rubdev
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">"
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 3
72
+ - 1
73
+ version: 1.3.1
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.7
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: libudev bindings
81
+ test_files: []
82
+