Class: Honker::CoreWatcher
- Inherits:
-
Object
- Object
- Honker::CoreWatcher
- Defined in:
- lib/honker.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(db_path, extension_path, backend) ⇒ CoreWatcher
constructor
A new instance of CoreWatcher.
- #wait(timeout_s) ⇒ Object
Constructor Details
#initialize(db_path, extension_path, backend) ⇒ CoreWatcher
Returns a new instance of CoreWatcher.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/honker.rb', line 32 def initialize(db_path, extension_path, backend) @lib = Fiddle.dlopen(extension_path) @open = Fiddle::Function.new( @lib["honker_watcher_open"], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T], Fiddle::TYPE_VOIDP, ) @wait = Fiddle::Function.new( @lib["honker_watcher_wait"], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG_LONG], Fiddle::TYPE_INT, ) @close = Fiddle::Function.new( @lib["honker_watcher_close"], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID, ) err = "\0" * 1024 @handle = @open.call(db_path.to_s, backend.to_s, err, err.bytesize) return unless @handle.to_i.zero? raise ArgumentError, err.delete_suffix("\0").split("\0", 2).first end |
Instance Method Details
#close ⇒ Object
64 65 66 67 68 69 |
# File 'lib/honker.rb', line 64 def close return if @handle.nil? || @handle.to_i.zero? @close.call(@handle) @handle = nil end |
#wait(timeout_s) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/honker.rb', line 56 def wait(timeout_s) code = @wait.call(@handle, (timeout_s * 1000).ceil) return true if code == 1 return false if code == 0 raise Error, "honker update watcher closed or died" end |