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 CHANGED
@@ -3,6 +3,7 @@ doc/*
3
3
  pkg/*
4
4
  test/coverage/*
5
5
  .bundle/*
6
+ vendor/*
6
7
  Gemfile.lock
7
8
  test.rb
8
- *.rbc
9
+ *.rbc
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)
@@ -15,6 +15,12 @@ module COM
15
15
  raise ModelNotFoundException, name
16
16
  end
17
17
 
18
+ def self.fetch(name)
19
+ self.const_get(name, false)
20
+ rescue NameError
21
+ nil
22
+ end
23
+
18
24
  def self.create(name, *args)
19
25
  self.get(name).new(*args)
20
26
  end
@@ -1,9 +1,35 @@
1
- require_relative '4.2-gen'
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 getEvent(*args)
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
@@ -35,82 +35,97 @@ module Util
35
35
  end
36
36
 
37
37
  CAMELCASE_SPECIALS = { # Order is important
38
- "fourcc_rgb" => "FOURCC_RGB",
39
- "am79c970a" => "Am79C970A",
40
- "am79c973" => "Am79C973",
41
- "i82540em" => "I82540EM",
42
- "i82543gc" => "I82543GC",
43
- "i82545em" => "I82545EM",
44
- "efidual" => "EFIDUAL",
45
- "split2g" => "Split2G",
46
- "cpuid" => "CPUID",
47
- "cdrom" => "CDROM",
48
- "efi32" => "EFI32",
49
- "efi64" => "EFI64",
50
- "piix3" => "PIIX3",
51
- "piix4" => "PIIX4",
52
- "winmm" => "WinMM",
53
- "ac97" => "AC97",
54
- "acpi" => "ACPI",
55
- "alsa" => "ALSA",
56
- "apic" => "APIC",
57
- "bios" => "BIOS",
58
- "csam" => "CSAM",
59
- "dhcp" => "DHCP",
60
- "fifo" => "FIFO",
61
- "ich6" => "ICH6",
62
- "ich9" => "ICH9",
63
- "macs" => "MACs",
64
- "mmpm" => "MMPM",
65
- "patm" => "PATM",
66
- "sata" => "SATA",
67
- "sb16" => "SB16",
68
- "scsi" => "SCSI",
69
- "slip" => "SLIP",
70
- "tftp" => "TFTP",
71
- "vbox" => "VBox",
72
- "vpid" => "VPID",
73
- "vram" => "VRAM",
74
- "vrde" => "VRDE",
75
- "vrdp" => "VRDP",
76
- "api" => "API",
77
- "cpu" => "CPU",
78
- "dns" => "DNS",
79
- "dvd" => "DVD",
80
- "efi" => "EFI",
81
- "esx" => "ESX",
82
- "gid" => "GID",
83
- "hda" => "HDA",
84
- "hdd" => "HDD",
85
- "ide" => "IDE",
86
- "irq" => "IRQ",
87
- "mac" => "MAC",
88
- "nat" => "NAT",
89
- "oss" => "OSS",
90
- "pae" => "PAE",
91
- "pci" => "PCI",
92
- "pid" => "PID",
93
- "png" => "PNG",
94
- "ppp" => "PPP",
95
- "ps2" => "PS2",
96
- "pxe" => "PXE",
97
- "ram" => "RAM",
98
- "rtc" => "RTC",
99
- "sas" => "SAS",
100
- "svc" => "SVC",
101
- "tcp" => "TCP",
102
- "udp" => "UDP",
103
- "uid" => "UID",
104
- "usb" => "USB",
105
- "utc" => "UTC",
106
- "vdi" => "VDI",
107
- "vfs" => "VFS",
108
- "3d" => "3D",
109
- "hw" => "HW",
110
- "io" => "IO",
111
- "ip" => "IP",
112
- "os" => "OS",
113
- "vm" => "VM",
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
@@ -1,5 +1,5 @@
1
1
  module VirtualBox
2
2
  module COM
3
- VERSION = "0.9.6"
3
+ VERSION = "0.9.7"
4
4
  end
5
5
  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.to_ffi, :uint) }
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.retrieve_values(ffi_args)
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
- # private
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("::").last
85
+ name = @interface.class.name.split('::').last
79
86
  Binding.get(name).new(@pointer)
80
87
  end
81
88
  end