gir_ffi 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/History.txt +14 -0
  2. data/TODO.rdoc +23 -5
  3. data/lib/ffi-glib/array.rb +14 -15
  4. data/lib/ffi-glib/container_class_methods.rb +0 -1
  5. data/lib/ffi-glib/hash_table.rb +3 -4
  6. data/lib/ffi-glib/ptr_array.rb +12 -4
  7. data/lib/ffi-glib/sized_array.rb +27 -7
  8. data/lib/ffi-gobject.rb +14 -15
  9. data/lib/ffi-gobject/closure.rb +1 -1
  10. data/lib/ffi-gobject/object.rb +40 -15
  11. data/lib/ffi-gobject/ruby_closure.rb +0 -1
  12. data/lib/ffi-gobject/value.rb +45 -21
  13. data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
  17. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
  18. data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
  19. data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
  20. data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
  21. data/lib/ffi-gobject_introspection/lib.rb +3 -0
  22. data/lib/gir_ffi-base.rb +3 -1
  23. data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
  24. data/lib/gir_ffi-base/glib/boolean.rb +13 -1
  25. data/lib/gir_ffi-base/gobject.rb +7 -0
  26. data/lib/gir_ffi-base/gobject/lib.rb +0 -2
  27. data/lib/gir_ffi.rb +1 -3
  28. data/lib/gir_ffi/arg_helper.rb +4 -85
  29. data/lib/gir_ffi/builder.rb +5 -5
  30. data/lib/gir_ffi/builder_helper.rb +7 -0
  31. data/lib/gir_ffi/builders/argument_builder.rb +132 -0
  32. data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
  33. data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
  34. data/lib/gir_ffi/builders/callback_builder.rb +38 -0
  35. data/lib/gir_ffi/builders/constant_builder.rb +18 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +62 -0
  37. data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
  38. data/lib/gir_ffi/builders/field_builder.rb +94 -0
  39. data/lib/gir_ffi/builders/function_builder.rb +123 -0
  40. data/lib/gir_ffi/builders/interface_builder.rb +29 -0
  41. data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
  42. data/lib/gir_ffi/builders/module_builder.rb +124 -0
  43. data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
  44. data/lib/gir_ffi/builders/null_builder.rb +11 -0
  45. data/lib/gir_ffi/builders/object_builder.rb +123 -0
  46. data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
  47. data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
  48. data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
  49. data/lib/gir_ffi/builders/signal_builder.rb +91 -0
  50. data/lib/gir_ffi/builders/struct_builder.rb +35 -0
  51. data/lib/gir_ffi/builders/type_builder.rb +40 -0
  52. data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
  53. data/lib/gir_ffi/builders/union_builder.rb +34 -0
  54. data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
  55. data/lib/gir_ffi/builders/with_layout.rb +55 -0
  56. data/lib/gir_ffi/builders/with_methods.rb +44 -0
  57. data/lib/gir_ffi/callback_base.rb +31 -0
  58. data/lib/gir_ffi/class_base.rb +16 -10
  59. data/lib/gir_ffi/enum_base.rb +8 -4
  60. data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
  61. data/lib/gir_ffi/in_out_pointer.rb +38 -39
  62. data/lib/gir_ffi/in_pointer.rb +33 -18
  63. data/lib/gir_ffi/info_ext.rb +0 -4
  64. data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
  66. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
  67. data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
  68. data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
  69. data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
  70. data/lib/gir_ffi/interface_base.rb +1 -1
  71. data/lib/gir_ffi/module_base.rb +5 -1
  72. data/lib/gir_ffi/object_base.rb +5 -1
  73. data/lib/gir_ffi/setter_argument_info.rb +4 -0
  74. data/lib/gir_ffi/signal_base.rb +21 -0
  75. data/lib/gir_ffi/struct_base.rb +24 -0
  76. data/lib/gir_ffi/type_base.rb +11 -0
  77. data/lib/gir_ffi/type_map.rb +4 -2
  78. data/lib/gir_ffi/union_base.rb +24 -0
  79. data/lib/gir_ffi/version.rb +1 -1
  80. data/tasks/test.rake +73 -7
  81. data/test/base_test_helper.rb +3 -19
  82. data/test/ffi-glib/array_test.rb +6 -0
  83. data/test/ffi-glib/ptr_array_test.rb +13 -0
  84. data/test/ffi-glib/ruby_closure_test.rb +7 -7
  85. data/test/ffi-glib/sized_array_test.rb +2 -2
  86. data/test/ffi-gobject/gobject_test.rb +3 -12
  87. data/test/ffi-gobject/object_test.rb +33 -2
  88. data/test/ffi-gobject/value_test.rb +114 -1
  89. data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
  90. data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
  91. data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
  92. data/test/ffi-gobject_test.rb +14 -14
  93. data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
  94. data/test/gir_ffi/arg_helper_test.rb +2 -122
  95. data/test/gir_ffi/builder_test.rb +67 -204
  96. data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
  97. data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
  98. data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
  99. data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
  100. data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
  101. data/test/gir_ffi/builders/field_builder_test.rb +94 -0
  102. data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
  103. data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
  104. data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
  105. data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
  106. data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
  107. data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
  108. data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
  109. data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
  110. data/test/gir_ffi/builders/union_builder_test.rb +29 -0
  111. data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
  112. data/test/gir_ffi/callback_base_test.rb +11 -0
  113. data/test/gir_ffi/class_base_test.rb +22 -22
  114. data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
  115. data/test/gir_ffi/in_out_pointer_test.rb +0 -7
  116. data/test/gir_ffi/in_pointer_test.rb +27 -3
  117. data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
  118. data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
  119. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
  120. data/test/gir_ffi/interface_base_test.rb +3 -5
  121. data/test/gir_ffi/object_base_test.rb +10 -6
  122. data/test/gir_ffi/type_map_test.rb +2 -2
  123. data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
  124. data/test/gir_ffi_test_helper.rb +12 -4
  125. data/test/integration/generated_gimarshallingtests_test.rb +436 -76
  126. data/test/integration/generated_gio_test.rb +5 -11
  127. data/test/integration/generated_gobject_test.rb +8 -0
  128. data/test/integration/generated_regress_test.rb +755 -309
  129. data/test/integration/generated_secret_test.rb +2 -1
  130. metadata +73 -72
  131. data/lib/ffi-gobject/ruby_style.rb +0 -23
  132. data/lib/gir_ffi/argument_builder.rb +0 -154
  133. data/lib/gir_ffi/builder/field.rb +0 -60
  134. data/lib/gir_ffi/builder/module.rb +0 -127
  135. data/lib/gir_ffi/builder/type.rb +0 -39
  136. data/lib/gir_ffi/builder/type/base.rb +0 -48
  137. data/lib/gir_ffi/builder/type/callback.rb +0 -30
  138. data/lib/gir_ffi/builder/type/constant.rb +0 -22
  139. data/lib/gir_ffi/builder/type/enum.rb +0 -66
  140. data/lib/gir_ffi/builder/type/interface.rb +0 -33
  141. data/lib/gir_ffi/builder/type/object.rb +0 -134
  142. data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
  143. data/lib/gir_ffi/builder/type/struct.rb +0 -34
  144. data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
  145. data/lib/gir_ffi/builder/type/union.rb +0 -34
  146. data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
  147. data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
  148. data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
  149. data/lib/gir_ffi/callback.rb +0 -72
  150. data/lib/gir_ffi/callback_helper.rb +0 -11
  151. data/lib/gir_ffi/error_argument_builder.rb +0 -17
  152. data/lib/gir_ffi/function_builder.rb +0 -112
  153. data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
  154. data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
  155. data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
  156. data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
  157. data/lib/gir_ffi/return_value_builder.rb +0 -81
  158. data/test/ffi-gobject/ruby_style_test.rb +0 -38
  159. data/test/gir_ffi/base_argument_builder_test.rb +0 -13
  160. data/test/gir_ffi/builder/type/callback_test.rb +0 -6
  161. data/test/gir_ffi/builder/type/constant_test.rb +0 -4
  162. data/test/gir_ffi/builder/type/union_test.rb +0 -12
  163. data/test/gir_ffi/callback_helper_test.rb +0 -10
  164. data/test/gir_ffi/callback_test.rb +0 -49
  165. data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
  166. data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -1,60 +0,0 @@
