Class: VirtualBox::COM::AbstractInterface
- Inherits:
-
AbstractModel
- Object
- AbstractModel
- VirtualBox::COM::AbstractInterface
- Defined in:
- lib/virtualbox/com/xpcomc-ffi/abstracts.rb,
lib/virtualbox/com/abstracts.rb,
ext/virtualbox-com/4.2/vbox.c,
ext/virtualbox-com/4.1/vbox.c,
ext/virtualbox-com/vbox.c
Overview
# Defining an Interface
Defining an interface is done by subclassing AbstractInterface and using the provided class methods to define the COM methods and properties. A small example class is shown below:
class Time < AbstractInterface
function :now, [[:out, :uint]]
property :hour, :uint
end
# Accessing an Interface
# Assume `time` was retrieved already
puts time.foo.to_s
time.hour = 20
x = time.now
The above example shows how the properties and functions can be used with a given interface.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#implementer ⇒ Object
readonly
Returns the value of attribute implementer.
Class Method Summary collapse
-
.function(name, type, args, opts = {}) ⇒ Object
Adds a function to the interface.
-
.functions ⇒ Object
List of functions (Spec::Function).
-
.member(name) ⇒ Object
Get a member by name.
-
.members ⇒ Object
List of members (Spec::*).
-
.properties ⇒ Object
List if properties (Spec::Property).
-
.property(name, type, opts = {}) ⇒ Object
Adds a property to the interface.
Instance Method Summary collapse
-
#cast(name) ⇒ Object
Cast to another model.
-
#initialize(*args) ⇒ AbstractInterface
constructor
Initializes the interface with the given implementer.
-
#inspect ⇒ Object
Concise inspect.
Methods inherited from AbstractModel
Constructor Details
#initialize(*args) ⇒ AbstractInterface
Initializes the interface with the given implementer
84 85 86 87 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 84 def initialize(*args) @args = args @implementer = Implementer.new(self, *args) end |
Instance Attribute Details
#implementer ⇒ Object (readonly)
Returns the value of attribute implementer.
35 36 37 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 35 def implementer @implementer end |
Class Method Details
.function(name, type, args, opts = {}) ⇒ Object
Adds a function to the interface
39 40 41 42 43 44 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 39 def function(name, type, args, opts={}) h[name] = Spec::Function.new(name, type, args, opts) define_method(name) { |*args| @implementer.call_function(spec, *args) } unless spec.hide? end |
.functions ⇒ Object
List of functions (Spec::Function)
68 69 70 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 68 def functions members.select {|s| s.kind_of?(Spec::Function) } end |
.member(name) ⇒ Object
Get a member by name
58 59 60 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 58 def member(name) h[name] end |
.members ⇒ Object
List of members (Spec::*)
63 64 65 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 63 def members h.values end |
.properties ⇒ Object
List if properties (Spec::Property)
73 74 75 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 73 def properties members.select {|s| s.kind_of?(Spec::Property) } end |
.property(name, type, opts = {}) ⇒ Object
Adds a property to the interface
47 48 49 50 51 52 53 54 55 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 47 def property(name, type, opts={}) h[name] = Spec::Property.new(name, type, opts) define_method(name) { @implementer.read_property(spec) } unless spec.hide? define_method(:"#{name}=") { |value| @implementer.write_property(spec, value) } unless spec.hide? || spec.readonly? end |
Instance Method Details
#cast(name) ⇒ Object
Cast to another model
91 92 93 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 91 def cast(name) @implementer.cast(name, *@args) end |
#inspect ⇒ Object
Concise inspect
96 97 98 |
# File 'lib/virtualbox/com/xpcomc-ffi/abstracts.rb', line 96 def inspect "#<#{self.class.name}>" end |