Module: Libvirt::FFI::Storage

Extended by:
FFI::Library, Helpers
Defined in:
lib/libvirt/ffi/storage.rb

Defined Under Namespace

Classes: PoolInfoStruct, VolumeInfoStruct

Constant Summary collapse

EVENT_ID_TO_CALLBACK =
{
    LIFECYCLE: :virConnectStoragePoolEventLifecycleCallback,
    REFRESH: :virConnectStoragePoolEventGenericCallback
}.freeze

Class Method Summary collapse

Methods included from Helpers

callback_function

Class Method Details

.event_callback_for(event_id) { ... } ⇒ FFI::Function

Creates event callback function for provided event_id

Parameters:

  • event_id (Integer, Symbol)

Yields:

  • connect_ptr, pool_ptr, *args, opaque_ptr

Returns:

  • (FFI::Function)


223
224
225
226
227
228
229
230
231
# File 'lib/libvirt/ffi/storage.rb', line 223

def event_callback_for(event_id, &block)
  event_id_sym = event_id.is_a?(Symbol) ? event_id : enum_type(:event_id)[event_id]

  callback_name = EVENT_ID_TO_CALLBACK.fetch(event_id_sym)
  callback_function(callback_name) do |*args|
    Util.log(:debug, name) { ".event_callback_for #{event_id_sym} CALLBACK #{args.map(&:to_s).join(', ')}," }
    block.call(*args)
  end
end