1
- require 'gir_ffi/argument_builder'
2
- require 'gir_ffi/return_value_builder'
3
- require 'gir_ffi/variable_name_generator'
4
- require 'gir_ffi/setter_argument_info'
5
-
6
- module GirFFI
7
- module Builder
8
- # Creates field getter and setter code for a given IFieldInfo.
9
- class Field
10
- def initialize field_info, lib_module, struct_class
11
- @info = field_info
12
- @libmodule = lib_module
13
- @struct_class = struct_class
14
- end
15
-
16
- def getter_def
17
- builder = return_value_builder
18
-
19
- return <<-CODE
20
- def #{@info.name}
21
- struct = #{@struct_class}.new @struct.to_ptr
22
- #{builder.cvar} = struct[#{field_symbol.inspect}]
23
- #{builder.post.join("\n")}
24
- #{builder.retval}
25
- end
26
- CODE
27
- end
28
-
29
- def setter_def
30
- builder = setter_builder
31
- name = @info.name
32
-
33
- return <<-CODE
34
- def #{name}= #{builder.inarg}
35
- #{builder.pre.join("\n")}
36
- struct = #{@struct_class}.new @struct.to_ptr
37
- struct[#{name.to_sym.inspect}] = #{builder.callarg}
38
- end
39
- CODE
40
- end
41
-
42
- private
43
-
44
- def field_symbol
45
- @info.name.to_sym
46
- end
47
-
48
- def return_value_builder
49
- vargen = VariableNameGenerator.new
50
- @rv_builder ||= ReturnValueBuilder.new vargen, @info.field_type, false
51
- end
52
-
53
- def setter_builder
54
- vargen = VariableNameGenerator.new
55
- argument_info = SetterArgumentInfo.new "value", @info.field_type
56
- ArgumentBuilder.new vargen, argument_info
57
- end
58
- end
59
- end
60
- end
@@ -1,127 +0,0 @@
1
- require 'gir_ffi/builder_helper'
2
- require 'gir_ffi/module_base'
3
- require 'gir_ffi/function_builder'
4
- require 'indentation'
5
-
6
- module GirFFI
7
- # Builds a module based on information found in the introspection
8
- # repository.
9
- class Builder::Module
10
- include BuilderHelper
11
-
12
- def initialize namespace, version=nil
13
- @namespace = namespace
14
- @version = version
15
- # FIXME: Pass safe namespace as an argument
16
- @safe_namespace = @namespace.gsub(/^(.)/) { $1.upcase }
17
- end
18
-
19
- def generate
20
- build_module
21
- end
22
-
23
- def setup_method method
24
- go = function_introspection_data method.to_s
25
-
26
- return false if go.nil?
27
-
28
- modul = build_module
29
- lib = modul.const_get(:Lib)
30
-
31
- Builder.attach_ffi_function lib, go
32
- definition = function_definition(go, lib)
33
- modul.class_eval definition
34
-
35
- true
36
- end
37
-
38
- def build_namespaced_class classname
39
- info = gir.find_by_name @namespace, classname.to_s
40
- if info.nil?
41
- raise NameError.new(
42
- "Class #{classname} not found in namespace #{@namespace}")
43
- end
44
- Builder.build_class info
45
- end
46
-
47
- def build_module
48
- unless defined? @module
49
- build_dependencies
50
- instantiate_module
51
- setup_lib_for_ffi
52
- setup_module unless already_set_up
53
- end
54
- @module
55
- end
56
-
57
- private
58
-
59
- def build_dependencies
60
- deps = gir.dependencies @namespace
61
- deps.each {|dep|
62
- name, version = dep.split '-'
63
- Builder.build_module name, version
64
- }
65
- end
66
-
67
- def instantiate_module
68
- @module = get_or_define_module ::Object, @safe_namespace
69
- end
70
-
71
- def setup_module
72
- @module.extend ModuleBase
73
- @module.const_set :GIR_FFI_BUILDER, self
74
- end
75
-
76
- def already_set_up
77
- @module.respond_to? :method_missing
78
- end
79
-
80
- def setup_lib_for_ffi
81
- @lib = get_or_define_module @module, :Lib
82
-
83
- unless (class << @lib; self.include? GirFFI::Library; end)
84
- @lib.extend GirFFI::Library
85
- @lib.ffi_lib_flags :global, :lazy
86
- libspec = gir.shared_library(@namespace)
87
- unless libspec.nil?
88
- @lib.ffi_lib(*libspec.split(/,/))
89
- end
90
- end
91
- end
92
-
93
- def sub_builder info
94
- if info.info_type == :function
95
- FunctionBuilder.new(info, libmodule)
96
- else
97
- Builder::Type.builder_for info
98
- end
99
- end
100
-
101
- def libmodule
102
- @module.const_get(:Lib)
103
- end
104
-
105
- def function_introspection_data function
106
- info = gir.find_by_name @namespace, function.to_s
107
- return nil if info.nil?
108
- info.info_type == :function ? info : nil
109
- end
110
-
111
- def function_definition info, libmodule
112
- FunctionBuilder.new(info, libmodule).generate
113
- end
114
-
115
- def gir
116
- unless defined? @gir
117
- @gir = GObjectIntrospection::IRepository.default
118
- @gir.require @namespace, @version
119
- end
120
- @gir
121
- end
122
-
123
- def get_or_define_module parent, name
124
- optionally_define_constant(parent, name) { Module.new }
125
- end
126
- end
127
- end
@@ -1,39 +0,0 @@
1
- require 'gir_ffi/builder/type/callback'
2
- require 'gir_ffi/builder/type/constant'
3
- require 'gir_ffi/builder/type/enum'
4
- require 'gir_ffi/builder/type/interface'
5
- require 'gir_ffi/builder/type/object'
6
- require 'gir_ffi/builder/type/struct'
7
- require 'gir_ffi/builder/type/unintrospectable'
8
- require 'gir_ffi/builder/type/union'
9
-
10
- module GirFFI
11
- # Builds a class based on information found in the introspection
12
- # repository.
13
- module Builder
14
- module Type
15
- CACHE = {}
16
-
17
- TYPE_MAP = {
18
- :callback => Callback,
19
- :constant => Constant,
20
- :enum => Enum,
21
- :flags => Enum,
22
- :interface => Interface,
23
- :object => Object,
24
- :struct => Struct,
25
- :union => Union,
26
- :unintrospectable => Unintrospectable
27
- }
28
-
29
- def self.build info
30
- TYPE_MAP[info.info_type].new(info).build_class
31
- end
32
-
33
- # TODO: Pull up to include :function and :module
34
- def self.builder_for info
35
- TYPE_MAP[info.info_type].new(info)
36
- end
37
- end
38
- end
39
- end
@@ -1,48 +0,0 @@
1
- require 'gir_ffi/builder_helper'
2
-
3
- module GirFFI
4
- module Builder
5
- module Type
6
-
7
- # Base class for type builders.
8
- class Base
9
- include BuilderHelper
10
-
11
- def initialize info
12
- @info = info
13
- @namespace = @info.namespace
14
- @classname = @info.safe_name
15
- end
16
-
17
- def build_class
18
- unless defined? @klass
19
- instantiate_class
20
- end
21
- @klass
22
- end
23
-
24
- attr_reader :info
25
-
26
- private
27
-
28
- def namespace_module
29
- @namespace_module ||= Builder.build_module @namespace
30
- end
31
-
32
- def lib
33
- @lib ||= namespace_module.const_get :Lib
34
- end
35
-
36
- def get_or_define_class namespace, name, parent
37
- optionally_define_constant(namespace, name) {
38
- Class.new parent
39
- }
40
- end
41
-
42
- def gir
43
- @gir ||= GObjectIntrospection::IRepository.default
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,30 +0,0 @@
1
- require 'gir_ffi/builder/type/base'
2
- module GirFFI
3
- module Builder
4
- module Type
5
-
6
- # Implements the creation of a callback type. The type will be
7
- # attached to the appropriate namespace module, and will be defined
8
- # as a callback for FFI.
9
- class Callback < Base
10
- def instantiate_class
11
- @klass = optionally_define_constant namespace_module, @classname do
12
- lib.callback callback_sym, argument_types, return_type
13
- end
14
- end
15
-
16
- def callback_sym
17
- @classname.to_sym
18
- end
19
-
20
- def argument_types
21
- @info.argument_ffi_types
22
- end
23
-
24
- def return_type
25
- @info.return_ffi_type
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,22 +0,0 @@
1
- require 'gir_ffi/builder/type/base'
2
- module GirFFI
3
- module Builder
4
- module Type
5
-
6
- # Implements the creation of a constant. Though semantically not a
7
- # type, its build method is like that of the types, in that it is
8
- # triggered by a missing constant in the parent namespace. The
9
- # constant will be attached to the appropriate namespace module.
10
- class Constant < Base
11
- private
12
-
13
- def instantiate_class
14
- @klass = optionally_define_constant namespace_module, @classname do
15
- info.value
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
@@ -1,66 +0,0 @@
1
- require 'gir_ffi/builder/type/registered_type'
2
- require 'gir_ffi/builder/type/with_methods'
3
- require 'gir_ffi/enum_base'
4
-
5
- module GirFFI
6
- module Builder
7
- module Type
8
-
9
- # Implements the creation of an enum or flags type. The type will be
10
- # attached to the appropriate namespace module, and will be defined
11
- # as an enum for FFI.
12
- class Enum < RegisteredType
13
- include WithMethods
14
-
15
- private
16
-
17
- def enum_sym
18
- @classname.to_sym
19
- end
20
-
21
- def value_spec
22
- return info.values.map {|vinfo|
23
- val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value)
24
- [vinfo.name.to_sym, val]
25
- }.flatten
26
- end
27
-
28
- def instantiate_class
29
- @klass = get_or_define_module namespace_module, @classname
30
- @enum = optionally_define_constant @klass, :Enum do
31
- lib.enum(enum_sym, value_spec)
32
- end
33
- unless already_set_up
34
- @klass.extend superclass
35
- setup_constants
36
- setup_gtype_getter
37
- stub_methods
38
- setup_inspect
39
- end
40
- end
41
-
42
- def setup_inspect
43
- @klass.instance_eval <<-EOS
44
- def self.inspect
45
- "#{@namespace}::#{@classname}"
46
- end
47
- EOS
48
- end
49
-
50
- def already_set_up
51
- @klass.respond_to? :get_gtype
52
- end
53
-
54
- def superclass
55
- @superclass ||= EnumBase
56
- end
57
-
58
- # FIXME: Remove duplication with Builder::Module
59
- def get_or_define_module parent, name
60
- optionally_define_constant(parent, name) { ::Module.new }
61
- end
62
- end
63
- end
64
- end
65
- end
66
-
@@ -1,33 +0,0 @@
1
- require 'gir_ffi/builder/type/registered_type'
2
- require 'gir_ffi/builder/type/with_methods'
3
- require 'gir_ffi/interface_base'
4
-
5
- module GirFFI
6
- module Builder
7
- module Type
8
-
9
- # Implements the creation of a module representing an Interface.
10
- class Interface < RegisteredType
11
- include WithMethods
12
-
13
- private
14
-
15
- # FIXME: The word 'class' is not really correct.
16
- def instantiate_class
17
- @klass = optionally_define_constant(namespace_module, @classname) do
18
- ::Module.new
19
- end
20
- setup_module unless already_set_up
21
- end
22
-
23
- def setup_module
24
- @klass.extend InterfaceBase
25
- setup_constants
26
- stub_methods
27
- setup_gtype_getter
28
- end
29
- end
30
- end
31
- end
32
- end
33
-
@@ -1,134 +0,0 @@
1
- require 'gir_ffi/builder/type/registered_type'
2
- require 'gir_ffi/builder/type/with_layout'
3
- require 'gir_ffi/builder/type/with_methods'
4
- require 'gir_ffi/builder/property'
5
- require 'gir_ffi/object_base'
6
-
7
- module GirFFI
8
- module Builder
9
- module Type
10
-
11
- # Implements the creation of a class representing a GObject Object.
12
- class Object < RegisteredType
13
- include WithMethods
14
- include WithLayout
15
-
16
- def find_signal signal_name
17
- signal_definers.each do |inf|
18
- inf.signals.each do |sig|
19
- return sig if sig.name == signal_name
20
- end
21
- end
22
- if parent
23
- return superclass.find_signal signal_name
24
- end
25
- raise "Signal #{signal_name} not found"
26
- end
27
-
28
- def find_property property_name
29
- info.properties.each do |prop|
30
- return prop if prop.name == property_name
31
- end
32
- if parent
33
- return superclass.find_property property_name
34
- end
35
- raise "Property #{property_name} not found"
36
- end
37
-
38
- private
39
-
40
- def setup_class
41
- setup_layout
42
- setup_constants
43
- stub_methods
44
- setup_gtype_getter
45
- if info.fundamental?
46
- setup_field_accessors
47
- else
48
- setup_property_accessors
49
- end
50
- setup_vfunc_invokers
51
- setup_interfaces
52
- end
53
-
54
- # FIXME: Private method only used in subclass
55
- def layout_superclass
56
- FFI::Struct
57
- end
58
-
59
- def parent
60
- unless defined? @parent
61
- pr = info.parent
62
- if pr.nil? or (pr.safe_name == @classname and pr.namespace == @namespace)
63
- @parent = nil
64
- else
65
- @parent = pr
66
- end
67
- end
68
- @parent
69
- end
70
-
71
- def superclass
72
- @superclass ||= if parent
73
- Builder.build_class parent
74
- else
75
- ObjectBase
76
- end
77
- end
78
-
79
- # TODO: Unify with field accessor setup.
80
- def setup_property_accessors
81
- info.properties.each do |prop|
82
- setup_accessors_for_property_info prop
83
- end
84
- end
85
-
86
- def setup_accessors_for_property_info prop
87
- builder = Builder::Property.new prop
88
- unless has_instance_method prop.getter_name
89
- @klass.class_eval builder.getter_def
90
- end
91
- @klass.class_eval builder.setter_def
92
- end
93
-
94
- # TODO: Guard agains accidental invocation of undefined vfuncs.
95
- # TODO: Create object responsible for creating these invokers
96
- def setup_vfunc_invokers
97
- info.vfuncs.each do |vfinfo|
98
- if (invoker = vfinfo.invoker)
99
- define_vfunc_invoker vfinfo.name, invoker.name
100
- end
101
- end
102
- end
103
-
104
- def define_vfunc_invoker vfunc_name, invoker_name
105
- return if vfunc_name == invoker_name
106
- @klass.class_eval "
107
- def #{vfunc_name} *args, &block
108
- #{invoker_name}(*args, &block)
109
- end
110
- "
111
- end
112
-
113
- def setup_interfaces
114
- interfaces.each do |iface|
115
- @klass.class_eval do
116
- include iface
117
- end
118
- end
119
- end
120
-
121
- def signal_definers
122
- [info] + info.interfaces
123
- end
124
-
125
- def interfaces
126
- info.interfaces.map do |ifinfo|
127
- GirFFI::Builder.build_class ifinfo
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
134
-