Class: Hakuban::ObjectDescriptorCallbackEventQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/hakuban/event-queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ ObjectDescriptorCallbackEventQueue



14
15
16
# File 'lib/hakuban/event-queue.rb', line 14

def initialize(pointer)
  @events_pointer = ::FFI::AutoPointer.new(pointer, proc { |ptr| FFI.hakuban_object_descriptor_events_return(ptr) })
end

Instance Method Details

#callback_register(&callback) ⇒ Object

WARNING: this callback may be run from a separate, non-ruby, thread



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hakuban/event-queue.rb', line 20

def callback_register(&callback)
  ffi_callback = proc { |_userdata, ffi_descriptor, ffi_action|
    action = Hakuban::action_int_to_symbol(ffi_action)
    descriptor = ObjectDescriptor.from_ffi(ffi_descriptor)
    callback.call(descriptor, action)
  }
  @callback_pointer = ::FFI::AutoPointer.new(
    FFI::hakuban_object_descriptor_events_callback_register(@events_pointer, ffi_callback, ::FFI::Pointer::NULL),
    proc { |ptr| FFI::hakuban_object_descriptor_events_callback_unregister(ptr) }
  )
end

#callback_unregisterObject



33
34
35
36
# File 'lib/hakuban/event-queue.rb', line 33

def callback_unregister
  @callback_pointer.free
  @callback_pointer = nil
end

#dropObject



39
40
41
42
# File 'lib/hakuban/event-queue.rb', line 39

def drop
  @events_pointer.free
  @events_pointer = nil
end