Class: Inotify
- Inherits:
-
Object
- Object
- Inotify
- Extended by:
- FFI::Library
- Defined in:
- lib/inotify/inotify_native.rb
Defined Under Namespace
Classes: Event, EventStruct
Constant Summary collapse
- MAX_NAME_SIZE =
4096
- ACCESS =
0x00000001
- MODIFY =
0x00000002
- ATTRIB =
0x00000004
- CLOSE_WRITE =
0x00000008
- CLOSE_NOWRITE =
0x00000010
- OPEN =
0x00000020
- MOVED_FROM =
0x00000040
- MOVED_TO =
0x00000080
- CREATE =
0x00000100
- DELETE =
0x00000200
- DELETE_SELF =
0x00000400
- MOVE_SELF =
0x00000800
- UNMOUNT =
Events sent by the kernel.
0x00002000
- Q_OVERFLOW =
0x00004000
- IGNORED =
0x00008000
- ONLYDIR =
0x01000000
- DONT_FOLLOW =
0x02000000
- MASK_ADD =
0x20000000
- ISDIR =
special flags
0x40000000
- ONESHOT =
0x80000000
- CLOSE =
helper events
(CLOSE_WRITE | CLOSE_NOWRITE)
- MOVE =
(MOVED_FROM | MOVED_TO)
- ALL_EVENTS =
All of the events
(ACCESS | MODIFY | ATTRIB | CLOSE_WRITE | \ CLOSE_NOWRITE | OPEN | MOVED_FROM | \ MOVED_TO | CREATE | DELETE | DELETE_SELF | MOVE_SELF)
Instance Method Summary collapse
- #add_watch(string, uint32) ⇒ Object
- #close ⇒ Object
- #each_event ⇒ Object
-
#initialize ⇒ Inotify
constructor
A new instance of Inotify.
- #read_event ⇒ Object
- #rm_watch(uint32) ⇒ Object
Constructor Details
#initialize ⇒ Inotify
Returns a new instance of Inotify.
46 47 48 49 |
# File 'lib/inotify/inotify_native.rb', line 46 def initialize @fd = self.inotify_init @io = FFI::IO.for_fd(@fd) end |
Instance Method Details
#add_watch(string, uint32) ⇒ Object
50 51 52 |
# File 'lib/inotify/inotify_native.rb', line 50 def add_watch(string, uint32) self.inotify_add_watch(@fd, string, uint32) end |
#close ⇒ Object
56 57 58 |
# File 'lib/inotify/inotify_native.rb', line 56 def close self.inotify_close(@fd) end |
#each_event ⇒ Object
59 60 61 62 63 64 |
# File 'lib/inotify/inotify_native.rb', line 59 def each_event loop do ready = IO.select([@io], nil, nil, nil) yield self.read_event end end |
#read_event ⇒ Object
65 66 67 68 69 70 |
# File 'lib/inotify/inotify_native.rb', line 65 def read_event buf = FFI::Buffer.alloc_out(EventStruct.size + MAX_NAME_SIZE, 1, false) ev = EventStruct.new(buf) n = self.read(@fd, buf, buf.total) Event.new(ev, buf) end |
#rm_watch(uint32) ⇒ Object
53 54 55 |
# File 'lib/inotify/inotify_native.rb', line 53 def rm_watch(uint32) self.inotify_rm_watch(@fd, uint32) end |