Class: VirtualBox::COM::Implementer::MSCOM
- Inherits:
-
Base
show all
- Defined in:
- lib/virtualbox/com/implementer/mscom.rb
Instance Attribute Summary collapse
#interface, #lib
Instance Method Summary
collapse
-
#call_function(name, args, opts) ⇒ Object
Calls a function from the interface with the given name.
-
#initialize(interface, lib_base, object) ⇒ MSCOM
constructor
Initializes the MSCOM implementer.
-
#read_array_of_interface(value, type) ⇒ Object
-
#read_array_of_unicode_string(value, type) ⇒ Object
-
#read_char(value, type) ⇒ Object
-
#read_enum(value, type) ⇒ Object
-
#read_int(value, type) ⇒ Object
-
#read_interface(value, type) ⇒ Object
-
#read_long(value, type) ⇒ Object
-
#read_property(name, opts) ⇒ Object
Reads a property from the interface with the given name.
-
#read_uint(value, type) ⇒ Object
-
#read_ulong(value, type) ⇒ Object
-
#read_unicode_string(value, type) ⇒ Object
-
#read_ushort(value, type) ⇒ Object
-
#returnable_value(value, type) ⇒ Object
Takes a value (returned from a WIN32OLE object) and a type and converts to a proper ruby return value type.
-
#single_type_to_arg(args, item, results) ⇒ Object
Converts a single type and args list to the proper formal args list.
-
#spec_to_args(spec, args) ⇒ Object
Takes a function spec and an argument list.
-
#write_property(name, value, opts) ⇒ Object
Writes a property from the interface with the given name and value.
Methods inherited from Base
#infer_type, #interface_klass, #ruby_version
Methods included from Logger
included, #logger, #logger_output=
Constructor Details
#initialize(interface, lib_base, object) ⇒ MSCOM
Initializes the MSCOM implementer.
13
14
15
16
17
18
19
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 13
def initialize(interface, lib_base, object)
super(interface, lib_base)
@object = object
require 'java' if Platform.jruby?
end
|
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
7
8
9
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 7
def object
@object
end
|
Instance Method Details
#call_function(name, args, opts) ⇒ Object
Calls a function from the interface with the given name
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 51
def call_function(name, args, opts)
jruby_exception = nil
jruby_exception = org.racob.com.ComFailException if Platform.jruby?
args = spec_to_args(opts[:spec], args)
value = nil
begin
value = @object.send(COM::FFI::Util.camelize(name.to_s), *args)
rescue jruby_exception
raise Exceptions::COMException.new(:function => name,
:result_code => 0)
end
returnable_value(value, opts[:value_type])
end
|
#read_array_of_interface(value, type) ⇒ Object
195
196
197
198
199
200
201
202
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 195
def read_array_of_interface(value, type)
klass = interface_klass(type.first)
value.collect do |item|
if !item.nil?
klass.new(self.class, lib, item)
end
end
end
|
#read_array_of_unicode_string(value, type) ⇒ Object
190
191
192
193
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 190
def read_array_of_unicode_string(value, type)
value
end
|
#read_char(value, type) ⇒ Object
156
157
158
159
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 156
def read_char(value, type)
!(value.to_s == "0")
end
|
#read_enum(value, type) ⇒ Object
181
182
183
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 181
def read_enum(value, type)
interface_klass(type)[value]
end
|
#read_int(value, type) ⇒ Object
173
174
175
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 173
def read_int(value, type)
value.to_i
end
|
#read_interface(value, type) ⇒ Object
185
186
187
188
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 185
def read_interface(value, type)
return nil if value.nil?
interface_klass(type).new(self.class, lib, value)
end
|
#read_long(value, type) ⇒ Object
177
178
179
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 177
def read_long(value, type)
value.to_i
end
|
#read_property(name, opts) ⇒ Object
Reads a property from the interface with the given name.
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 22
def read_property(name, opts)
method = COM::FFI::Util.camelize(name.to_s)
value = if ruby_version >= 1.9
@object.send(method)
else
@object[method]
end
returnable_value(value, opts[:value_type])
end
|
#read_uint(value, type) ⇒ Object
165
166
167
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 165
def read_uint(value, type)
value.to_i
end
|
#read_ulong(value, type) ⇒ Object
169
170
171
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 169
def read_ulong(value, type)
value.to_i
end
|
#read_unicode_string(value, type) ⇒ Object
151
152
153
154
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 151
def read_unicode_string(value, type)
value
end
|
#read_ushort(value, type) ⇒ Object
161
162
163
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 161
def read_ushort(value, type)
value.to_i
end
|
#returnable_value(value, type) ⇒ Object
Takes a value (returned from a WIN32OLE object) and a type and converts to a proper ruby return value type.
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 140
def returnable_value(value, type)
return nil if type.nil? || type == :void
klass = type.is_a?(Array) ? type.first : type
ignore, inferred_type = infer_type(klass)
array_of = type.is_a?(Array) ? "array_of_" : ""
send("read_#{array_of}#{inferred_type}", value, type)
end
|
#single_type_to_arg(args, item, results) ⇒ Object
Converts a single type and args list to the proper formal args list
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 99
def single_type_to_arg(args, item, results)
if item.is_a?(Array) && item.length == 1
data = args.shift
results << data.inject([]) do |converted_data, single|
single_type_to_arg([single], item[0], converted_data)
end
elsif item.to_s[0,1] == item.to_s[0,1].upcase
interface = interface_klass(item.to_sym)
if interface.superclass == COM::AbstractInterface
instance = args.shift
results << if !instance.nil?
instance.implementer.object
else
nil
end
elsif interface.superclass == COM::AbstractEnum
results << interface.index(args.shift.to_sym)
end
elsif item == T_BOOL
results << (args.shift ? 1 : 0)
else
results << args.shift
end
end
|
#spec_to_args(spec, args) ⇒ Object
Takes a function spec and an argument list. This handles properly converting enums to ints and AbstractInterfaces to proper MSCOM interfaces.
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 80
def spec_to_args(spec, args)
args = args.dup
spec = spec.collect do |item|
if item.is_a?(Array) && item[0] == :out
nil
else
item
end
end.compact
spec = spec.inject([]) do |results, item|
single_type_to_arg(args, item, results)
end
end
|
#write_property(name, value, opts) ⇒ Object
Writes a property from the interface with the given name and value.
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/virtualbox/com/implementer/mscom.rb', line 38
def write_property(name, value, opts)
method = COM::FFI::Util.camelize(name.to_s)
value = spec_to_args([opts[:value_type]], [value]).first
if ruby_version >= 1.9
@object.send("#{method}=", value)
else
@object[method] = value
end
end
|