glib2 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3023 -0
- data/README +28 -0
- data/Rakefile +87 -0
- data/extconf.rb +61 -0
- data/sample/bookmarkfile.rb +66 -0
- data/sample/completion.rb +45 -0
- data/sample/idle.rb +41 -0
- data/sample/iochannel.rb +44 -0
- data/sample/keyfile.rb +62 -0
- data/sample/shell.rb +36 -0
- data/sample/spawn.rb +25 -0
- data/sample/timeout.rb +28 -0
- data/sample/timeout2.rb +35 -0
- data/sample/timer.rb +40 -0
- data/sample/type-register.rb +103 -0
- data/sample/type-register2.rb +104 -0
- data/sample/utils.rb +54 -0
- data/src/glib-enum-types.c +1032 -0
- data/src/glib-enum-types.h +140 -0
- data/src/lib/glib-mkenums.rb +199 -0
- data/src/lib/glib2.rb +220 -0
- data/src/lib/mkmf-gnome2.rb +390 -0
- data/src/lib/pkg-config.rb +137 -0
- data/src/rbgcompat.h +30 -0
- data/src/rbglib.c +320 -0
- data/src/rbglib.h +96 -0
- data/src/rbglib_bookmarkfile.c +595 -0
- data/src/rbglib_completion.c +192 -0
- data/src/rbglib_convert.c +195 -0
- data/src/rbglib_error.c +95 -0
- data/src/rbglib_fileutils.c +83 -0
- data/src/rbglib_i18n.c +44 -0
- data/src/rbglib_int64.c +157 -0
- data/src/rbglib_iochannel.c +883 -0
- data/src/rbglib_keyfile.c +846 -0
- data/src/rbglib_maincontext.c +917 -0
- data/src/rbglib_mainloop.c +87 -0
- data/src/rbglib_messages.c +150 -0
- data/src/rbglib_pollfd.c +111 -0
- data/src/rbglib_shell.c +68 -0
- data/src/rbglib_source.c +190 -0
- data/src/rbglib_spawn.c +345 -0
- data/src/rbglib_threads.c +51 -0
- data/src/rbglib_timer.c +127 -0
- data/src/rbglib_unicode.c +611 -0
- data/src/rbglib_utils.c +386 -0
- data/src/rbglib_win32.c +136 -0
- data/src/rbgobj_boxed.c +251 -0
- data/src/rbgobj_closure.c +337 -0
- data/src/rbgobj_convert.c +167 -0
- data/src/rbgobj_enums.c +961 -0
- data/src/rbgobj_fundamental.c +30 -0
- data/src/rbgobj_object.c +892 -0
- data/src/rbgobj_param.c +390 -0
- data/src/rbgobj_paramspecs.c +305 -0
- data/src/rbgobj_signal.c +963 -0
- data/src/rbgobj_strv.c +61 -0
- data/src/rbgobj_type.c +851 -0
- data/src/rbgobj_typeinstance.c +121 -0
- data/src/rbgobj_typeinterface.c +148 -0
- data/src/rbgobj_typemodule.c +66 -0
- data/src/rbgobj_typeplugin.c +49 -0
- data/src/rbgobj_value.c +313 -0
- data/src/rbgobj_valuearray.c +59 -0
- data/src/rbgobj_valuetypes.c +298 -0
- data/src/rbgobject.c +406 -0
- data/src/rbgobject.h +265 -0
- data/src/rbgprivate.h +88 -0
- data/src/rbgutil.c +222 -0
- data/src/rbgutil.h +82 -0
- data/src/rbgutil_callback.c +231 -0
- data/test/glib-test-init.rb +6 -0
- data/test/glib-test-utils.rb +12 -0
- data/test/run-test.rb +25 -0
- data/test/test_enum.rb +99 -0
- data/test/test_file_utils.rb +15 -0
- data/test/test_glib2.rb +120 -0
- data/test/test_iochannel.rb +275 -0
- data/test/test_key_file.rb +38 -0
- data/test/test_mkenums.rb +25 -0
- data/test/test_signal.rb +20 -0
- data/test/test_timeout.rb +28 -0
- data/test/test_unicode.rb +369 -0
- data/test/test_utils.rb +37 -0
- data/test/test_win32.rb +13 -0
- metadata +165 -0
data/src/rbglib_spawn.c
ADDED
@@ -0,0 +1,345 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbglib_spawn.c -
|
5
|
+
|
6
|
+
$Author: sakai $
|
7
|
+
$Date: 2007/07/08 02:40:12 $
|
8
|
+
|
9
|
+
Copyright (C) 2004 Masao Mutoh
|
10
|
+
Copyright (C) 2004 Kazuhiro NISHIYAMA
|
11
|
+
|
12
|
+
**********************************************************************/
|
13
|
+
#include "rbgprivate.h"
|
14
|
+
#include "rbglib.h"
|
15
|
+
|
16
|
+
static ID id_call;
|
17
|
+
static ID id_new;
|
18
|
+
|
19
|
+
static void
|
20
|
+
child_setup(func)
|
21
|
+
gpointer func;
|
22
|
+
{
|
23
|
+
if (! NIL_P(func)){
|
24
|
+
rb_funcall((VALUE)func, id_call, 0);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE
|
29
|
+
rbglib_m_spawn_async_with_pipes(self, working_directory, argv, envp, flags)
|
30
|
+
VALUE self, working_directory, argv, envp, flags;
|
31
|
+
{
|
32
|
+
GError *err = NULL;
|
33
|
+
gboolean ret;
|
34
|
+
GPid child_pid;
|
35
|
+
VALUE func = Qnil;
|
36
|
+
gint gargc, genc, i;
|
37
|
+
gchar** gargv = (gchar**)NULL;
|
38
|
+
gchar** genvp = (gchar**)NULL;
|
39
|
+
gint standard_input, standard_output, standard_error;
|
40
|
+
|
41
|
+
if (rb_block_given_p()) {
|
42
|
+
func = rb_block_proc();
|
43
|
+
G_RELATIVE(self, func);
|
44
|
+
}
|
45
|
+
|
46
|
+
if (! NIL_P(argv)){
|
47
|
+
Check_Type(argv, T_ARRAY);
|
48
|
+
gargc = RARRAY_LEN(argv);
|
49
|
+
gargv = ALLOCA_N(gchar*, gargc + 1);
|
50
|
+
for (i = 0; i < gargc; i++) {
|
51
|
+
if (TYPE(RARRAY_PTR(argv)[i]) == T_STRING) {
|
52
|
+
gargv[i] = RVAL2CSTR(RARRAY_PTR(argv)[i]);
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
gargv[i] = "";
|
56
|
+
}
|
57
|
+
}
|
58
|
+
gargv[gargc] = (gchar*)NULL;
|
59
|
+
}
|
60
|
+
|
61
|
+
if (! NIL_P(envp)){
|
62
|
+
Check_Type(envp, T_ARRAY);
|
63
|
+
genc = RARRAY_LEN(envp);
|
64
|
+
genvp = ALLOCA_N(gchar*, genc + 1);
|
65
|
+
for (i = 0; i < genc; i++) {
|
66
|
+
if (TYPE(RARRAY_PTR(envp)[i]) == T_STRING) {
|
67
|
+
genvp[i] = RVAL2CSTR(RARRAY_PTR(envp)[i]);
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
genvp[i] = "";
|
71
|
+
}
|
72
|
+
}
|
73
|
+
genvp[genc] = (gchar*)NULL;
|
74
|
+
}
|
75
|
+
|
76
|
+
ret = g_spawn_async_with_pipes(NIL_P(working_directory) ? NULL : RVAL2CSTR(working_directory),
|
77
|
+
gargv, genvp, NUM2INT(flags),
|
78
|
+
(GSpawnChildSetupFunc)child_setup,
|
79
|
+
(gpointer)func,
|
80
|
+
&child_pid,
|
81
|
+
&standard_input, &standard_output,
|
82
|
+
&standard_error, &err);
|
83
|
+
|
84
|
+
if (! ret) RAISE_GERROR(err);
|
85
|
+
|
86
|
+
return rb_ary_new3(4, INT2NUM((gint)child_pid),
|
87
|
+
rb_funcall(rb_cIO, id_new, 1, INT2NUM(standard_input)),
|
88
|
+
rb_funcall(rb_cIO, id_new, 1, INT2NUM(standard_output)),
|
89
|
+
rb_funcall(rb_cIO, id_new, 1, INT2NUM(standard_error)));
|
90
|
+
}
|
91
|
+
|
92
|
+
static VALUE
|
93
|
+
rbglib_m_spawn_async(self, working_directory, argv, envp, flags)
|
94
|
+
VALUE self, working_directory, argv, envp, flags;
|
95
|
+
{
|
96
|
+
GError *err = NULL;
|
97
|
+
gboolean ret;
|
98
|
+
GPid child_pid;
|
99
|
+
VALUE func = Qnil;
|
100
|
+
gint gargc, genc, i;
|
101
|
+
gchar** gargv = (gchar**)NULL;
|
102
|
+
gchar** genvp = (gchar**)NULL;
|
103
|
+
|
104
|
+
if (rb_block_given_p()) {
|
105
|
+
func = rb_block_proc();
|
106
|
+
G_RELATIVE(self, func);
|
107
|
+
}
|
108
|
+
|
109
|
+
if (! NIL_P(argv)){
|
110
|
+
Check_Type(argv, T_ARRAY);
|
111
|
+
gargc = RARRAY_LEN(argv);
|
112
|
+
gargv = ALLOCA_N(gchar*, gargc + 1);
|
113
|
+
for (i = 0; i < gargc; i++) {
|
114
|
+
if (TYPE(RARRAY_PTR(argv)[i]) == T_STRING) {
|
115
|
+
gargv[i] = RVAL2CSTR(RARRAY_PTR(argv)[i]);
|
116
|
+
}
|
117
|
+
else {
|
118
|
+
gargv[i] = "";
|
119
|
+
}
|
120
|
+
}
|
121
|
+
gargv[gargc] = (gchar*)NULL;
|
122
|
+
}
|
123
|
+
|
124
|
+
if (! NIL_P(envp)){
|
125
|
+
Check_Type(envp, T_ARRAY);
|
126
|
+
genc = RARRAY_LEN(envp);
|
127
|
+
genvp = ALLOCA_N(gchar*, genc + 1);
|
128
|
+
for (i = 0; i < genc; i++) {
|
129
|
+
if (TYPE(RARRAY_PTR(envp)[i]) == T_STRING) {
|
130
|
+
genvp[i] = RVAL2CSTR(RARRAY_PTR(envp)[i]);
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
genvp[i] = "";
|
134
|
+
}
|
135
|
+
}
|
136
|
+
genvp[genc] = (gchar*)NULL;
|
137
|
+
}
|
138
|
+
|
139
|
+
ret = g_spawn_async(NIL_P(working_directory) ? NULL : RVAL2CSTR(working_directory),
|
140
|
+
gargv, genvp, NUM2INT(flags),
|
141
|
+
(GSpawnChildSetupFunc)child_setup, (gpointer)func,
|
142
|
+
&child_pid, &err);
|
143
|
+
|
144
|
+
if (! ret){
|
145
|
+
RAISE_GERROR(err);
|
146
|
+
}
|
147
|
+
|
148
|
+
return INT2NUM((int)child_pid);
|
149
|
+
}
|
150
|
+
|
151
|
+
static VALUE
|
152
|
+
rbglib_m_spawn_sync(self, working_directory, argv, envp, flags)
|
153
|
+
VALUE self, working_directory, argv, envp, flags;
|
154
|
+
{
|
155
|
+
GError *err = NULL;
|
156
|
+
gboolean ret;
|
157
|
+
VALUE func = Qnil;
|
158
|
+
gint gargc, genc, i;
|
159
|
+
gchar** gargv = (gchar**)NULL;
|
160
|
+
gchar** genvp = (gchar**)NULL;
|
161
|
+
gchar *standard_output = NULL, *standard_error = NULL;
|
162
|
+
gint exit_status;
|
163
|
+
VALUE std_out, std_err;
|
164
|
+
|
165
|
+
if (rb_block_given_p()) {
|
166
|
+
func = rb_block_proc();
|
167
|
+
G_RELATIVE(self, func);
|
168
|
+
}
|
169
|
+
|
170
|
+
if (! NIL_P(argv)){
|
171
|
+
Check_Type(argv, T_ARRAY);
|
172
|
+
gargc = RARRAY_LEN(argv);
|
173
|
+
gargv = ALLOCA_N(gchar*, gargc + 1);
|
174
|
+
for (i = 0; i < gargc; i++) {
|
175
|
+
if (TYPE(RARRAY_PTR(argv)[i]) == T_STRING) {
|
176
|
+
gargv[i] = RVAL2CSTR(RARRAY_PTR(argv)[i]);
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
gargv[i] = "";
|
180
|
+
}
|
181
|
+
}
|
182
|
+
gargv[gargc] = (gchar*)NULL;
|
183
|
+
}
|
184
|
+
|
185
|
+
if (! NIL_P(envp)){
|
186
|
+
Check_Type(envp, T_ARRAY);
|
187
|
+
genc = RARRAY_LEN(envp);
|
188
|
+
genvp = ALLOCA_N(gchar*, genc + 1);
|
189
|
+
for (i = 0; i < genc; i++) {
|
190
|
+
if (TYPE(RARRAY_PTR(envp)[i]) == T_STRING) {
|
191
|
+
genvp[i] = RVAL2CSTR(RARRAY_PTR(envp)[i]);
|
192
|
+
}
|
193
|
+
else {
|
194
|
+
genvp[i] = "";
|
195
|
+
}
|
196
|
+
}
|
197
|
+
genvp[genc] = (gchar*)NULL;
|
198
|
+
}
|
199
|
+
|
200
|
+
ret = g_spawn_sync(NIL_P(working_directory) ? NULL : RVAL2CSTR(working_directory),
|
201
|
+
gargv, genvp, NUM2INT(flags),
|
202
|
+
(GSpawnChildSetupFunc)child_setup, (gpointer)func,
|
203
|
+
&standard_output, &standard_error,
|
204
|
+
&exit_status, &err);
|
205
|
+
|
206
|
+
|
207
|
+
if (! ret){
|
208
|
+
RAISE_GERROR(err);
|
209
|
+
}
|
210
|
+
|
211
|
+
if (standard_output) {
|
212
|
+
std_out = CSTR2RVAL(standard_output);
|
213
|
+
g_free(standard_output);
|
214
|
+
} else {
|
215
|
+
std_out = Qnil;
|
216
|
+
standard_output = NULL;
|
217
|
+
}
|
218
|
+
if (standard_error) {
|
219
|
+
std_err = CSTR2RVAL(standard_error);
|
220
|
+
g_free(standard_error);
|
221
|
+
standard_error = NULL;
|
222
|
+
} else {
|
223
|
+
std_err = Qnil;
|
224
|
+
}
|
225
|
+
|
226
|
+
if (! ret)
|
227
|
+
RAISE_GERROR(err);
|
228
|
+
|
229
|
+
return rb_ary_new3(3, std_out, std_err, INT2FIX(exit_status));
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
static VALUE
|
234
|
+
rbglib_m_spawn_command_line_sync(self, str)
|
235
|
+
VALUE self, str;
|
236
|
+
{
|
237
|
+
GError *err = NULL;
|
238
|
+
const gchar *command_line;
|
239
|
+
gchar *standard_output = NULL, *standard_error = NULL;
|
240
|
+
gint exit_status;
|
241
|
+
VALUE std_out, std_err;
|
242
|
+
gboolean ret;
|
243
|
+
|
244
|
+
command_line = StringValuePtr(str);
|
245
|
+
ret = g_spawn_command_line_sync(command_line,
|
246
|
+
&standard_output,
|
247
|
+
&standard_error,
|
248
|
+
&exit_status,
|
249
|
+
&err);
|
250
|
+
if (standard_output) {
|
251
|
+
std_out = CSTR2RVAL(standard_output);
|
252
|
+
g_free(standard_output);
|
253
|
+
} else {
|
254
|
+
std_out = Qnil;
|
255
|
+
standard_output = NULL;
|
256
|
+
}
|
257
|
+
if (standard_error) {
|
258
|
+
std_err = CSTR2RVAL(standard_error);
|
259
|
+
g_free(standard_error);
|
260
|
+
standard_error = NULL;
|
261
|
+
} else {
|
262
|
+
std_err = Qnil;
|
263
|
+
}
|
264
|
+
|
265
|
+
if (! ret)
|
266
|
+
RAISE_GERROR(err);
|
267
|
+
|
268
|
+
return rb_ary_new3(3, std_out, std_err, INT2FIX(exit_status));
|
269
|
+
}
|
270
|
+
|
271
|
+
static VALUE
|
272
|
+
rbglib_m_spawn_command_line_async(self, str)
|
273
|
+
VALUE self, str;
|
274
|
+
{
|
275
|
+
GError *err = NULL;
|
276
|
+
const gchar *command_line;
|
277
|
+
VALUE ret;
|
278
|
+
|
279
|
+
command_line = StringValuePtr(str);
|
280
|
+
ret = CBOOL2RVAL(g_spawn_command_line_async(command_line, &err));
|
281
|
+
if (err != NULL)
|
282
|
+
RAISE_GERROR(err);
|
283
|
+
|
284
|
+
return ret;
|
285
|
+
}
|
286
|
+
|
287
|
+
#ifdef HAVE_G_SPAWN_CLOSE_PID
|
288
|
+
static VALUE
|
289
|
+
rbglib_m_spawn_close_pid(self, pid)
|
290
|
+
VALUE self, pid;
|
291
|
+
{
|
292
|
+
g_spawn_close_pid(NUM2INT(pid));
|
293
|
+
return Qnil;
|
294
|
+
}
|
295
|
+
#endif
|
296
|
+
|
297
|
+
void
|
298
|
+
Init_glib_spawn()
|
299
|
+
{
|
300
|
+
VALUE mGSpawn = rb_define_module_under(mGLib, "Spawn");
|
301
|
+
VALUE cSpawnError = G_DEF_ERROR2(G_SPAWN_ERROR, "SpawnError", mGLib, rb_eIOError);
|
302
|
+
|
303
|
+
id_call = rb_intern("call");
|
304
|
+
id_new = rb_intern("new");
|
305
|
+
|
306
|
+
/* glib/gspawn.h */
|
307
|
+
rb_define_module_function(mGSpawn, "async_with_pipes", rbglib_m_spawn_async_with_pipes, 4);
|
308
|
+
rb_define_module_function(mGSpawn, "async", rbglib_m_spawn_async, 4);
|
309
|
+
rb_define_module_function(mGSpawn, "sync", rbglib_m_spawn_sync, 4);
|
310
|
+
rb_define_module_function(mGSpawn, "command_line_sync", rbglib_m_spawn_command_line_sync, 1);
|
311
|
+
rb_define_module_function(mGSpawn, "command_line_async", rbglib_m_spawn_command_line_async, 1);
|
312
|
+
#ifdef HAVE_G_SPAWN_CLOSE_PID
|
313
|
+
rb_define_module_function(mGSpawn, "close_pid", rbglib_m_spawn_close_pid, 1);
|
314
|
+
#endif
|
315
|
+
|
316
|
+
rb_define_const(mGSpawn, "LEAVE_DESCRIPTORS_OPEN", INT2NUM(G_SPAWN_LEAVE_DESCRIPTORS_OPEN));
|
317
|
+
rb_define_const(mGSpawn, "DO_NOT_REAP_CHILD", INT2NUM(G_SPAWN_DO_NOT_REAP_CHILD));
|
318
|
+
rb_define_const(mGSpawn, "SEARCH_PATH", INT2NUM(G_SPAWN_SEARCH_PATH));
|
319
|
+
rb_define_const(mGSpawn, "STDOUT_TO_DEV_NULL", INT2NUM(G_SPAWN_STDOUT_TO_DEV_NULL));
|
320
|
+
rb_define_const(mGSpawn, "STDERR_TO_DEV_NULL", INT2NUM(G_SPAWN_STDERR_TO_DEV_NULL));
|
321
|
+
rb_define_const(mGSpawn, "CHILD_INHERITS_STDIN", INT2NUM(G_SPAWN_CHILD_INHERITS_STDIN));
|
322
|
+
rb_define_const(mGSpawn, "FILE_AND_ARGV_ZERO", INT2NUM(G_SPAWN_FILE_AND_ARGV_ZERO));
|
323
|
+
|
324
|
+
rb_define_const(cSpawnError, "FORK", INT2NUM(G_SPAWN_ERROR_FORK));
|
325
|
+
rb_define_const(cSpawnError, "READ", INT2NUM(G_SPAWN_ERROR_READ));
|
326
|
+
rb_define_const(cSpawnError, "CHDIR", INT2NUM(G_SPAWN_ERROR_CHDIR));
|
327
|
+
rb_define_const(cSpawnError, "EACCES", INT2NUM(G_SPAWN_ERROR_ACCES));
|
328
|
+
rb_define_const(cSpawnError, "EPERM", INT2NUM(G_SPAWN_ERROR_PERM));
|
329
|
+
rb_define_const(cSpawnError, "E2BIG", INT2NUM(G_SPAWN_ERROR_2BIG));
|
330
|
+
rb_define_const(cSpawnError, "ENOEXEC", INT2NUM(G_SPAWN_ERROR_NOEXEC));
|
331
|
+
rb_define_const(cSpawnError, "ENAMETOOLONG", INT2NUM(G_SPAWN_ERROR_NAMETOOLONG));
|
332
|
+
rb_define_const(cSpawnError, "ENOENT", INT2NUM(G_SPAWN_ERROR_NOENT));
|
333
|
+
rb_define_const(cSpawnError, "ENOMEM", INT2NUM(G_SPAWN_ERROR_NOMEM));
|
334
|
+
rb_define_const(cSpawnError, "ENOTDIR", INT2NUM(G_SPAWN_ERROR_NOTDIR));
|
335
|
+
rb_define_const(cSpawnError, "ELOOP", INT2NUM(G_SPAWN_ERROR_LOOP));
|
336
|
+
rb_define_const(cSpawnError, "ETXTBUSY", INT2NUM(G_SPAWN_ERROR_TXTBUSY));
|
337
|
+
rb_define_const(cSpawnError, "EIO", INT2NUM(G_SPAWN_ERROR_IO));
|
338
|
+
rb_define_const(cSpawnError, "ENFILE", INT2NUM(G_SPAWN_ERROR_NFILE));
|
339
|
+
rb_define_const(cSpawnError, "EMFILE", INT2NUM(G_SPAWN_ERROR_MFILE));
|
340
|
+
rb_define_const(cSpawnError, "EINVAL", INT2NUM(G_SPAWN_ERROR_INVAL));
|
341
|
+
rb_define_const(cSpawnError, "EISDIR", INT2NUM(G_SPAWN_ERROR_ISDIR));
|
342
|
+
rb_define_const(cSpawnError, "ELIBBAD", INT2NUM(G_SPAWN_ERROR_LIBBAD));
|
343
|
+
rb_define_const(cSpawnError, "FAILED", INT2NUM(G_SPAWN_ERROR_FAILED));
|
344
|
+
|
345
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbglib_threads.c -
|
5
|
+
|
6
|
+
$Author: mutoh $
|
7
|
+
$Date: 2005/03/06 14:10:17 $
|
8
|
+
|
9
|
+
Copyright (C) 2005 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#include "rbgprivate.h"
|
13
|
+
|
14
|
+
static VALUE gthreads;
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
gt_init(self)
|
18
|
+
VALUE self;
|
19
|
+
{
|
20
|
+
#ifdef HAVE_G_THREAD_INIT
|
21
|
+
#ifdef G_THREADS_ENABLED
|
22
|
+
g_thread_init(NULL);
|
23
|
+
#endif
|
24
|
+
#endif
|
25
|
+
return self;
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE
|
29
|
+
gt_supported(self)
|
30
|
+
VALUE self;
|
31
|
+
{
|
32
|
+
#ifdef HAVE_G_THREAD_INIT
|
33
|
+
#ifdef G_THREADS_ENABLED
|
34
|
+
return CBOOL2RVAL(g_thread_supported());
|
35
|
+
#else
|
36
|
+
return Qfalse;
|
37
|
+
#endif
|
38
|
+
#else
|
39
|
+
return Qfalse;
|
40
|
+
#endif
|
41
|
+
|
42
|
+
}
|
43
|
+
|
44
|
+
void
|
45
|
+
Init_glib_threads()
|
46
|
+
{
|
47
|
+
gthreads = rb_define_class_under(mGLib, "Thread", rb_cObject);
|
48
|
+
|
49
|
+
rb_define_singleton_method(gthreads, "init", gt_init, 0);
|
50
|
+
rb_define_singleton_method(gthreads, "supported?", gt_supported, 0);
|
51
|
+
}
|
data/src/rbglib_timer.c
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbglib_timer.c -
|
5
|
+
|
6
|
+
$Author: mutoh $
|
7
|
+
$Date: 2005/11/23 14:27:58 $
|
8
|
+
|
9
|
+
Copyright (C) 2005 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#include "rbgprivate.h"
|
13
|
+
|
14
|
+
#ifdef G_OS_WIN32
|
15
|
+
#include <windows.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
/*****************************************/
|
19
|
+
|
20
|
+
/* This is stolen from gtimer.c of glib-2.6.2. */
|
21
|
+
struct _GTimer
|
22
|
+
{
|
23
|
+
#ifdef G_OS_WIN32
|
24
|
+
DWORD start;
|
25
|
+
DWORD end;
|
26
|
+
#else /* !G_OS_WIN32 */
|
27
|
+
struct timeval start;
|
28
|
+
struct timeval end;
|
29
|
+
#endif /* !G_OS_WIN32 */
|
30
|
+
|
31
|
+
guint active : 1;
|
32
|
+
};
|
33
|
+
|
34
|
+
static GTimer*
|
35
|
+
timer_copy(timer)
|
36
|
+
GTimer* timer;
|
37
|
+
{
|
38
|
+
GTimer* new_timer;
|
39
|
+
g_return_val_if_fail (timer != NULL, NULL);
|
40
|
+
|
41
|
+
new_timer = g_new(struct _GTimer, 1);
|
42
|
+
*new_timer = *timer;
|
43
|
+
return new_timer;
|
44
|
+
}
|
45
|
+
|
46
|
+
GType
|
47
|
+
g_timer_get_type(void)
|
48
|
+
{
|
49
|
+
static GType our_type = 0;
|
50
|
+
if (our_type == 0)
|
51
|
+
our_type = g_boxed_type_register_static ("GTimer",
|
52
|
+
(GBoxedCopyFunc)timer_copy,
|
53
|
+
(GBoxedFreeFunc)g_timer_destroy);
|
54
|
+
return our_type;
|
55
|
+
}
|
56
|
+
/*****************************************/
|
57
|
+
|
58
|
+
#define G_TYPE_TIMER (g_timer_get_type())
|
59
|
+
|
60
|
+
#define _SELF(s) ((GTimer*)RVAL2BOXED(s, G_TYPE_TIMER))
|
61
|
+
|
62
|
+
static VALUE
|
63
|
+
timer_initialize(self)
|
64
|
+
VALUE self;
|
65
|
+
{
|
66
|
+
G_INITIALIZE(self, g_timer_new());
|
67
|
+
return Qnil;
|
68
|
+
}
|
69
|
+
|
70
|
+
static VALUE
|
71
|
+
timer_start(self)
|
72
|
+
VALUE self;
|
73
|
+
{
|
74
|
+
g_timer_start(_SELF(self));
|
75
|
+
return self;
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE
|
79
|
+
timer_stop(self)
|
80
|
+
VALUE self;
|
81
|
+
{
|
82
|
+
g_timer_stop(_SELF(self));
|
83
|
+
return self;
|
84
|
+
}
|
85
|
+
|
86
|
+
#if GLIB_CHECK_VERSION(2,4,0)
|
87
|
+
static VALUE
|
88
|
+
timer_continue(self)
|
89
|
+
VALUE self;
|
90
|
+
{
|
91
|
+
g_timer_continue(_SELF(self));
|
92
|
+
return self;
|
93
|
+
}
|
94
|
+
#endif
|
95
|
+
|
96
|
+
static VALUE
|
97
|
+
timer_elapsed(self)
|
98
|
+
VALUE self;
|
99
|
+
{
|
100
|
+
gulong microseconds;
|
101
|
+
gdouble ret = g_timer_elapsed(_SELF(self), µseconds);
|
102
|
+
|
103
|
+
return rb_assoc_new(rb_float_new(ret), ULONG2NUM(microseconds));
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE
|
107
|
+
timer_reset(self)
|
108
|
+
VALUE self;
|
109
|
+
{
|
110
|
+
g_timer_reset(_SELF(self));
|
111
|
+
return self;
|
112
|
+
}
|
113
|
+
|
114
|
+
void
|
115
|
+
Init_glib_timer()
|
116
|
+
{
|
117
|
+
VALUE timer = G_DEF_CLASS(G_TYPE_TIMER, "Timer", mGLib);
|
118
|
+
|
119
|
+
rb_define_method(timer, "initialize", timer_initialize, 0);
|
120
|
+
rb_define_method(timer, "start", timer_start, 0);
|
121
|
+
rb_define_method(timer, "stop", timer_stop, 0);
|
122
|
+
#if GLIB_CHECK_VERSION(2,4,0)
|
123
|
+
rb_define_method(timer, "continue", timer_continue, 0);
|
124
|
+
#endif
|
125
|
+
rb_define_method(timer, "elapsed", timer_elapsed, 0);
|
126
|
+
rb_define_method(timer, "reset", timer_reset, 0);
|
127
|
+
}
|