module Libvirt::FFI::Domain
Constants
- EVENT_ID_TO_CALLBACK
Public Class Methods
Creates event callback function for lifecycle event_id @param event_id_sym [Symbol] @yield connect_ptr, domain_ptr, event, detail, opaque_ptr @return [FFI::Function]
# File lib/libvirt/ffi/domain.rb, line 865 def self.event_callback(&block) callback_function(:virConnectDomainEventCallback) do |conn, dom, event, detail, opaque| detail_sym = event_detail_type(event, detail) Util.log(:debug) { "Libvirt::Domain LIFECYCLE CALLBACK #{conn}, #{dom}, #{event}, #{detail_sym}, #{opaque}," } block.call(conn, dom, event, detail_sym, opaque) 0 end end
Creates generic event callback function for provided event_id_sym @param event_id_sym [Symbol] @yield connect_ptr, domain_ptr, *args, opaque_ptr @return [FFI::Function]
# File lib/libvirt/ffi/domain.rb, line 853 def self.event_callback_base(event_id_sym, &block) callback_name = EVENT_ID_TO_CALLBACK.fetch(event_id_sym) callback_function(callback_name) do |*args| Util.log(:debug) { "Libvirt::Domain #{event_id_sym} CALLBACK #{args.map(&:to_s).join(', ')}," } block.call(*args) end end
Creates event callback function for provided event_id @param event_id [Integer,Symbol] @yield connect_ptr, domain_ptr, *args, opaque_ptr @return [FFI::Function]
# File lib/libvirt/ffi/domain.rb, line 838 def self.event_callback_for(event_id, &block) event_id_sym = event_id.is_a?(Symbol) ? event_id : enum_type(:event_id)[event_id] case event_id_sym when :LIFECYCLE event_callback(&block) else event_callback_base(event_id_sym, &block) end end
Converts detail from lifecycle callback from integer to symbol name. @param event [Symbol] enum :event_type (virDomainEventType) @param detail [Integer] @return [Symbol]
# File lib/libvirt/ffi/domain.rb, line 820 def self.event_detail_type(event, detail) detail_enum = enum_type(:"event_#{event.to_s.downcase}_detail_type") detail_enum[detail] end
Converts state reason of domain from integer to symbol name. @param state [Symbol] enum :state (virDomainState) @param reason [Integer] @return [Symbol]
# File lib/libvirt/ffi/domain.rb, line 829 def self.state_reason(state, reason) reason_enum = enum_type(:"#{state.to_s.downcase}_reason") reason_enum[reason] end