inotify-ffi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +8 -0
  2. data/inotify-ffi.gemspec +26 -0
  3. data/lib/inotify-ffi.rb +59 -0
  4. metadata +57 -0
@@ -0,0 +1,8 @@
1
+ # inotify-ffi
2
+
3
+ Blaten, unashamed rip-off of [samples/inotify.rb](http://github.com/ffi/ffi/blob/master/samples/inotify.rb)
4
+
5
+ Now a gem.
6
+
7
+ ## Install
8
+ gem install inotify-ffi
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+
5
+ s.name = 'inotify-ffi'
6
+ s.version = '0.1.0'
7
+ s.date = '2009-11-19'
8
+
9
+ s.description = "ffi interface for inotify"
10
+ s.summary = s.description
11
+
12
+ s.authors = ["Blake Mizerany"]
13
+ s.email = "blake.mizerany@gmail.com"
14
+
15
+ s.files = %w[
16
+ README.md
17
+ inotify-ffi.gemspec
18
+ lib/inotify-ffi.rb
19
+ ]
20
+
21
+ s.extra_rdoc_files = %w[README.md]
22
+
23
+ s.homepage = "http://github.com/bmizerany/inotify-ffi/"
24
+ s.require_paths = %w[lib]
25
+ s.rubygems_version = '1.1.1'
26
+ end
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'ffi'
3
+ module Inotify
4
+ extend FFI::Library
5
+ class Event < FFI::Struct
6
+ layout \
7
+ :wd, :int,
8
+ :mask, :uint,
9
+ :cookie, :uint,
10
+ :len, :uint
11
+ end
12
+ attach_function :init, :inotify_init, [ ], :int
13
+ attach_function :add_watch, :inotify_add_watch, [ :int, :string, :uint ], :int
14
+ attach_function :rm_watch, :inotify_rm_watch, [ :int, :uint ], :int
15
+ attach_function :read, [ :int, :buffer_out, :uint ], :int
16
+ IN_ACCESS=0x00000001
17
+ IN_MODIFY=0x00000002
18
+ IN_ATTRIB=0x00000004
19
+ IN_CLOSE_WRITE=0x00000008
20
+ IN_CLOSE_NOWRITE=0x00000010
21
+ IN_CLOSE=(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
22
+ IN_OPEN=0x00000020
23
+ IN_MOVED_FROM=0x00000040
24
+ IN_MOVED_TO=0x00000080
25
+ IN_MOVE= (IN_MOVED_FROM | IN_MOVED_TO)
26
+ IN_CREATE=0x00000100
27
+ IN_DELETE=0x00000200
28
+ IN_DELETE_SELF=0x00000400
29
+ IN_MOVE_SELF=0x00000800
30
+ # Events sent by the kernel.
31
+ IN_UNMOUNT=0x00002000
32
+ IN_Q_OVERFLOW=0x00004000
33
+ IN_IGNORED=0x00008000
34
+ IN_ONLYDIR=0x01000000
35
+ IN_DONT_FOLLOW=0x02000000
36
+ IN_MASK_ADD=0x20000000
37
+ IN_ISDIR=0x40000000
38
+ IN_ONESHOT=0x80000000
39
+ IN_ALL_EVENTS=(IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE \
40
+ | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM \
41
+ | IN_MOVED_TO | IN_CREATE | IN_DELETE \
42
+ | IN_DELETE_SELF | IN_MOVE_SELF)
43
+
44
+ end
45
+ if $0 == __FILE__
46
+ fd = Inotify.init
47
+ puts "fd=#{fd}"
48
+ wd = Inotify.add_watch(fd, "/tmp/", Inotify::IN_ALL_EVENTS)
49
+ fp = FFI::IO.for_fd(fd)
50
+ puts "wfp=#{fp}"
51
+ while true
52
+ buf = FFI::Buffer.alloc_out(Inotify::Event.size + 4096, 1, false)
53
+ ev = Inotify::Event.new buf
54
+ ready = IO.select([ fp ], nil, nil, nil)
55
+ n = Inotify.read(fd, buf, buf.total)
56
+ puts "Read #{n} bytes from inotify fd"
57
+ puts "event.wd=#{ev[:wd]} mask=#{ev[:mask]} len=#{ev[:len]} name=#{ev[:len] > 0 ? buf.get_string(16) : 'unknown'}"
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inotify-ffi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Blake Mizerany
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ffi interface for inotify
17
+ email: blake.mizerany@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.md
24
+ files:
25
+ - README.md
26
+ - inotify-ffi.gemspec
27
+ - lib/inotify-ffi.rb
28
+ has_rdoc: true
29
+ homepage: http://github.com/bmizerany/inotify-ffi/
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: ffi interface for inotify
56
+ test_files: []
57
+