Module: InotifyCtypes

Included in:
Inotify
Defined in:
lib/inotify.rb

Overview

The basic ctypes for every function required by inotify

Instance Method Summary collapse

Instance Method Details

#inotify_add_watch(fd, path, mask) ⇒ Object

Add a path to the inotify watch.



129
130
131
# File 'lib/inotify.rb', line 129

def inotify_add_watch(fd, path, mask)
  $__inotify_add_watch.call(fd, path, mask)
end

#inotify_close(fd) ⇒ Object

Close inotify file descriptor.



148
149
150
# File 'lib/inotify.rb', line 148

def inotify_close(fd)
  $__close.call(fd)
end

#inotify_event(buffer) ⇒ Object

Parse the result of read on an inotify file descriptor.



112
113
114
115
116
117
118
119
120
121
# File 'lib/inotify.rb', line 112

def inotify_event(buffer)
  wd, mask, cookie, len, name = buffer.unpack("lLLLZ*")
  event = Hash.new
  event["wd"]     = wd
  event["mask"]   = mask
  event["cookie"] = cookie
  event["len"]    = len
  event["name"]   = name
  event
end

#inotify_initObject

Open inotify file descriptor.



124
125
126
# File 'lib/inotify.rb', line 124

def inotify_init
  $__inotify_init.call
end

#inotify_read(fd) ⇒ Object

Allocate a buffer, call read and then parse the result.



139
140
141
142
143
144
145
# File 'lib/inotify.rb', line 139

def inotify_read(fd)
  max_len = 20 + 1024 + 1
  cbuff = Fiddle::Pointer.malloc(max_len)
  max_len.times { |index| cbuff[index] = 0 }
  len = $__read.call(fd, cbuff, max_len)
  inotify_event(cbuff.to_s(len))
end

#inotify_rm_watch(fd, wd) ⇒ Object

Remove a watch descriptor from the inotify watch.



134
135
136
# File 'lib/inotify.rb', line 134

def inotify_rm_watch(fd, wd)
  $__inotify_rm_watch.call(fd, wd)
end