class FChange::Watcher
is to be able to disable them using {#close}.
The main purpose of having Watcher objects
via {Notifier#run #run} or {Notifier#process #process}.
The Notifier actually takes care of the checking for events,
One {Notifier} may have many {Watcher}s.
A watcher is usually created via {Notifier#watch}.
specified by {FChange::Notifier#watch event flags}.
Watchers monitor a single path for changes,
def callback!(event)
-
event
(Event
) --
Other tags:
- Private: -
def callback!(event) @callback[event] end
def close
-
(SystemCallError)
- if the watch fails to be disabled for some reason
def close r = Native.FindCloseChangeNotification(@id) #@notifier.remove_watcher(self) return if r == 0 raise SystemCallError.new("Failed to stop watching #{@path.inspect}", r) end
def initialize(notifier, path, recursive, *flags, &callback)
- See: Notifier#watch -
Other tags:
- Private: -
def initialize(notifier, path, recursive, *flags, &callback) @notifier = notifier @callback = callback || proc {} @path = path @flags = flags @recursive = recursive ? 1 : 0 @id = Native.FindFirstChangeNotificationA(path, @recursive, Native::Flags.to_mask(flags)); @id = Native.FindFirstChangeNotificationW(normalize_path(path), @recursive, Native::Flags.to_mask(flags)); unless @id < 0 @notifier.add_watcher(self) return end raise SystemCallError.new("Failed to watch #{path.inspect}", @id) end
def normalize_path(path)
def normalize_path(path) if(path.size > 256) path = "\\\\?\\" + Pathname.new(path).realpath.to_s end require 'rchardet' require 'iconv' cd = CharDet.detect(path) encoding = cd['encoding'] converter = Iconv.new("UTF-16LE", encoding) converter.iconv(path) # path.encode!("UTF-16LE") end