virtualbox-com 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/LICENSE +2 -2
- data/README.md +85 -0
- data/lib/virtualbox/com.rb +6 -0
- data/lib/virtualbox/com/model/4.2.rb +28 -2
- data/lib/virtualbox/com/util.rb +91 -76
- data/lib/virtualbox/com/version.rb +1 -1
- data/lib/virtualbox/com/xpcomc-ffi.rb +0 -20
- data/lib/virtualbox/com/xpcomc-ffi/binding.rb +16 -3
- data/lib/virtualbox/com/xpcomc-ffi/implementer.rb +9 -2
- data/lib/virtualbox/com/xpcomc-ffi/lib.rb +1 -0
- data/lib/virtualbox/com/xpcomc-ffi/model-types.rb +9 -8
- data/lib/virtualbox/com/xpcomc-ffi/sig.rb +205 -253
- data/lib/virtualbox/com/xpcomc-ffi/xpcomc-vbox.rb +18 -2
- data/scripts/xidl-conv.rb +4 -3
- data/virtualbox-com.gemspec +2 -2
- metadata +6 -5
- data/Readme.md +0 -59
- data/lib/virtualbox/com/model/4.2-gen.rb +0 -2720
data/.gitignore
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010 Mitchell Hashimoto.
|
1
|
+
Copyright (c) 2013 Stephane D'Alu / INSA-Lyon, 2010 Mitchell Hashimoto.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# VirtualBox-Com Ruby Gem
|
2
|
+
|
3
|
+
The `virtualbox-COM` ruby gem is a library which focus on the
|
4
|
+
direct mapping of the VirtualBox API and allows anyone to control
|
5
|
+
VirtualBox from ruby code! Create, destroy, start, stop, suspend, and
|
6
|
+
resume virtual machines. Also list virtual machines, list hard
|
7
|
+
drives, network devices, etc.
|
8
|
+
|
9
|
+
This is a simplified version (focusing on the VirtualBox API) of the
|
10
|
+
unmaintained [virtualbox](https://github.com/mitchellh/virtualbox) gem
|
11
|
+
by [Mitchell Hashimoto](https://github.com/mitchellh) from which
|
12
|
+
part of this code belongs.
|
13
|
+
|
14
|
+
|
15
|
+
## Installation and Requirements
|
16
|
+
|
17
|
+
First you need to install [VirtualBox](http://www.virtualbox.org/)
|
18
|
+
which is available for Windows, Linux, and OS X. After installation,
|
19
|
+
install the gem:
|
20
|
+
|
21
|
+
sudo gem install virtualbox-com
|
22
|
+
|
23
|
+
The gem uses the native COM interface which VirtualBox provides to
|
24
|
+
communicate with it. The gem uses Ruby-FFI to talk to the VirtualBox
|
25
|
+
dynamic library, and all the mapping as been generated from
|
26
|
+
the `VirtualBox.xidl`.
|
27
|
+
|
28
|
+
No configuration should be necessary to use this gem, but if
|
29
|
+
the dynamic library is not found, you can set the environment
|
30
|
+
variable `VBOX_APP_HOME` to the full library path.
|
31
|
+
|
32
|
+
|
33
|
+
## API Documentation
|
34
|
+
|
35
|
+
You can refer to the [VirtualBox SDK](https://www.virtualbox.org/sdkref/annotated.html)
|
36
|
+
knowning that in this gem
|
37
|
+
* classes are not prefixed with the `I` (`IMachine` => `Machine`)
|
38
|
+
* methods have been uncamelized (`canShowConsoleWindow` => `can_show_console_window`)
|
39
|
+
* when calling a method you only specify the in parameters, all the out (including the default return)
|
40
|
+
are being returned in an array if there is more than one, directly otherwise
|
41
|
+
|
42
|
+
|
43
|
+
## Basic Usage
|
44
|
+
require 'virtualbox-com'
|
45
|
+
|
46
|
+
lib = VirtualBox::COM
|
47
|
+
|
48
|
+
lib.virtualbox.machines.each {|vm|
|
49
|
+
puts "%s: %s" % [ vm.bame, vm.state ]
|
50
|
+
}
|
51
|
+
|
52
|
+
You can find more examples in the [`examples`](examples) directory
|
53
|
+
|
54
|
+
|
55
|
+
## Reporting Bugs or Feature Requests
|
56
|
+
|
57
|
+
Please use the [issue tracker](https://github.com/sdalu/virtualbox-com/issues).
|
58
|
+
|
59
|
+
|
60
|
+
## TODO
|
61
|
+
|
62
|
+
Improve documentation, re-implement a test-suite
|
63
|
+
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
If you'd like to contribute to VirtualBox, the first step to developing is to
|
68
|
+
clone this repo, get [bundler](http://github.com/carlhuda/bundler) if you
|
69
|
+
don't have it already, and do the following:
|
70
|
+
|
71
|
+
bundle install --relock
|
72
|
+
rake
|
73
|
+
|
74
|
+
This will run the test suite, which should come back all green! Then
|
75
|
+
you're good to go!
|
76
|
+
|
77
|
+
|
78
|
+
## Special Thanks
|
79
|
+
|
80
|
+
These folks went above and beyond with contributions to the virtualbox gem, and
|
81
|
+
for that, I have to say "thanks!"
|
82
|
+
|
83
|
+
* [Mitchell Hashimoto](https://github.com/mitchellh),
|
84
|
+
[Kieran Pilkington](https://github.com/KieranP),
|
85
|
+
[Aleksey Palazhchenko](https://github.com/AlekSi)
|
data/lib/virtualbox/com.rb
CHANGED
@@ -1,9 +1,35 @@
|
|
1
|
-
require_relative '4.2-
|
1
|
+
require_relative '4.2-generated'
|
2
|
+
require 'set'
|
2
3
|
|
3
4
|
module VirtualBox
|
4
5
|
module COM
|
5
6
|
module Model
|
6
7
|
|
8
|
+
|
9
|
+
class Machine < AbstractInterface
|
10
|
+
ONLINE_STATES = Set.new [ :running,
|
11
|
+
:paused,
|
12
|
+
:stuck,
|
13
|
+
:teleporting,
|
14
|
+
:live_snapshotting,
|
15
|
+
:starting,
|
16
|
+
:stopping,
|
17
|
+
:saving,
|
18
|
+
:restoring,
|
19
|
+
:teleporting_paused_vm,
|
20
|
+
:teleporting_in,
|
21
|
+
:fault_tolerant_syncing,
|
22
|
+
:deleting_snapshot_online,
|
23
|
+
:deleting_snapshot_paused,
|
24
|
+
]
|
25
|
+
|
26
|
+
def is_online?
|
27
|
+
ONLINE_STATES.include?(state)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
7
33
|
class Progress < AbstractInterface
|
8
34
|
# This method blocks the execution while the operations represented
|
9
35
|
# by this {Progress} object execute, but yields a block every `x`
|
@@ -84,7 +110,7 @@ class EventSource < AbstractInterface
|
|
84
110
|
:on_drag_and_drop_mode_changed => :DragAndDropModeChangedEvent,
|
85
111
|
}
|
86
112
|
|
87
|
-
def
|
113
|
+
def get_casted_event(*args)
|
88
114
|
if e = get_event(*args)
|
89
115
|
(model = MODEL_MAP[e.type]) ? e.cast(model) : e
|
90
116
|
end
|
data/lib/virtualbox/com/util.rb
CHANGED
@@ -35,82 +35,97 @@ module Util
|
|
35
35
|
end
|
36
36
|
|
37
37
|
CAMELCASE_SPECIALS = { # Order is important
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
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
|
-
"
|
89
|
-
"
|
90
|
-
"
|
91
|
-
"
|
92
|
-
"
|
93
|
-
"
|
94
|
-
"
|
95
|
-
"
|
96
|
-
"
|
97
|
-
"
|
98
|
-
"
|
99
|
-
"
|
100
|
-
"
|
101
|
-
"
|
102
|
-
"
|
103
|
-
"
|
104
|
-
"
|
105
|
-
"
|
106
|
-
"
|
107
|
-
"
|
108
|
-
"
|
109
|
-
"
|
110
|
-
"
|
111
|
-
"
|
112
|
-
"
|
113
|
-
"
|
38
|
+
"accelerate_2d" => "accelerate2D",
|
39
|
+
"accelerate_3d" => "accelerate3D",
|
40
|
+
"fourcc_rgb" => "FOURCC_RGB",
|
41
|
+
"screenshot" => "ScreenShot",
|
42
|
+
"am79c970a" => "Am79C970A",
|
43
|
+
"am79c973" => "Am79C973",
|
44
|
+
"i82540em" => "I82540EM",
|
45
|
+
"i82543gc" => "I82543GC",
|
46
|
+
"i82545em" => "I82545EM",
|
47
|
+
"efidual" => "EFIDUAL",
|
48
|
+
"split2g" => "Split2G",
|
49
|
+
"cpuid" => "CPUID",
|
50
|
+
"cdrom" => "CDROM",
|
51
|
+
"efi32" => "EFI32",
|
52
|
+
"efi64" => "EFI64",
|
53
|
+
"piix3" => "PIIX3",
|
54
|
+
"piix4" => "PIIX4",
|
55
|
+
"winmm" => "WinMM",
|
56
|
+
"ac97" => "AC97",
|
57
|
+
"acpi" => "ACPI",
|
58
|
+
"alsa" => "ALSA",
|
59
|
+
"apic" => "APIC",
|
60
|
+
"bios" => "BIOS",
|
61
|
+
"csam" => "CSAM",
|
62
|
+
"dhcp" => "DHCP",
|
63
|
+
"fifo" => "FIFO",
|
64
|
+
"hpet" => "HPET",
|
65
|
+
"ich6" => "ICH6",
|
66
|
+
"ich9" => "ICH9",
|
67
|
+
"ipv6" => "IPV6",
|
68
|
+
"macs" => "MACs",
|
69
|
+
"mmpm" => "MMPM",
|
70
|
+
"patm" => "PATM",
|
71
|
+
"sata" => "SATA",
|
72
|
+
"sb16" => "SB16",
|
73
|
+
"scsi" => "SCSI",
|
74
|
+
"slip" => "SLIP",
|
75
|
+
"tftp" => "TFTP",
|
76
|
+
"uuid" => "UUID",
|
77
|
+
"vbox" => "VBox",
|
78
|
+
"vpid" => "VPID",
|
79
|
+
"vram" => "VRAM",
|
80
|
+
"vrde" => "VRDE",
|
81
|
+
"vrdp" => "VRDP",
|
82
|
+
"acl" => "ACL",
|
83
|
+
"api" => "API",
|
84
|
+
"cad" => "CAD",
|
85
|
+
"cpu" => "CPU",
|
86
|
+
"dns" => "DNS",
|
87
|
+
"dvd" => "DVD",
|
88
|
+
"efi" => "EFI",
|
89
|
+
"esx" => "ESX",
|
90
|
+
"gid" => "GID",
|
91
|
+
"hda" => "HDA",
|
92
|
+
"hdd" => "HDD",
|
93
|
+
"hid" => "HID",
|
94
|
+
"ide" => "IDE",
|
95
|
+
"irq" => "IRQ",
|
96
|
+
"iso" => "ISO",
|
97
|
+
"mac" => "MAC",
|
98
|
+
"nat" => "NAT",
|
99
|
+
"oss" => "OSS",
|
100
|
+
"pae" => "PAE",
|
101
|
+
"pci" => "PCI",
|
102
|
+
"pid" => "PID",
|
103
|
+
"png" => "PNG",
|
104
|
+
"ppp" => "PPP",
|
105
|
+
"ps2" => "PS2",
|
106
|
+
"pxe" => "PXE",
|
107
|
+
"ram" => "RAM",
|
108
|
+
"rtc" => "RTC",
|
109
|
+
"sas" => "SAS",
|
110
|
+
"svc" => "SVC",
|
111
|
+
"tcp" => "TCP",
|
112
|
+
"udp" => "UDP",
|
113
|
+
"uid" => "UID",
|
114
|
+
"usb" => "USB",
|
115
|
+
"utc" => "UTC",
|
116
|
+
"vdi" => "VDI",
|
117
|
+
"vfs" => "VFS",
|
118
|
+
"2d" => "2D",
|
119
|
+
"3d" => "3D",
|
120
|
+
"gh" => "GH",
|
121
|
+
"hg" => "HG",
|
122
|
+
"hd" => "HD",
|
123
|
+
"hw" => "HW",
|
124
|
+
"io" => "IO",
|
125
|
+
"ip" => "IP",
|
126
|
+
"os" => "OS",
|
127
|
+
"vm" => "VM",
|
128
|
+
"vd" => "VD",
|
114
129
|
}
|
115
130
|
|
116
131
|
end
|
@@ -32,26 +32,6 @@ end
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
module VirtualBox
|
36
|
-
module COM
|
37
|
-
class AbstractInterface
|
38
|
-
def self.to_ffi
|
39
|
-
:pointer
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
module VirtualBox
|
47
|
-
module COM
|
48
|
-
class AbstractEnum
|
49
|
-
def self.to_ffi
|
50
|
-
UINT32
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
35
|
|
56
36
|
|
57
37
|
# Load FFI implementation
|
@@ -5,8 +5,20 @@ module XPCOMC
|
|
5
5
|
# The Binding class hold all the FFI infrastructure
|
6
6
|
class Binding
|
7
7
|
extend ::FFI::Library
|
8
|
+
|
8
9
|
attr_reader :object
|
9
10
|
|
11
|
+
def self.init
|
12
|
+
# To simplify code, use typedef for type aliasing
|
13
|
+
typedef :int, :boolean
|
14
|
+
typedef :pointer, :unicode_string
|
15
|
+
Model.constants.each {|c| m = Model.get(c)
|
16
|
+
if m <= AbstractInterface then typedef :pointer, c
|
17
|
+
elsif m <= AbstractEnum then typedef :uint32, c
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
10
22
|
|
11
23
|
# Retrieve a Binding class corresponding to the Model
|
12
24
|
# This will avoid polluting the model object with implementation data
|
@@ -24,6 +36,8 @@ class Binding
|
|
24
36
|
def self.bind(model)
|
25
37
|
raise "model already bound" if const_defined?(:Object, false)
|
26
38
|
|
39
|
+
# self.init
|
40
|
+
|
27
41
|
# List of functions (name, signature)
|
28
42
|
# Defined in the order they appear in the Model definition
|
29
43
|
sigs = model.members.inject({}) do |list, spec|
|
@@ -32,7 +46,7 @@ class Binding
|
|
32
46
|
const_set(:Sig, sigs)
|
33
47
|
|
34
48
|
# Register ffi callbacks
|
35
|
-
sigs.each {|name, sig| callback(name, sig.
|
49
|
+
sigs.each {|name, sig| callback(name, sig.to_ffi_callback, :uint) }
|
36
50
|
|
37
51
|
# Object layout
|
38
52
|
const_set(:Object, Class.new(::FFI::Struct))
|
@@ -47,7 +61,6 @@ class Binding
|
|
47
61
|
|
48
62
|
# Model
|
49
63
|
const_set(:Model, model)
|
50
|
-
|
51
64
|
self
|
52
65
|
end
|
53
66
|
|
@@ -78,7 +91,7 @@ class Binding
|
|
78
91
|
if (result & 0x8000_0000) != 0
|
79
92
|
raise COMException, :vtbl => name, :code => result
|
80
93
|
end
|
81
|
-
sig.
|
94
|
+
sig.read_values(ffi_args)
|
82
95
|
end
|
83
96
|
end
|
84
97
|
|
@@ -33,6 +33,7 @@ class Implementer
|
|
33
33
|
@pointer = pointer # "binding" attribute
|
34
34
|
end
|
35
35
|
|
36
|
+
#--[ Required by Model ]-----------------------------------------------
|
36
37
|
|
37
38
|
# Cast to another interface.
|
38
39
|
# Will raise NoInterfaceException if not supported
|
@@ -69,13 +70,19 @@ class Implementer
|
|
69
70
|
end
|
70
71
|
|
71
72
|
|
73
|
+
#----------------------------------------------------------------------
|
74
|
+
|
75
|
+
def object
|
76
|
+
binding.object
|
77
|
+
end
|
78
|
+
|
72
79
|
#--[ Private ]---------------------------------------------------------
|
73
|
-
|
80
|
+
private
|
74
81
|
|
75
82
|
# Lazy initialisation of the binding attribute
|
76
83
|
def binding
|
77
84
|
@binding ||= begin
|
78
|
-
name = @interface.class.name.split(
|
85
|
+
name = @interface.class.name.split('::').last
|
79
86
|
Binding.get(name).new(@pointer)
|
80
87
|
end
|
81
88
|
end
|