Class: VirtualBox::COM::XPCOMC::Implementer

Inherits:
Object
  • Object
show all
Defined in:
lib/virtualbox/com/xpcomc-ffi/implementer.rb

Overview

Implementer is a wrapper for the Binding class. Performs lazy initialisation and enhance function call

Constant Summary collapse

EXCEPTION_MAP =
Hash.new(COMException).merge!({
    0x8000_4001 => NotImplementedException,
    0x8000_4002 => NoInterfaceException,
    0x80BB_0001 => ObjectNotFoundException,
    0x80BB_0002 => InvalidVMStateException,
    0x80BB_0003 => VMErrorException,
    0x80BB_0004 => FileErrorException,
    0x80BB_0005 => SubsystemException,
    0x80BB_0006 => PDMException,
    0x80BB_0007 => InvalidObjectStateException,
    0x80BB_0008 => HostErrorException,
    0x80BB_0009 => NotSupportedException,
    0x80BB_000A => XMLErrorException,
    0x80BB_000B => InvalidSessionStateException,
    0x80BB_000C => ObjectInUseException,
    0x8007_0057 => InvalidArgException
}).freeze

Instance Method Summary collapse

Constructor Details

#initialize(interface, pointer) ⇒ Implementer

Initialize implementation of the COM interface



28
29
30
31
32
33
34
# File 'lib/virtualbox/com/xpcomc-ffi/implementer.rb', line 28

def initialize(interface, pointer)
    unless interface.kind_of?(AbstractInterface)
        raise ArgumentError, "only COM interface can be implemented"
    end
    @interface = interface	# For lazy creation of the
    @pointer   = pointer	#  "binding" attribute
end

Instance Method Details

#call_function(spec, *args) ⇒ Object

Calls a function



65
66
67
68
69
70
# File 'lib/virtualbox/com/xpcomc-ffi/implementer.rb', line 65

def call_function(spec, *args)
    binding.call(spec.name,   *args)
rescue COMException => e
    e.data.merge!(:function => spec.name, :mode => :call)
    raise EXCEPTION_MAP[e.data[:code]], e.data
end

#cast(interface, pointer) ⇒ Object

Cast to another interface. Will raise NoInterfaceException if not supported



40
41
42
43
44
45
46
# File 'lib/virtualbox/com/xpcomc-ffi/implementer.rb', line 40

def cast(interface, pointer)
    iid = Binding.get(interface)::IID
    Model.create(interface, binding.call(:QueryInterface, iid))
rescue COMException => e
    e.data.merge!(:mode => :cast)
    raise EXCEPTION_MAP[e.data[:code]], e.data
end

#objectObject




75
76
77
# File 'lib/virtualbox/com/xpcomc-ffi/implementer.rb', line 75

def object
    binding.object
end

#read_property(spec) ⇒ Object

Reads a property



49
50
51
52
53
54
# File 'lib/virtualbox/com/xpcomc-ffi/implementer.rb', line 49

def read_property(spec)
    binding.call(spec.getter)
rescue COMException => e
    e.data.merge!(:property => spec.name, :mode => :read)
    raise EXCEPTION_MAP[e.data[:code]], e.data
end

#write_property(spec, value) ⇒ Object

Writes a property



57
58
59
60
61
62
# File 'lib/virtualbox/com/xpcomc-ffi/implementer.rb', line 57

def write_property(spec, value)
    binding.call(spec.setter, [value])
rescue COMException => e
    e.data.merge!(:property => spec.name, :mode => :write)
    raise EXCEPTION_MAP[e.data[:code]], e.data
end