glib2 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/ChangeLog +3023 -0
  2. data/README +28 -0
  3. data/Rakefile +87 -0
  4. data/extconf.rb +61 -0
  5. data/sample/bookmarkfile.rb +66 -0
  6. data/sample/completion.rb +45 -0
  7. data/sample/idle.rb +41 -0
  8. data/sample/iochannel.rb +44 -0
  9. data/sample/keyfile.rb +62 -0
  10. data/sample/shell.rb +36 -0
  11. data/sample/spawn.rb +25 -0
  12. data/sample/timeout.rb +28 -0
  13. data/sample/timeout2.rb +35 -0
  14. data/sample/timer.rb +40 -0
  15. data/sample/type-register.rb +103 -0
  16. data/sample/type-register2.rb +104 -0
  17. data/sample/utils.rb +54 -0
  18. data/src/glib-enum-types.c +1032 -0
  19. data/src/glib-enum-types.h +140 -0
  20. data/src/lib/glib-mkenums.rb +199 -0
  21. data/src/lib/glib2.rb +220 -0
  22. data/src/lib/mkmf-gnome2.rb +390 -0
  23. data/src/lib/pkg-config.rb +137 -0
  24. data/src/rbgcompat.h +30 -0
  25. data/src/rbglib.c +320 -0
  26. data/src/rbglib.h +96 -0
  27. data/src/rbglib_bookmarkfile.c +595 -0
  28. data/src/rbglib_completion.c +192 -0
  29. data/src/rbglib_convert.c +195 -0
  30. data/src/rbglib_error.c +95 -0
  31. data/src/rbglib_fileutils.c +83 -0
  32. data/src/rbglib_i18n.c +44 -0
  33. data/src/rbglib_int64.c +157 -0
  34. data/src/rbglib_iochannel.c +883 -0
  35. data/src/rbglib_keyfile.c +846 -0
  36. data/src/rbglib_maincontext.c +917 -0
  37. data/src/rbglib_mainloop.c +87 -0
  38. data/src/rbglib_messages.c +150 -0
  39. data/src/rbglib_pollfd.c +111 -0
  40. data/src/rbglib_shell.c +68 -0
  41. data/src/rbglib_source.c +190 -0
  42. data/src/rbglib_spawn.c +345 -0
  43. data/src/rbglib_threads.c +51 -0
  44. data/src/rbglib_timer.c +127 -0
  45. data/src/rbglib_unicode.c +611 -0
  46. data/src/rbglib_utils.c +386 -0
  47. data/src/rbglib_win32.c +136 -0
  48. data/src/rbgobj_boxed.c +251 -0
  49. data/src/rbgobj_closure.c +337 -0
  50. data/src/rbgobj_convert.c +167 -0
  51. data/src/rbgobj_enums.c +961 -0
  52. data/src/rbgobj_fundamental.c +30 -0
  53. data/src/rbgobj_object.c +892 -0
  54. data/src/rbgobj_param.c +390 -0
  55. data/src/rbgobj_paramspecs.c +305 -0
  56. data/src/rbgobj_signal.c +963 -0
  57. data/src/rbgobj_strv.c +61 -0
  58. data/src/rbgobj_type.c +851 -0
  59. data/src/rbgobj_typeinstance.c +121 -0
  60. data/src/rbgobj_typeinterface.c +148 -0
  61. data/src/rbgobj_typemodule.c +66 -0
  62. data/src/rbgobj_typeplugin.c +49 -0
  63. data/src/rbgobj_value.c +313 -0
  64. data/src/rbgobj_valuearray.c +59 -0
  65. data/src/rbgobj_valuetypes.c +298 -0
  66. data/src/rbgobject.c +406 -0
  67. data/src/rbgobject.h +265 -0
  68. data/src/rbgprivate.h +88 -0
  69. data/src/rbgutil.c +222 -0
  70. data/src/rbgutil.h +82 -0
  71. data/src/rbgutil_callback.c +231 -0
  72. data/test/glib-test-init.rb +6 -0
  73. data/test/glib-test-utils.rb +12 -0
  74. data/test/run-test.rb +25 -0
  75. data/test/test_enum.rb +99 -0
  76. data/test/test_file_utils.rb +15 -0
  77. data/test/test_glib2.rb +120 -0
  78. data/test/test_iochannel.rb +275 -0
  79. data/test/test_key_file.rb +38 -0
  80. data/test/test_mkenums.rb +25 -0
  81. data/test/test_signal.rb +20 -0
  82. data/test/test_timeout.rb +28 -0
  83. data/test/test_unicode.rb +369 -0
  84. data/test/test_utils.rb +37 -0
  85. data/test/test_win32.rb +13 -0
  86. metadata +165 -0
