Class: Hakuban::ObjectDescriptorCallbackEventQueue
- Inherits:
-
Object
- Object
- Hakuban::ObjectDescriptorCallbackEventQueue
- Defined in:
- lib/hakuban/event-queue.rb
Instance Method Summary collapse
-
#callback_register(&callback) ⇒ Object
WARNING: this callback may be run from a separate, non-ruby, thread.
- #callback_unregister ⇒ Object
- #drop ⇒ Object
-
#initialize(pointer) ⇒ ObjectDescriptorCallbackEventQueue
constructor
A new instance of ObjectDescriptorCallbackEventQueue.
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_unregister ⇒ Object
33 34 35 36 |
# File 'lib/hakuban/event-queue.rb', line 33 def callback_unregister @callback_pointer.free @callback_pointer = nil end |
#drop ⇒ Object
39 40 41 42 |
# File 'lib/hakuban/event-queue.rb', line 39 def drop @events_pointer.free @events_pointer = nil end |