gobject-introspection 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/Rakefile +50 -0
  2. data/ext/gobject-introspection/extconf.rb +97 -0
  3. data/ext/gobject-introspection/rb-gi-arg-info.c +151 -0
  4. data/ext/gobject-introspection/rb-gi-argument.c +223 -0
  5. data/ext/gobject-introspection/rb-gi-base-info.c +218 -0
  6. data/ext/gobject-introspection/rb-gi-boxed-info.c +48 -0
  7. data/ext/gobject-introspection/rb-gi-callable-info.c +124 -0
  8. data/ext/gobject-introspection/rb-gi-callback-info.c +48 -0
  9. data/ext/gobject-introspection/rb-gi-constant-info.c +77 -0
  10. data/ext/gobject-introspection/rb-gi-constructor-info.c +82 -0
  11. data/ext/gobject-introspection/rb-gi-conversions.h +95 -0
  12. data/ext/gobject-introspection/rb-gi-enum-info.c +145 -0
  13. data/ext/gobject-introspection/rb-gi-field-info.c +149 -0
  14. data/ext/gobject-introspection/rb-gi-flags-info.c +48 -0
  15. data/ext/gobject-introspection/rb-gi-function-info.c +199 -0
  16. data/ext/gobject-introspection/rb-gi-interface-info.c +222 -0
  17. data/ext/gobject-introspection/rb-gi-loader.c +61 -0
  18. data/ext/gobject-introspection/rb-gi-method-info.c +66 -0
  19. data/ext/gobject-introspection/rb-gi-object-info.c +345 -0
  20. data/ext/gobject-introspection/rb-gi-property-info.c +77 -0
  21. data/ext/gobject-introspection/rb-gi-registered-type-info.c +86 -0
  22. data/ext/gobject-introspection/rb-gi-repository.c +164 -0
  23. data/ext/gobject-introspection/rb-gi-signal-info.c +77 -0
  24. data/ext/gobject-introspection/rb-gi-struct-info.c +183 -0
  25. data/ext/gobject-introspection/rb-gi-type-info.c +143 -0
  26. data/ext/gobject-introspection/rb-gi-type-tag.c +43 -0
  27. data/ext/gobject-introspection/rb-gi-types.h +71 -0
  28. data/ext/gobject-introspection/rb-gi-union-info.c +206 -0
  29. data/ext/gobject-introspection/rb-gi-unresolved-info.c +48 -0
  30. data/ext/gobject-introspection/rb-gi-value-info.c +57 -0
  31. data/ext/gobject-introspection/rb-gi-vfunc-info.c +91 -0
  32. data/ext/gobject-introspection/rb-gobject-introspection.c +42 -0
  33. data/ext/gobject-introspection/rb-gobject-introspection.h +105 -0
  34. data/extconf.rb +71 -0
  35. data/lib/gobject-introspection.rb +39 -0
  36. data/lib/gobject-introspection/collection-reader.rb +34 -0
  37. data/lib/gobject-introspection/loader.rb +148 -0
  38. data/lib/gobject-introspection/object-info.rb +33 -0
  39. data/lib/gobject-introspection/repository.rb +32 -0
  40. data/lib/gobject-introspection/struct-info.rb +28 -0
  41. data/sample/clutter-basic-actor.rb +132 -0
  42. data/sample/clutter.rb +29 -0
  43. data/test/gobject-introspection-test-utils.rb +26 -0
  44. data/test/run-test.rb +45 -0
  45. data/test/test-arg-info.rb +68 -0
  46. data/test/test-base-info.rb +31 -0
  47. data/test/test-boxed-info.rb +21 -0
  48. data/test/test-callable-info.rb +49 -0
  49. data/test/test-callback-info.rb +29 -0
  50. data/test/test-constant-info.rb +24 -0
  51. data/test/test-enum-info.rb +56 -0
  52. data/test/test-field-type.rb +42 -0
  53. data/test/test-flags-info.rb +27 -0
  54. data/test/test-function-info.rb +37 -0
  55. data/test/test-interface-info.rb +97 -0
  56. data/test/test-loader.rb +30 -0
  57. data/test/test-object-info.rb +131 -0
  58. data/test/test-property-info.rb +38 -0
  59. data/test/test-registered-type-info.rb +35 -0
  60. data/test/test-repository.rb +59 -0
  61. data/test/test-signal-info.rb +37 -0
  62. data/test/test-struct-info.rb +57 -0
  63. data/test/test-type-info.rb +62 -0
  64. data/test/test-type-tag.rb +29 -0
  65. data/test/test-union-info.rb +21 -0
  66. data/test/test-value-info.rb +28 -0
  67. data/test/test-vfunc-info.rb +42 -0
  68. metadata +162 -0