@@ -0,0 +1,87 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_mainloop.c -
5
+
6
+ $Author: ktou $
7
+ $Date: 2007/10/03 11:06:01 $
8
+
9
+ Copyright (C) 2005,2006 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ /*****************************************/
15
+ GType
16
+ g_main_loop_get_type(void)
17
+ {
18
+ static GType our_type = 0;
19
+ if (our_type == 0)
20
+ our_type = g_boxed_type_register_static ("GMainLoop",
21
+ (GBoxedCopyFunc)g_main_loop_ref,
22
+ (GBoxedFreeFunc)g_main_loop_unref);
23
+ return our_type;
24
+ }
25
+ /*****************************************/
26
+
27
+ #define _SELF(s) ((GMainLoop*)RVAL2BOXED(s, G_TYPE_MAIN_LOOP))
28
+
29
+ /*****************************************/
30
+
31
+ static VALUE
32
+ ml_initialize(int argc, VALUE *argv, VALUE self)
33
+ {
34
+ VALUE context, is_running;
35
+ GMainLoop *loop;
36
+ GMainContext *main_context = NULL;
37
+
38
+ rb_scan_args(argc, argv, "02", &context, &is_running);
39
+
40
+ if (!NIL_P(context))
41
+ main_context = RVAL2BOXED(context, G_TYPE_MAIN_CONTEXT);
42
+ loop = g_main_loop_new(main_context, RVAL2CBOOL(is_running));
43
+ G_INITIALIZE(self, loop);
44
+ return Qnil;
45
+ }
46
+
47
+ static VALUE
48
+ ml_run(self)
49
+ VALUE self;
50
+ {
51
+ g_main_loop_run(_SELF(self));
52
+ return self;
53
+ }
54
+
55
+ static VALUE
56
+ ml_quit(self)
57
+ VALUE self;
58
+ {
59
+ g_main_loop_quit(_SELF(self));
60
+ return Qnil;
61
+ }
62
+
63
+ static VALUE
64
+ ml_is_running(self)
65
+ VALUE self;
66
+ {
67
+ return CBOOL2RVAL(g_main_loop_is_running(_SELF(self)));
68
+ }
69
+
70
+ static VALUE
71
+ ml_get_context(self)
72
+ VALUE self;
73
+ {
74
+ return BOXED2RVAL(g_main_loop_get_context(_SELF(self)), G_TYPE_MAIN_CONTEXT);
75
+ }
76
+
77
+ void
78
+ Init_glib_main_loop()
79
+ {
80
+ VALUE ml = G_DEF_CLASS(G_TYPE_MAIN_LOOP, "MainLoop", mGLib);
81
+
82
+ rb_define_method(ml, "initialize", ml_initialize, -1);
83
+ rb_define_method(ml, "run", ml_run, 0);
84
+ rb_define_method(ml, "quit", ml_quit, 0);
85
+ rb_define_method(ml, "running?", ml_is_running, 0);
86
+ rb_define_method(ml, "context", ml_get_context, 0);
87
+ }
@@ -0,0 +1,150 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_messages.c -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/07 14:03:35 $
8
+
9
+ Copyright (C) 2002-2005 Masao Mutoh
10
+
11
+ This file is devided from rbgtkmain.c.
12
+ rbgtkmain.c -
13
+ Copyright (C) 1998-2000 Yukihiro Matsumoto,
14
+ Daisuke Kanda,
15
+ Hiroshi Igarashi
16
+ ************************************************/
17
+
18
+ #include "rbgprivate.h"
19
+
20
+ #ifndef HAVE_RB_SOURCEFILE
21
+ #define rb_sourcefile() (ruby_sourcefile)
22
+ #endif
23
+
24
+ #ifndef HAVE_RB_SOURCELINE
25
+ #define rb_sourceline() (ruby_sourceline)
26
+ #endif
27
+
28
+ static VALUE rbglib_log_handler_procs;
29
+ static ID id_call;
30
+ static gboolean log_canceled;
31
+
32
+ static gchar* logmessage(GLogLevelFlags level)
33
+ {
34
+ if (level & G_LOG_LEVEL_ERROR){
35
+ return "ERROR";
36
+ } else if (level & G_LOG_LEVEL_CRITICAL){
37
+ return "CRITICAL";
38
+ } else if (level & G_LOG_LEVEL_WARNING){
39
+ return "WARNING";
40
+ } else if (level & G_LOG_LEVEL_MESSAGE){
41
+ return "MESSAGE";
42
+ } else if (level & G_LOG_LEVEL_INFO){
43
+ return "INFO";
44
+ } else if (level & G_LOG_LEVEL_DEBUG){
45
+ return "DEBUG";
46
+ }
47
+ return "UNKNOWN";
48
+ }
49
+
50
+ static void
51
+ rbglib_log_handler(log_domain, log_level, message, user_data)
52
+ const gchar *log_domain;
53
+ GLogLevelFlags log_level;
54
+ const gchar *message;
55
+ gpointer user_data;
56
+ {
57
+ if (! log_canceled){
58
+ #ifdef HAVE_RUBY_SET_CURRENT_SOURCE
59
+ ruby_set_current_source();
60
+ #endif
61
+ g_printerr("%s: line %d\n", rb_sourcefile(), rb_sourceline());
62
+ g_printerr(" %s-%s **:%s\n", log_domain, logmessage(log_level), message);
63
+ } else {
64
+ g_log_default_handler(log_domain, log_level, message, user_data);
65
+ }
66
+ }
67
+
68
+ /* Use Internal only */
69
+ static VALUE
70
+ rbglib_m_log_cancel_handler(self)
71
+ VALUE self;
72
+ {
73
+ log_canceled = TRUE;
74
+ return Qnil;
75
+ }
76
+
77
+ static VALUE
78
+ rbglib_m_log_set_handler(self, domain, levels)
79
+ VALUE self, domain, levels;
80
+ {
81
+ guint handler_id = g_log_set_handler(NIL_P(domain) ? NULL : RVAL2CSTR(domain),
82
+ NUM2INT(levels),
83
+ (GLogFunc)rbglib_log_handler, (gpointer)self);
84
+ return UINT2NUM(handler_id);
85
+ }
86
+
87
+ static VALUE
88
+ rbglib_m_log_remove_handler(self, domain, handler_id)
89
+ VALUE self, domain, handler_id;
90
+ {
91
+ g_log_remove_handler(NIL_P(domain) ? NULL : RVAL2CSTR(domain),
92
+ NUM2UINT(handler_id));
93
+ G_REMOVE_RELATIVE(self, handler_id, rbglib_log_handler_procs);
94
+ return Qnil;
95
+ }
96
+
97
+ static VALUE
98
+ rbglib_m_log_set_always_fatal(self, fatal_mask)
99
+ VALUE self, fatal_mask;
100
+ {
101
+ return INT2NUM(g_log_set_always_fatal(NUM2INT(fatal_mask)));
102
+ }
103
+
104
+ static VALUE
105
+ rbglib_m_log_set_fatal_mask(self, domain, fatal_mask)
106
+ VALUE self, domain, fatal_mask;
107
+ {
108
+ return INT2NUM(g_log_set_fatal_mask(NIL_P(domain) ? NULL : RVAL2CSTR(domain),
109
+ NUM2INT(fatal_mask)));
110
+ }
111
+
112
+ static VALUE
113
+ rbglib_m_log(self, domain, level, str)
114
+ VALUE self, domain, level, str;
115
+ {
116
+ g_log(NIL_P(domain) ? NULL : RVAL2CSTR(domain), NUM2INT(level), RVAL2CSTR(str), NULL);
117
+ return Qnil;
118
+ }
119
+
120
+ void
121
+ Init_glib_messages()
122
+ {
123
+ VALUE mGLog = rb_define_module_under(mGLib, "Log");
124
+
125
+ id_call = rb_intern("call");
126
+ log_canceled = FALSE;
127
+
128
+ rb_global_variable(&rbglib_log_handler_procs);
129
+ rbglib_log_handler_procs = rb_hash_new();
130
+ rb_define_module_function(mGLog, "set_handler", rbglib_m_log_set_handler, 2);
131
+ rb_define_module_function(mGLog, "remove_handler", rbglib_m_log_remove_handler, 2);
132
+ rb_define_module_function(mGLog, "cancel_handler", rbglib_m_log_cancel_handler, 0);
133
+ rb_define_module_function(mGLog, "set_always_fatal", rbglib_m_log_set_always_fatal, 1);
134
+ rb_define_module_function(mGLog, "set_fatal_mask", rbglib_m_log_set_fatal_mask, 2);
135
+ rb_define_module_function(mGLog, "log", rbglib_m_log, 3);
136
+
137
+ rb_define_const(mGLog, "FATAL_MASK", INT2NUM(G_LOG_FATAL_MASK));
138
+ rb_define_const(mGLog, "LEVEL_USER_SHIFT", INT2NUM(G_LOG_LEVEL_USER_SHIFT));
139
+
140
+ /* GLogLevelFlags */
141
+ rb_define_const(mGLog, "FLAG_RECURSION", INT2NUM(G_LOG_FLAG_RECURSION));
142
+ rb_define_const(mGLog, "FLAG_FATAL", INT2NUM(G_LOG_FLAG_FATAL));
143
+ rb_define_const(mGLog, "LEVEL_ERROR", INT2NUM(G_LOG_LEVEL_ERROR));
144
+ rb_define_const(mGLog, "LEVEL_CRITICAL", INT2NUM(G_LOG_LEVEL_CRITICAL));
145
+ rb_define_const(mGLog, "LEVEL_WARNING", INT2NUM(G_LOG_LEVEL_WARNING));
146
+ rb_define_const(mGLog, "LEVEL_MESSAGE", INT2NUM(G_LOG_LEVEL_MESSAGE));
147
+ rb_define_const(mGLog, "LEVEL_INFO", INT2NUM(G_LOG_LEVEL_INFO));
148
+ rb_define_const(mGLog, "LEVEL_DEBUG", INT2NUM(G_LOG_LEVEL_DEBUG));
149
+ rb_define_const(mGLog, "LEVEL_MASK", INT2NUM(G_LOG_LEVEL_MASK));
150
+ }
@@ -0,0 +1,111 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_pollfd.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2005/03/12 18:03:56 $
8
+
9
+ Copyright (C) 2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ /*****************************************/
15
+ static GPollFD*
16
+ pollfd_copy(const GPollFD* pollfd)
17
+ {
18
+ GPollFD* new_pollfd;
19
+ g_return_val_if_fail (pollfd != NULL, NULL);
20
+
21
+ new_pollfd = g_new(GPollFD, 1);
22
+ *new_pollfd = *pollfd;
23
+ return new_pollfd;
24
+ }
25
+
26
+ GType
27
+ g_poll_fd_get_type(void)
28
+ {
29
+ static GType our_type = 0;
30
+ if (our_type == 0)
31
+ our_type = g_boxed_type_register_static ("GPollFD",
32
+ (GBoxedCopyFunc)pollfd_copy,
33
+ (GBoxedFreeFunc)g_free);
34
+ return our_type;
35
+ }
36
+ /*****************************************/
37
+
38
+ #define _SELF(s) ((GPollFD*)RVAL2BOXED(s, G_TYPE_POLL_FD))
39
+
40
+ static VALUE
41
+ poll_initialize(self, fd, events, revents)
42
+ VALUE self, fd, events, revents;
43
+ {
44
+ GPollFD gfd;
45
+ gfd.fd = NUM2INT(fd);
46
+ gfd.events = NUM2INT(events);
47
+ gfd.revents = NUM2INT(revents);
48
+
49
+ G_INITIALIZE(self, &gfd);
50
+ return Qnil;
51
+ }
52
+
53
+ static VALUE
54
+ poll_set_fd(self, fd)
55
+ VALUE self, fd;
56
+ {
57
+ _SELF(self)->fd = fd;
58
+ return self;
59
+ }
60
+ static VALUE
61
+ poll_fd(self)
62
+ VALUE self;
63
+ {
64
+ return INT2NUM(_SELF(self)->fd);
65
+ }
66
+
67
+ static VALUE
68
+ poll_set_events(self, events)
69
+ VALUE self, events;
70
+ {
71
+ _SELF(self)->events = events;
72
+ return self;
73
+ }
74
+ static VALUE
75
+ poll_events(self)
76
+ VALUE self;
77
+ {
78
+ return INT2NUM(_SELF(self)->events);
79
+ }
80
+
81
+ static VALUE
82
+ poll_set_revents(self, revents)
83
+ VALUE self, revents;
84
+ {
85
+ _SELF(self)->revents = revents;
86
+ return self;
87
+ }
88
+ static VALUE
89
+ poll_revents(self)
90
+ VALUE self;
91
+ {
92
+ return INT2NUM(_SELF(self)->revents);
93
+ }
94
+
95
+ void
96
+ Init_glib_poll_fd()
97
+ {
98
+ VALUE fd = G_DEF_CLASS(G_TYPE_POLL_FD, "PollFD", mGLib);
99
+
100
+ rb_define_method(fd, "initialize", poll_initialize, 3);
101
+
102
+ rb_define_method(fd, "set_fd", poll_set_fd, 1);
103
+ rb_define_method(fd, "fd", poll_fd, 0);
104
+ rb_define_method(fd, "set_events", poll_set_events, 1);
105
+ rb_define_method(fd, "events", poll_events, 0);
106
+ rb_define_method(fd, "set_revents", poll_set_revents, 1);
107
+ rb_define_method(fd, "revents", poll_revents, 0);
108
+
109
+ G_DEF_SETTERS(fd);
110
+
111
+ }
@@ -0,0 +1,68 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_shell.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2005/10/14 19:10:08 $
8
+
9
+ Copyright (C) 2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ static VALUE
15
+ shell_parse(self, command_line)
16
+ VALUE self, command_line;
17
+ {
18
+ gint argc, i;
19
+ gchar** argv;
20
+ GError* err = NULL;
21
+ VALUE ary;
22
+
23
+ gboolean ret = g_shell_parse_argv(RVAL2CSTR(command_line),
24
+ &argc, &argv, &err);
25
+
26
+ if (! ret) RAISE_GERROR(err);
27
+
28
+ ary = rb_ary_new();
29
+ for (i = 0; i < argc; i++) {
30
+ rb_ary_push(ary, CSTR2RVAL(argv[i]));
31
+ }
32
+ g_strfreev (argv);
33
+ return ary;
34
+ }
35
+
36
+ static VALUE
37
+ shell_quote(self, unquoted_string)
38
+ VALUE self, unquoted_string;
39
+ {
40
+ return CSTR2RVAL2(g_shell_quote((const gchar*)RVAL2CSTR(unquoted_string)));
41
+ }
42
+
43
+ static VALUE
44
+ shell_unquote(self, quoted_string)
45
+ VALUE self, quoted_string;
46
+ {
47
+ GError* err = NULL;
48
+ gchar* str = g_shell_unquote((const gchar*)RVAL2CSTR(quoted_string), &err);
49
+
50
+ if (! str) RAISE_GERROR(err);
51
+
52
+ return CSTR2RVAL2(str);
53
+ }
54
+
55
+ void
56
+ Init_glib_shell()
57
+ {
58
+ VALUE mShell = rb_define_module_under(mGLib, "Shell");
59
+ VALUE cShellError = G_DEF_ERROR2(G_SHELL_ERROR, "ShellError", mGLib, rb_eRuntimeError);
60
+
61
+ rb_define_module_function(mShell, "parse", shell_parse, 1);
62
+ rb_define_module_function(mShell, "quote", shell_quote, 1);
63
+ rb_define_module_function(mShell, "unquote", shell_unquote, 1);
64
+
65
+ rb_define_const(cShellError, "BAD_QUOTING", INT2FIX(G_SHELL_ERROR_BAD_QUOTING));
66
+ rb_define_const(cShellError, "EMPTY_STRING", INT2FIX(G_SHELL_ERROR_EMPTY_STRING));
67
+ rb_define_const(cShellError, "FAILED", INT2FIX(G_SHELL_ERROR_FAILED));
68
+ }
@@ -0,0 +1,190 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_source.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:28 $
8
+
9
+ Copyright (C) 2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ static ID id_call;
15
+
16
+ /*****************************************/
17
+ static void
18
+ source_free(source)
19
+ GSource* source;
20
+ {
21
+ g_source_unref(source);
22
+ g_source_destroy(source);
23
+ }
24
+
25
+ GType
26
+ g_source_get_type(void)
27
+ {
28
+ static GType our_type = 0;
29
+ if (our_type == 0)
30
+ our_type = g_boxed_type_register_static ("GSource",
31
+ (GBoxedCopyFunc)g_source_ref,
32
+ (GBoxedFreeFunc)source_free);
33
+ return our_type;
34
+ }
35
+ /*****************************************/
36
+
37
+ #define _SELF(s) ((GSource*)RVAL2BOXED(s, G_TYPE_SOURCE))
38
+
39
+ /*
40
+ GSource* g_source_new (GSourceFuncs *source_funcs,
41
+ guint struct_size);
42
+ */
43
+
44
+ static VALUE
45
+ source_attach(self, context)
46
+ VALUE self, context;
47
+ {
48
+ return UINT2NUM(g_source_attach(_SELF(self),
49
+ RVAL2BOXED(context, G_TYPE_MAIN_CONTEXT)));
50
+ }
51
+
52
+ #if GLIB_CHECK_VERSION(2,12,0)
53
+ static VALUE
54
+ source_is_destroyed(self)
55
+ VALUE self;
56
+ {
57
+ return CBOOL2RVAL(g_source_is_destroyed(_SELF(self)));
58
+ }
59
+ #endif
60
+
61
+ static VALUE
62
+ source_set_priority(self, priority)
63
+ VALUE self, priority;
64
+ {
65
+ g_source_set_priority(_SELF(self), NUM2INT(priority));
66
+ return self;
67
+ }
68
+
69
+ static VALUE
70
+ source_get_priority(self)
71
+ VALUE self;
72
+ {
73
+ return INT2NUM(g_source_get_priority(_SELF(self)));
74
+ }
75
+
76
+ static VALUE
77
+ source_set_can_recurse(self, can_recurse)
78
+ VALUE self, can_recurse;
79
+ {
80
+ g_source_set_can_recurse(_SELF(self), RVAL2CBOOL(can_recurse));
81
+ return self;
82
+ }
83
+
84
+ static VALUE
85
+ source_get_can_recurse(self)
86
+ VALUE self;
87
+ {
88
+ return CBOOL2RVAL(g_source_get_can_recurse(_SELF(self)));
89
+ }
90
+
91
+ static VALUE
92
+ source_get_id(self)
93
+ VALUE self;
94
+ {
95
+ return UINT2NUM(g_source_get_id(_SELF(self)));
96
+ }
97
+
98
+ static VALUE
99
+ source_get_context(self)
100
+ VALUE self;
101
+ {
102
+ GMainContext* context = g_source_get_context(_SELF(self));
103
+ return BOXED2RVAL(context, G_TYPE_MAIN_CONTEXT);
104
+ }
105
+
106
+ static gboolean
107
+ source_func(func)
108
+ gpointer func;
109
+ {
110
+ return RVAL2CBOOL(rb_funcall((VALUE)func, id_call, 0));
111
+ }
112
+
113
+ static VALUE
114
+ source_set_callback(self)
115
+ VALUE self;
116
+ {
117
+ VALUE func = rb_block_proc();
118
+ G_RELATIVE(self, func);
119
+ g_source_set_callback(_SELF(self),
120
+ (GSourceFunc)source_func,
121
+ (gpointer)func,
122
+ (GDestroyNotify)NULL);
123
+ return self;
124
+ }
125
+
126
+ /*
127
+ void g_source_set_callback_indirect (GSource *source,
128
+ gpointer callback_data,
129
+ GSourceCallbackFuncs *callback_funcs);
130
+ */
131
+
132
+ static VALUE
133
+ source_add_poll(self, fd)
134
+ VALUE self, fd;
135
+ {
136
+ g_source_add_poll(_SELF(self), RVAL2BOXED(fd, G_TYPE_POLL_FD));
137
+ return self;
138
+ }
139
+
140
+ static VALUE
141
+ source_remove_poll(self, fd)
142
+ VALUE self, fd;
143
+ {
144
+ g_source_remove_poll(_SELF(self), RVAL2BOXED(fd, G_TYPE_POLL_FD));
145
+ return self;
146
+ }
147
+
148
+ static VALUE
149
+ source_get_current_time(self)
150
+ VALUE self;
151
+ {
152
+ GTimeVal timeval;
153
+ g_source_get_current_time(_SELF(self), &timeval);
154
+
155
+ return rb_assoc_new(LONG2NUM(timeval.tv_sec), LONG2NUM(timeval.tv_usec));
156
+ }
157
+
158
+ /* How can I implement them ?
159
+ gboolean g_source_remove_by_funcs_user_data
160
+ (GSourceFuncs *funcs,
161
+ gpointer user_data);
162
+ gboolean g_source_remove_by_user_data (gpointer user_data);
163
+ */
164
+
165
+ void
166
+ Init_glib_source()
167
+ {
168
+ VALUE src = G_DEF_CLASS(G_TYPE_SOURCE, "Source", mGLib);
169
+
170
+ id_call = rb_intern("call");
171
+
172
+ rb_define_method(src, "attach", source_attach, 1);
173
+ #if GLIB_CHECK_VERSION(2,12,0)
174
+ rb_define_method(src, "destroyed?", source_is_destroyed, 0);
175
+ #endif
176
+ rb_define_method(src, "set_priority", source_set_priority, 1);
177
+ rb_define_method(src, "priority", source_get_priority, 0);
178
+ rb_define_method(src, "set_can_recurse", source_set_can_recurse, 1);
179
+ rb_define_method(src, "can_recurse?", source_get_can_recurse, 0);
180
+ rb_define_method(src, "id", source_get_id, 0);
181
+ rb_define_method(src, "context", source_get_context, 0);
182
+ rb_define_method(src, "set_callback", source_set_callback, 0);
183
+ rb_define_method(src, "add_poll", source_add_poll, 1);
184
+ rb_define_method(src, "remove_poll", source_remove_poll, 1);
185
+ rb_define_method(src, "current_time", source_get_current_time, 0);
186
+
187
+ /* GLib::Source.remove is moved to rbglib_maincontext.c */
188
+
189
+ G_DEF_SETTERS(src);
190
+ }