lib/virtualbox/com/ffi/interface.rb in virtualbox-0.8.6 vs lib/virtualbox/com/ffi/interface.rb in virtualbox-0.9.0

- old
+ new

@@ -1,58 +1,38 @@ require 'ffi' module VirtualBox module COM module FFI - extend ::FFI::Library - - # FFI specific types - NSRESULT_TYPE = :uint - - # Creates all the FFI classes for a given version. - def self.for_version(version, &block) - @__module = Module.new - ::VirtualBox::COM::Util.set_interface_version(version) - const_set(::VirtualBox::COM::Util.version_const, @__module) - instance_eval(&block) - @__module = Kernel - end - - # Returns a Class which creates an FFI interface to the specified - # com interface and potentially a parent class as well. - def self.create_interface(interface, parent=nil) - klass = Class.new(Interface) - @__module.const_set(interface, klass) - klass.com_interface(interface, parent) - klass - end - # Represents a VirtualBox XPCOM C interface, which is a C struct # which emulates an object (a struct with function pointers # and getters/setters). This class does **a lot** of magic which pretty # much represents everything wrong about ruby programmers, but keep # in mind it is well tested and well commented, and the meta-programming # was done out of a need to keep things DRY between Windows and Unix # operating systems. class Interface extend ::FFI::Library + # FFI specific types + NSRESULT_TYPE = :uint + attr_reader :vtbl_parent attr_reader :vtbl class << self # Sets up the args to the FFI::Struct `layout` method. This # method defines all the callbacks necessary for working with # FFI and also sets up any layout args to send in. The way the # XPCOM C structs are setup, the properties are first, in # `GetFoo` and `SetFoo` format. And the functions are next. They are # put into the struct in the order defined in the {AbstractInterface}. - def com_interface(interface, parent=nil) + def com_interface(interface) # Create the parent class and vtbl class interface = ::VirtualBox::COM::Util.versioned_interface(interface) define_vtbl_parent_for_interface(interface) - define_vtbl_for_interface(interface, parent) + define_vtbl_for_interface(interface) end # Creates the parent of the vtbl class associated with a given # interface. def define_vtbl_parent_for_interface(interface) @@ -62,11 +42,14 @@ # Set the constant const_set("VtblParent", @vtbl_parent_klass) end # Creates the vtbl class associated with a given interface. - def define_vtbl_for_interface(interface, parent=nil) + def define_vtbl_for_interface(interface) + # Get the parent for the interface + parent = interface.get_parent + # Define the properties, then the functions, since thats the order # the FFI structs are in layout_args.clear define_interface_parent(parent) define_interface_properties(interface) @@ -86,10 +69,10 @@ # # @param [Symbol] parent The name of the parent represented by a symbol def define_interface_parent(parent) return if parent.nil? - parent_klass = Object.module_eval("::VirtualBox::COM::FFI::#{::VirtualBox::COM::Util.version_const}::#{parent}::Vtbl") + parent_klass = Util.versioned_interface(parent).const_get("Vtbl") layout_args << [:superklass, parent_klass] end # Defines all the properties on a com interface. def define_interface_properties(interface)