@@ -0,0 +1,48 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIFlagsInfo
24
+
25
+ GType
26
+ gi_flags_info_get_type(void)
27
+ {
28
+ static GType type = 0;
29
+ if (type == 0) {
30
+ type = g_boxed_type_register_static("GIFlagsInfo",
31
+ (GBoxedCopyFunc)g_base_info_ref,
32
+ (GBoxedFreeFunc)g_base_info_unref);
33
+ }
34
+ return type;
35
+ }
36
+
37
+ void
38
+ rb_gi_flags_info_init(VALUE rb_mGI, VALUE rb_cGIEnumInfo)
39
+ {
40
+ VALUE RG_TARGET_NAMESPACE;
41
+
42
+ RG_TARGET_NAMESPACE =
43
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_FLAGS_INFO, "FlagsInfo", rb_mGI,
44
+ rb_cGIEnumInfo);
45
+
46
+ /* Suppress a warning. */
47
+ (void)RG_TARGET_NAMESPACE;
48
+ }
@@ -0,0 +1,199 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIFunctionInfo
24
+ #define SELF(self) RVAL2GI_FUNCTION_INFO(self)
25
+
26
+ GType
27
+ gi_function_info_get_type(void)
28
+ {
29
+ static GType type = 0;
30
+ if (type == 0) {
31
+ type = g_boxed_type_register_static("GIFunctionInfo",
32
+ (GBoxedCopyFunc)g_base_info_ref,
33
+ (GBoxedFreeFunc)g_base_info_unref);
34
+ }
35
+ return type;
36
+ }
37
+
38
+ static VALUE
39
+ rg_symbol(VALUE self)
40
+ {
41
+ GIFunctionInfo *info;
42
+
43
+ info = SELF(self);
44
+ return CSTR2RVAL(g_function_info_get_symbol(info));
45
+ }
46
+
47
+ static VALUE
48
+ rg_flags(VALUE self)
49
+ {
50
+ GIFunctionInfo *info;
51
+
52
+ info = SELF(self);
53
+ return GI_FUNCTION_INFO_FLAGS2RVAL(g_function_info_get_flags(info));
54
+ }
55
+
56
+ static VALUE
57
+ rg_property(VALUE self)
58
+ {
59
+ GIFunctionInfo *info;
60
+
61
+ info = SELF(self);
62
+ return GI_BASE_INFO2RVAL(g_function_info_get_property(info));
63
+ }
64
+
65
+ static VALUE
66
+ rg_vfunc(VALUE self)
67
+ {
68
+ GIFunctionInfo *info;
69
+
70
+ info = SELF(self);
71
+ return GI_BASE_INFO2RVAL(g_function_info_get_vfunc(info));
72
+ }
73
+
74
+ static void
75
+ fill_gi_argument_by_ruby(GIArgument *argument, GIArgInfo *arg_info,
76
+ VALUE rb_argument)
77
+ {
78
+ GITypeInfo type_info;
79
+
80
+ g_arg_info_load_type(arg_info, &type_info);
81
+ RVAL2GI_ARGUMENT(argument, &type_info, rb_argument);
82
+ }
83
+
84
+ static void
85
+ fill_in_argument(GIArgInfo *arg_info, GArray *in_args, int argc, VALUE *argv)
86
+ {
87
+ VALUE rb_argument;
88
+ GIArgument argument;
89
+
90
+ /* TODO: check argc */
91
+ rb_argument = argv[in_args->len];
92
+ fill_gi_argument_by_ruby(&argument, arg_info, rb_argument);
93
+ g_array_append_val(in_args, argument);
94
+ }
95
+
96
+ static void
97
+ fill_out_argument(G_GNUC_UNUSED GIArgInfo *arg_info, GArray *out_args)
98
+ {
99
+ GIArgument argument;
100
+ g_array_append_val(out_args, argument);
101
+ }
102
+
103
+ static void
104
+ fill_argument(GIArgInfo *arg_info, GArray *in_args, GArray *out_args,
105
+ int argc, VALUE *argv)
106
+ {
107
+ switch (g_arg_info_get_direction(arg_info)) {
108
+ case GI_DIRECTION_IN:
109
+ fill_in_argument(arg_info, in_args, argc, argv);
110
+ break;
111
+ case GI_DIRECTION_OUT:
112
+ fill_out_argument(arg_info, out_args);
113
+ break;
114
+ case GI_DIRECTION_INOUT:
115
+ fill_in_argument(arg_info, in_args, argc, argv);
116
+ fill_out_argument(arg_info, out_args);
117
+ break;
118
+ default:
119
+ g_assert_not_reached();
120
+ break;
121
+ }
122
+ }
123
+
124
+ void
125
+ rb_gi_function_info_invoke_raw(GIFunctionInfo *info, int argc, VALUE *argv,
126
+ GIArgument *return_value)
127
+ {
128
+ GICallableInfo *callable_info;
129
+ gint i, n_args;
130
+ GArray *in_args, *out_args;
131
+ gboolean succeeded;
132
+ GError *error = NULL;
133
+
134
+ callable_info = (GICallableInfo *)info;
135
+ n_args = g_callable_info_get_n_args(callable_info);
136
+ in_args = g_array_new(FALSE, FALSE, sizeof(GIArgument));
137
+ out_args = g_array_new(FALSE, FALSE, sizeof(GIArgument));
138
+ if (g_function_info_get_flags(callable_info) & GI_FUNCTION_IS_METHOD) {
139
+ GIArgument argument;
140
+ /* TODO: check argc */
141
+ argument.v_pointer = RVAL2GOBJ(argv[0]);
142
+ g_array_append_val(in_args, argument);
143
+ }
144
+ for (i = 0; i < n_args; i++) {
145
+ GIArgInfo arg_info;
146
+ g_callable_info_load_arg(callable_info, i, &arg_info);
147
+ fill_argument(&arg_info, in_args, out_args, argc, argv);
148
+ }
149
+ succeeded = g_function_info_invoke(info,
150
+ (GIArgument *)(in_args->data),
151
+ in_args->len,
152
+ (GIArgument *)(out_args->data),
153
+ out_args->len,
154
+ return_value,
155
+ &error);
156
+ g_array_unref(in_args);
157
+ g_array_unref(out_args);
158
+ if (!succeeded) {
159
+ RG_RAISE_ERROR(error);
160
+ }
161
+ }
162
+
163
+ static VALUE
164
+ rg_invoke(int argc, VALUE *argv, VALUE self)
165
+ {
166
+ GIFunctionInfo *info;
167
+ GICallableInfo *callable_info;
168
+ GIArgument return_value;
169
+ GITypeInfo return_value_info;
170
+
171
+ info = SELF(self);
172
+ callable_info = (GICallableInfo *)info;
173
+
174
+ rb_gi_function_info_invoke_raw(info, argc, argv, &return_value);
175
+ g_callable_info_load_return_type(callable_info, &return_value_info);
176
+
177
+ return GI_ARGUMENT2RVAL(&return_value, &return_value_info);
178
+ }
179
+
180
+ void
181
+ rb_gi_function_info_init(VALUE rb_mGI, VALUE rb_cGICallableInfo)
182
+ {
183
+ VALUE RG_TARGET_NAMESPACE;
184
+
185
+ RG_TARGET_NAMESPACE =
186
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_FUNCTION_INFO, "FunctionInfo", rb_mGI,
187
+ rb_cGICallableInfo);
188
+
189
+ RG_DEF_METHOD(symbol, 0);
190
+ RG_DEF_METHOD(flags, 0);
191
+ RG_DEF_METHOD(property, 0);
192
+ RG_DEF_METHOD(vfunc, 0);
193
+ RG_DEF_METHOD(invoke, -1);
194
+
195
+ G_DEF_CLASS(G_TYPE_I_FUNCTION_INFO_FLAGS, "FunctionInfoFlags", rb_mGI);
196
+
197
+ rb_gi_method_info_init(rb_mGI, RG_TARGET_NAMESPACE);
198
+ rb_gi_constructor_info_init(rb_mGI, RG_TARGET_NAMESPACE);
199
+ }
@@ -0,0 +1,222 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2012 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rb-gobject-introspection.h"
22
+
23
+ #define RG_TARGET_NAMESPACE rb_cGIInterfaceInfo
24
+ #define SELF(self) (RVAL2GI_INTERFACE_INFO(self))
25
+
26
+ GType
27
+ gi_interface_info_get_type(void)
28
+ {
29
+ static GType type = 0;
30
+ if (type == 0) {
31
+ type = g_boxed_type_register_static("GIInterfaceInfo",
32
+ (GBoxedCopyFunc)g_base_info_ref,
33
+ (GBoxedFreeFunc)g_base_info_unref);
34
+ }
35
+ return type;
36
+ }
37
+
38
+ static VALUE
39
+ rg_n_prerequisites(VALUE self)
40
+ {
41
+ GIInterfaceInfo *info;
42
+
43
+ info = SELF(self);
44
+ return INT2NUM(g_interface_info_get_n_prerequisites(info));
45
+ }
46
+
47
+ static VALUE
48
+ rg_get_prerequisite(VALUE self, VALUE rb_n)
49
+ {
50
+ GIInterfaceInfo *info;
51
+ gint n;
52
+
53
+ info = SELF(self);
54
+ n = NUM2INT(rb_n);
55
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_interface_info_get_prerequisite(info, n));
56
+ }
57
+
58
+ static VALUE
59
+ rg_n_properties(VALUE self)
60
+ {
61
+ GIInterfaceInfo *info;
62
+
63
+ info = SELF(self);
64
+ return INT2NUM(g_interface_info_get_n_properties(info));
65
+ }
66
+
67
+ static VALUE
68
+ rg_get_property(VALUE self, VALUE rb_n)
69
+ {
70
+ GIInterfaceInfo *info;
71
+ gint n;
72
+
73
+ info = SELF(self);
74
+ n = NUM2INT(rb_n);
75
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_interface_info_get_property(info, n));
76
+ }
77
+
78
+ static VALUE
79
+ rg_n_methods(VALUE self)
80
+ {
81
+ GIInterfaceInfo *info;
82
+
83
+ info = SELF(self);
84
+ return INT2NUM(g_interface_info_get_n_methods(info));
85
+ }
86
+
87
+ static VALUE
88
+ rg_get_method(VALUE self, VALUE rb_n_or_name)
89
+ {
90
+ GIInterfaceInfo *info;
91
+ GIFunctionInfo *function_info;
92
+
93
+ info = SELF(self);
94
+ if (RB_TYPE_P(rb_n_or_name, T_FIXNUM)) {
95
+ gint n;
96
+ n = NUM2INT(rb_n_or_name);
97
+ function_info = g_interface_info_get_method(info, n);
98
+ } else {
99
+ const char *name;
100
+ name = RVAL2CSTR(rb_n_or_name);
101
+ function_info = g_interface_info_find_method(info, name);
102
+ }
103
+
104
+ return GI_BASE_INFO2RVAL_WITH_UNREF(function_info);
105
+ }
106
+
107
+ static VALUE
108
+ rg_n_signals(VALUE self)
109
+ {
110
+ GIInterfaceInfo *info;
111
+
112
+ info = SELF(self);
113
+ return INT2NUM(g_interface_info_get_n_signals(info));
114
+ }
115
+
116
+ static VALUE
117
+ rg_get_signal(VALUE self, VALUE rb_n_or_name)
118
+ {
119
+ GIInterfaceInfo *info;
120
+ GISignalInfo *signal_info;
121
+
122
+ info = SELF(self);
123
+ if (RB_TYPE_P(rb_n_or_name, T_FIXNUM)) {
124
+ gint n;
125
+ n = NUM2INT(rb_n_or_name);
126
+ signal_info = g_interface_info_get_signal(info, n);
127
+ } else {
128
+ #ifdef HAVE_G_INTERFACE_INFO_FIND_SIGNAL
129
+ const char *name;
130
+ name = RVAL2CSTR(rb_n_or_name);
131
+ signal_info = g_interface_info_find_signal(info, name);
132
+ #else
133
+ rb_raise(rb_eArgError,
134
+ "g_interface_info_find_signal() is defined "
135
+ "since GObjectIntrospection 1.34");
136
+ #endif
137
+ }
138
+
139
+ return GI_BASE_INFO2RVAL_WITH_UNREF(signal_info);
140
+ }
141
+
142
+ static VALUE
143
+ rg_n_vfuncs(VALUE self)
144
+ {
145
+ GIInterfaceInfo *info;
146
+
147
+ info = SELF(self);
148
+ return INT2NUM(g_interface_info_get_n_vfuncs(info));
149
+ }
150
+
151
+ static VALUE
152
+ rg_get_vfunc(VALUE self, VALUE rb_n_or_name)
153
+ {
154
+ GIInterfaceInfo *info;
155
+ GIVFuncInfo *vfunc_info;
156
+
157
+ info = SELF(self);
158
+ if (RB_TYPE_P(rb_n_or_name, T_FIXNUM)) {
159
+ gint n;
160
+ n = NUM2INT(rb_n_or_name);
161
+ vfunc_info = g_interface_info_get_vfunc(info, n);
162
+ } else {
163
+ const gchar *name;
164
+ name = RVAL2CSTR(rb_n_or_name);
165
+ vfunc_info = g_interface_info_find_vfunc(info, name);
166
+ }
167
+
168
+ return GI_BASE_INFO2RVAL_WITH_UNREF(vfunc_info);
169
+ }
170
+
171
+ static VALUE
172
+ rg_n_constants(VALUE self)
173
+ {
174
+ GIInterfaceInfo *info;
175
+
176
+ info = SELF(self);
177
+ return INT2NUM(g_interface_info_get_n_constants(info));
178
+ }
179
+
180
+ static VALUE
181
+ rg_get_constant(VALUE self, VALUE rb_n)
182
+ {
183
+ GIInterfaceInfo *info;
184
+ gint n;
185
+
186
+ info = SELF(self);
187
+ n = NUM2INT(rb_n);
188
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_interface_info_get_constant(info, n));
189
+ }
190
+
191
+ static VALUE
192
+ rg_iface_struct(VALUE self)
193
+ {
194
+ GIInterfaceInfo *info;
195
+
196
+ info = SELF(self);
197
+ return GI_BASE_INFO2RVAL_WITH_UNREF(g_interface_info_get_iface_struct(info));
198
+ }
199
+
200
+ void
201
+ rb_gi_interface_info_init(VALUE rb_mGI, VALUE rb_cGIRegisteredTypeInfo)
202
+ {
203
+ VALUE RG_TARGET_NAMESPACE;
204
+
205
+ RG_TARGET_NAMESPACE =
206
+ G_DEF_CLASS_WITH_PARENT(GI_TYPE_INTERFACE_INFO, "InterfaceInfo", rb_mGI,
207
+ rb_cGIRegisteredTypeInfo);
208
+
209
+ RG_DEF_METHOD(n_prerequisites, 0);
210
+ RG_DEF_METHOD(get_prerequisite, 1);
211
+ RG_DEF_METHOD(n_properties, 0);
212
+ RG_DEF_METHOD(get_property, 1);
213
+ RG_DEF_METHOD(n_methods, 0);
214
+ RG_DEF_METHOD(get_method, 1);
215
+ RG_DEF_METHOD(n_signals, 0);
216
+ RG_DEF_METHOD(get_signal, 1);
217
+ RG_DEF_METHOD(n_vfuncs, 0);
218
+ RG_DEF_METHOD(get_vfunc, 1);
219
+ RG_DEF_METHOD(n_constants, 0);
220
+ RG_DEF_METHOD(get_constant, 1);
221
+ RG_DEF_METHOD(iface_struct, 0);
222
+ }