Module: VirtualBox::COM::XPCOMC::Lib

Extended by:
FFI::Library
Defined in:
lib/virtualbox/com/xpcomc-ffi/lib.rb

Constant Summary collapse

SUPPORTED_VERSIONS =
{
    "4.2" => [ "3b2f08eb-b810-4715-bee0-bb06b9880ad2",
               "12F4DCDB-12B2-4EC1-B7CD-DDD9F6C5BF4D" ]
}
PATH =

Constant with default library path and name according to running plateform

case Util.platform
when :mac
    [ "/Applications/VirtualBox.app/Contents/MacOS",
      "/Applications/MacPorts/VirtualBox.app/Contents/MacOS" ]
when :linux
    [ "/opt/VirtualBox", 
      "/usr/lib/virtualbox",
      "/usr/lib64/virtualbox" ]
when :solaris
    [ "/opt/VirtualBox/amd64",
      "/opt/VirtualBox/i386" ]
when :freebsd
    [ "/usr/local/lib/virtualbox" ]
else 
    [ ]
end
NAME =
case Util.platform
when :max then "VBoxXPCOMC.dylib"
else           "VBoxXPCOMC.so"
end

Class Method Summary collapse

Class Method Details

.initObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/virtualbox/com/xpcomc-ffi/lib.rb', line 41

def self.init
    # Only once
    return if respond_to?(:VBoxGetXPCOMCFunctions)

    # Initialize lib and attach main function
    ffi_lib_flags(:now, :local)
    ffi_lib(ENV['VBOX_APP_HOME'] || PATH.map {|path| "#{path}/#{NAME}"})
    attach_function :VBoxGetXPCOMCFunctions, [:uint], :pointer


    # Get the pointer to the XPCOMC struct which contains the functions
    # to initialize
    xpcom_ptr = self.VBoxGetXPCOMCFunctions(XPCOMC::VERSION)
    @@xpcom = XPCOMC::VBox.new(xpcom_ptr)


    # Initializes the VirtualBox and Session interfaces.
    # It goes through the various supported interfaces.
    SUPPORTED_VERSIONS.each {|version, iids|
        virtualbox_iid_str, session_iid_str = iids

        # Setup the OUT pointers
        virtualbox_ptr = ::FFI::MemoryPointer.new(:pointer)
           session_ptr = ::FFI::MemoryPointer.new(:pointer)

        # Call the initialization functions
        @@xpcom[:pfnComInitialize].call(virtualbox_iid_str, virtualbox_ptr,
                                           session_iid_str,    session_ptr)

        # Read the pointers from the results 
        virtualbox_ptr = virtualbox_ptr.read_pointer
           session_ptr =    session_ptr.read_pointer

        # If either pointers are null it means that 
        # the initialization was not successful
        next if virtualbox_ptr.null? || session_ptr.null?

        # Load the interface description
        require "virtualbox/com/model/#{version}-generated"
        require "virtualbox/com/model/#{version}"

        #
        @@virtualbox = Model.create(:VirtualBox, virtualbox_ptr)
        @@session    = Model.create(:Session,       session_ptr)

        break
    }
end

.sessionObject



92
# File 'lib/virtualbox/com/xpcomc-ffi/lib.rb', line 92

def self.session    ; @@session    ; end

.virtualboxObject



91
# File 'lib/virtualbox/com/xpcomc-ffi/lib.rb', line 91

def self.virtualbox ; @@virtualbox ; end

.xpcomObject



90
# File 'lib/virtualbox/com/xpcomc-ffi/lib.rb', line 90

def self.xpcom      ; @@xpcom      ; end