Class: Hakuban::ObjectDescriptorCallbackEventQueue

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

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ ObjectDescriptorCallbackEventQueue

Returns a new instance of ObjectDescriptorCallbackEventQueue.



12
13
14
# File 'lib/hakuban/event-queue.rb', line 12

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



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

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



31
32
33
34
# File 'lib/hakuban/event-queue.rb', line 31

def callback_unregister
  @callback_pointer.free
  @callback_pointer = nil
end

#dropObject



37
38
39
40
# File 'lib/hakuban/event-queue.rb', line 37

def drop
  @events_pointer.free
  @events_pointer = nil
end