gio2 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +26 -9
  3. data/ext/gio2/extconf.rb +38 -28
  4. data/ext/gio2/rb-gio2-pollable-source.c +59 -0
  5. data/ext/gio2/{rbgiofilteroutputstream.c → rb-gio2.c} +9 -5
  6. data/ext/gio2/{gio2.c → rb-gio2.h} +5 -10
  7. data/extconf.rb +22 -6
  8. data/lib/gio2.rb +38 -143
  9. data/lib/gio2/deprecated.rb +16 -0
  10. data/lib/gio2/inet-address.rb +33 -0
  11. data/lib/gio2/input-stream.rb +39 -0
  12. data/lib/gio2/loader.rb +244 -0
  13. data/lib/gio2/output-stream.rb +24 -0
  14. data/lib/gio2/pollable-input-stream.rb +51 -0
  15. data/lib/gio2/pollable-output-stream.rb +32 -0
  16. data/lib/gio2/resources.rb +62 -0
  17. data/test/fixture/content-type/x-content/unix-software/autorun.sh +1 -0
  18. data/test/fixture/resource/Rakefile +32 -0
  19. data/test/fixture/resource/logo.png +0 -0
  20. data/test/fixture/resource/ruby-gio2.gresource +0 -0
  21. data/test/fixture/resource/ruby-gio2.gresource.xml +6 -0
  22. data/test/gio2-test-utils.rb +21 -0
  23. data/test/gio2-test-utils/fixture.rb +24 -0
  24. data/test/gio2-test-utils/socket-client.rb +59 -0
  25. data/test/run-test.rb +45 -9
  26. data/test/test-buffered-input-stream.rb +23 -0
  27. data/test/test-charset-converter.rb +23 -0
  28. data/test/test-content-type.rb +31 -0
  29. data/test/test-data-input-stream.rb +21 -0
  30. data/test/test-file-enumerator.rb +26 -0
  31. data/test/test-file-monitor.rb +33 -0
  32. data/test/test-file.rb +28 -0
  33. data/test/test-inet-address.rb +34 -0
  34. data/test/test-input-stream.rb +36 -0
  35. data/test/test-output-stream.rb +39 -0
  36. data/test/test-pollable-input-stream.rb +54 -0
  37. data/test/test-pollable-output-stream.rb +53 -0
  38. data/test/test-resources.rb +58 -0
  39. metadata +49 -107
  40. data/README +0 -34
  41. data/ext/gio2/depend +0 -11
  42. data/ext/gio2/gio2.def +0 -2
  43. data/ext/gio2/gio2.h +0 -30
  44. data/ext/gio2/rbgio.c +0 -133
  45. data/ext/gio2/rbgio2.h +0 -158
  46. data/ext/gio2/rbgio2conversions.h +0 -154
  47. data/ext/gio2/rbgio2private.h +0 -148
  48. data/ext/gio2/rbgioappinfo.c +0 -317
  49. data/ext/gio2/rbgioapplaunchcontext.c +0 -81
  50. data/ext/gio2/rbgioasyncinitable.c +0 -246
  51. data/ext/gio2/rbgioasyncresult.c +0 -41
  52. data/ext/gio2/rbgiobufferedinputstream.c +0 -167
  53. data/ext/gio2/rbgiobufferedoutputstream.c +0 -50
  54. data/ext/gio2/rbgiocancellable.c +0 -180
  55. data/ext/gio2/rbgiocharsetconverter.c +0 -57
  56. data/ext/gio2/rbgiocontenttype.c +0 -131
  57. data/ext/gio2/rbgioconverter.c +0 -113
  58. data/ext/gio2/rbgioconverterinputstream.c +0 -43
  59. data/ext/gio2/rbgioconverteroutputstream.c +0 -43
  60. data/ext/gio2/rbgiodatainputstream.c +0 -309
  61. data/ext/gio2/rbgiodataoutputstream.c +0 -186
  62. data/ext/gio2/rbgiodesktopappinfo.c +0 -87
  63. data/ext/gio2/rbgiodrive.c +0 -266
  64. data/ext/gio2/rbgioemblem.c +0 -52
  65. data/ext/gio2/rbgioemblemedicon.c +0 -65
  66. data/ext/gio2/rbgiofile.c +0 -2045
  67. data/ext/gio2/rbgiofileattribute.c +0 -114
  68. data/ext/gio2/rbgiofileattributeinfo.c +0 -86
  69. data/ext/gio2/rbgiofileattributeinfolist.c +0 -108
  70. data/ext/gio2/rbgiofileattributematcher.c +0 -95
  71. data/ext/gio2/rbgiofiledescriptorbased.c +0 -45
  72. data/ext/gio2/rbgiofileenumerator.c +0 -166
  73. data/ext/gio2/rbgiofileicon.c +0 -41
  74. data/ext/gio2/rbgiofileinfo.c +0 -617
  75. data/ext/gio2/rbgiofileinputstream.c +0 -91
  76. data/ext/gio2/rbgiofileiostream.c +0 -98
  77. data/ext/gio2/rbgiofilemonitor.c +0 -46
  78. data/ext/gio2/rbgiofilenamecompleter.c +0 -73
  79. data/ext/gio2/rbgiofileoutputstream.c +0 -98
  80. data/ext/gio2/rbgiofilterinputstream.c +0 -28
  81. data/ext/gio2/rbgioicon.c +0 -69
  82. data/ext/gio2/rbgioinetaddress.c +0 -118
  83. data/ext/gio2/rbgioinetsocketaddress.c +0 -41
  84. data/ext/gio2/rbgioinitable.c +0 -199
  85. data/ext/gio2/rbgioinputstream.c +0 -341
  86. data/ext/gio2/rbgioio.c +0 -73
  87. data/ext/gio2/rbgioiomodule.c +0 -45
  88. data/ext/gio2/rbgioiomodules.c +0 -47
  89. data/ext/gio2/rbgioioscheduler.c +0 -102
  90. data/ext/gio2/rbgioioschedulerjob.c +0 -121
  91. data/ext/gio2/rbgioiostream.c +0 -107
  92. data/ext/gio2/rbgioloadableicon.c +0 -92
  93. data/ext/gio2/rbgiomemoryinputstream.c +0 -67
  94. data/ext/gio2/rbgiomemoryoutputstream.c +0 -44
  95. data/ext/gio2/rbgiomount.c +0 -286
  96. data/ext/gio2/rbgiomountoperation.c +0 -53
  97. data/ext/gio2/rbgionetworkaddress.c +0 -59
  98. data/ext/gio2/rbgionetworkservice.c +0 -45
  99. data/ext/gio2/rbgiooutputstream.c +0 -331
  100. data/ext/gio2/rbgioresolver.c +0 -230
  101. data/ext/gio2/rbgioseekable.c +0 -91
  102. data/ext/gio2/rbgiosimpleasyncresult.c +0 -152
  103. data/ext/gio2/rbgiosocket.c +0 -390
  104. data/ext/gio2/rbgiosocketaddress.c +0 -34
  105. data/ext/gio2/rbgiosocketaddressenumerator.c +0 -83
  106. data/ext/gio2/rbgiosocketclient.c +0 -207
  107. data/ext/gio2/rbgiosocketconnectable.c +0 -41
  108. data/ext/gio2/rbgiosocketconnection.c +0 -66
  109. data/ext/gio2/rbgiosocketconnectionfactory.c +0 -39
  110. data/ext/gio2/rbgiosocketcontrolmessage.c +0 -82
  111. data/ext/gio2/rbgiosocketlistener.c +0 -246
  112. data/ext/gio2/rbgiosocketservice.c +0 -66
  113. data/ext/gio2/rbgiosrvtarget.c +0 -76
  114. data/ext/gio2/rbgiotcpconnection.c +0 -28
  115. data/ext/gio2/rbgiothemedicon.c +0 -83
  116. data/ext/gio2/rbgiothreadedsocketservice.c +0 -43
  117. data/ext/gio2/rbgiotlscertificate.c +0 -89
  118. data/ext/gio2/rbgiounixconnection.c +0 -71
  119. data/ext/gio2/rbgiounixfdlist.c +0 -115
  120. data/ext/gio2/rbgiounixfdmessage.c +0 -74
  121. data/ext/gio2/rbgiounixinputstream.c +0 -51
  122. data/ext/gio2/rbgiounixmount.c +0 -164
  123. data/ext/gio2/rbgiounixmountmonitor.c +0 -65
  124. data/ext/gio2/rbgiounixmountpoint.c +0 -136
  125. data/ext/gio2/rbgiounixmountpoints.c +0 -58
  126. data/ext/gio2/rbgiounixmounts.c +0 -58
  127. data/ext/gio2/rbgiounixoutputstream.c +0 -51
  128. data/ext/gio2/rbgiounixsocketaddress.c +0 -69
  129. data/ext/gio2/rbgiovfs.c +0 -84
  130. data/ext/gio2/rbgiovolume.c +0 -193
  131. data/ext/gio2/rbgiovolumemonitor.c +0 -77
  132. data/ext/gio2/rbgiozlibcompressor.c +0 -52
  133. data/ext/gio2/rbgiozlibdecompressor.c +0 -45
  134. data/ext/gio2/util.c +0 -303
  135. data/test/test_bufferedinputstream.rb +0 -9
  136. data/test/test_charsetconverter.rb +0 -9
  137. data/test/test_datainputstream.rb +0 -7
  138. data/test/test_fileenumerator.rb +0 -8
  139. data/test/test_filemonitor.rb +0 -17
  140. data/test/test_inetaddress.rb +0 -8
@@ -1,81 +0,0 @@
1
- /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2008-2009 Ruby-GNOME2 Project Team
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
- * MA 02110-1301 USA
20
- */
21
-
22
- #include "rbgio2private.h"
23
-
24
- #define RG_TARGET_NAMESPACE cAppLaunchContext
25
- #define _SELF(value) RVAL2GAPPLAUNCHCONTEXT(value)
26
-
27
- static VALUE
28
- rg_initialize(VALUE self)
29
- {
30
- G_INITIALIZE(self, g_app_launch_context_new());
31
-
32
- return Qnil;
33
- }
34
-
35
- typedef char *(*GetMethod)(GAppLaunchContext *, GAppInfo *, GList *);
36
-
37
- static VALUE
38
- get_value_by(GetMethod method, int argc, VALUE *argv, VALUE self)
39
- {
40
- VALUE info, rbfiles;
41
- GList *files;
42
- char *value;
43
-
44
- rb_scan_args(argc, argv, "11", &info, &rbfiles);
45
- files = GFILEARY2GLIST_ACCEPT_NIL(rbfiles);
46
- value = method(_SELF(self), RVAL2GAPPINFO(info), files);
47
- g_list_free(files);
48
-
49
- return CSTR2RVAL_FREE(value);
50
- }
51
-
52
- static VALUE
53
- rg_get_display(int argc, VALUE *argv, VALUE self)
54
- {
55
- return get_value_by(g_app_launch_context_get_display, argc, argv, self);
56
- }
57
-
58
- static VALUE
59
- rg_get_startup_notify_id(int argc, VALUE *argv, VALUE self)
60
- {
61
- return get_value_by(g_app_launch_context_get_startup_notify_id, argc, argv, self);
62
- }
63
-
64
- static VALUE
65
- rg_launch_failed(VALUE self, VALUE sn_id)
66
- {
67
- g_app_launch_context_launch_failed(_SELF(self), RVAL2CSTR(sn_id));
68
-
69
- return self;
70
- }
71
-
72
- void
73
- Init_gapplaunchcontext(VALUE mGio)
74
- {
75
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_APP_LAUNCH_CONTEXT, "AppLaunchContext", mGio);
76
-
77
- RG_DEF_METHOD(initialize, 0);
78
- RG_DEF_METHOD(get_display, -1);
79
- RG_DEF_METHOD(get_startup_notify_id, -1);
80
- RG_DEF_METHOD(launch_failed, 1);
81
- }
@@ -1,246 +0,0 @@
1
- /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2008-2009 Ruby-GNOME2 Project Team
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
- * MA 02110-1301 USA
20
- */
21
-
22
- #include "rbgio2private.h"
23
-
24
- #define RG_TARGET_NAMESPACE mAsyncInitable
25
- #define _SELF(value) RVAL2GASYNCINITABLE(value)
26
-
27
- static VALUE
28
- rg_init_async(int argc, VALUE *argv, VALUE self)
29
- {
30
- VALUE rbio_priority, rbcancellable, block;
31
- int io_priority;
32
- GCancellable *cancellable;
33
-
34
- rb_scan_args(argc, argv, "02&", &rbio_priority, &rbcancellable, &block);
35
- io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
36
- cancellable = RVAL2GCANCELLABLE(rbcancellable);
37
- SAVE_BLOCK(block);
38
- g_async_initable_init_async(_SELF(self),
39
- io_priority,
40
- cancellable,
41
- rbgio_async_ready_callback,
42
- (gpointer)block);
43
-
44
- return self;
45
- }
46
-
47
- static VALUE
48
- rg_init_finish(VALUE self, VALUE result)
49
- {
50
- GError *error = NULL;
51
-
52
- if (!g_async_initable_init_finish(_SELF(self),
53
- RVAL2GASYNCRESULT(result),
54
- &error))
55
- rbgio_raise_error(error);
56
-
57
- return self;
58
- }
59
-
60
- /* NOTE: We don't implement g_async_initable_new_async. */
61
-
62
- /* NOTE: We don't implement g_async_initable_new_valist_async. */
63
-
64
- struct rbgio_gasyncinitable_new_async_data {
65
- GObjectClass *gclass;
66
- int io_priority;
67
- GCancellable *cancellable;
68
- VALUE block;
69
- VALUE rbparameters;
70
- guint index;
71
- guint n_parameters;
72
- GParameter *parameters;
73
- };
74
-
75
- static VALUE
76
- rbgio_gasyncinitiable_new_async_parameters_initialize(VALUE key_value,
77
- struct rbgio_gasyncinitable_new_async_data *data)
78
- {
79
- VALUE key, value;
80
- GParamSpec *spec;
81
-
82
- if (data->index >= data->n_parameters)
83
- rb_raise(rb_eArgError,
84
- "too many parameters (%d >= %d)",
85
- data->index, data->n_parameters);
86
-
87
- key = rb_ary_entry(key_value, 0);
88
- value = rb_ary_entry(key_value, 1);
89
-
90
- data->parameters[data->index].name = SYMBOL_P(key) ?
91
- rb_id2name(SYM2ID(key)) :
92
- StringValuePtr(key);
93
- spec = g_object_class_find_property(data->gclass,
94
- data->parameters[data->index].name);
95
- if (spec == NULL)
96
- rb_raise(rb_eArgError,
97
- "%s: no such property",
98
- data->parameters[data->index].name);
99
- g_value_init(&(data->parameters[data->index].value),
100
- G_PARAM_SPEC_VALUE_TYPE(spec));
101
- rbgobj_rvalue_to_gvalue(value, &(data->parameters[data->index].value));
102
-
103
- data->index++;
104
-
105
- return Qnil;
106
- }
107
-
108
- static VALUE
109
- rbgio_gasyncinitable_new_async_body(struct rbgio_gasyncinitable_new_async_data *data)
110
- {
111
- rb_iterate(rb_each,
112
- data->rbparameters,
113
- rbgio_gasyncinitiable_new_async_parameters_initialize,
114
- (VALUE)data);
115
-
116
- SAVE_BLOCK(data->block);
117
-
118
- g_async_initable_newv_async(G_TYPE_FROM_CLASS(data->gclass),
119
- data->n_parameters,
120
- data->parameters,
121
- data->io_priority,
122
- data->cancellable,
123
- rbgio_async_ready_callback,
124
- (gpointer)data->block);
125
-
126
- return Qnil;
127
- }
128
-
129
- static VALUE
130
- rbgio_gasyncinitable_new_async_ensure(struct rbgio_gasyncinitable_new_async_data *data)
131
- {
132
- guint i;
133
-
134
- g_type_class_unref(data->gclass);
135
- for (i = 0; i < data->n_parameters; i++)
136
- if (G_IS_VALUE(&data->parameters[i].value))
137
- g_value_unset(&data->parameters[i].value);
138
-
139
- g_free(data->parameters);
140
-
141
- return Qnil;
142
- }
143
-
144
- void
145
- rbgio_gasyncinitable_new_async(GType type,
146
- VALUE parameters,
147
- VALUE io_priority,
148
- VALUE cancellable,
149
- VALUE block)
150
- {
151
- static ID s_id_length;
152
- struct rbgio_gasyncinitable_new_async_data data;
153
-
154
- if (s_id_length == 0)
155
- s_id_length = rb_intern("length");
156
-
157
- if (!g_type_is_a(type, G_TYPE_OBJECT))
158
- rb_raise(rb_eArgError,
159
- "%s is not a descendant of GObject",
160
- g_type_name(type));
161
-
162
- if (NIL_P(parameters)) {
163
- SAVE_BLOCK(block);
164
- g_async_initable_newv_async(type,
165
- 0,
166
- NULL,
167
- RVAL2IOPRIORITYDEFAULT(io_priority),
168
- RVAL2GCANCELLABLE(cancellable),
169
- rbgio_async_ready_callback,
170
- (gpointer)block);
171
-
172
- return;
173
- } else {
174
- parameters = rb_convert_type(parameters,
175
- T_HASH,
176
- "Hash",
177
- "to_hash");
178
- }
179
-
180
- data.gclass = G_OBJECT_CLASS(g_type_class_ref(type));
181
- data.io_priority = RVAL2IOPRIORITYDEFAULT(io_priority);
182
- data.cancellable = RVAL2GCANCELLABLE(cancellable);
183
- data.block = block;
184
- data.rbparameters = parameters;
185
- data.index = 0;
186
- data.n_parameters = RVAL2GUINT(rb_funcall(parameters, s_id_length, 0));
187
- data.parameters = g_new(GParameter, data.n_parameters);
188
-
189
- rb_ensure(rbgio_gasyncinitable_new_async_body, (VALUE)&data,
190
- rbgio_gasyncinitable_new_async_ensure, (VALUE)&data);
191
-
192
- return;
193
- }
194
-
195
- static VALUE
196
- rg_initialize(int argc, VALUE *argv, VALUE self)
197
- {
198
- const RGObjClassInfo* info;
199
- VALUE io_priority, cancellable, parameters, block;
200
-
201
- rb_scan_args(argc, argv, "03&", &io_priority, &cancellable, &parameters, &block);
202
-
203
- info = CLASS2CINFO(self);
204
- if (info->klass != self)
205
- rb_raise(rb_eTypeError,
206
- "%s: class not registered with GLib",
207
- rb_class2name(self));
208
-
209
- rbgio_gasyncinitable_new_async(info->gtype,
210
- parameters,
211
- io_priority,
212
- cancellable,
213
- block);
214
-
215
- return self;
216
- }
217
-
218
- static VALUE
219
- rg_initialize_finish(VALUE self, VALUE result)
220
- {
221
- GError *error = NULL;
222
- GObject *object;
223
- VALUE rbobject;
224
-
225
- object = g_async_initable_new_finish(_SELF(self),
226
- RVAL2GASYNCRESULT(result),
227
- &error);
228
- if (object == NULL)
229
- rbgio_raise_error(error);
230
-
231
- rbobject = GOBJ2RVAL(object);
232
- g_object_unref(object);
233
-
234
- return rbobject;
235
- }
236
-
237
- void
238
- Init_gasyncinitable(VALUE mGio)
239
- {
240
- VALUE RG_TARGET_NAMESPACE = G_DEF_INTERFACE(G_TYPE_ASYNC_INITABLE, "AsyncInitable", mGio);
241
-
242
- RG_DEF_METHOD(init_async, -1);
243
- RG_DEF_METHOD(init_finish, 1);
244
- RG_DEF_METHOD(initialize, -1);
245
- RG_DEF_METHOD(initialize_finish, 1);
246
- }
@@ -1,41 +0,0 @@
1
- /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2008-2009 Ruby-GNOME2 Project Team
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
- * MA 02110-1301 USA
20
- */
21
-
22
- #include "rbgio2private.h"
23
-
24
- #define RG_TARGET_NAMESPACE mAsyncResult
25
- #define _SELF(value) RVAL2GASYNCRESULT(value)
26
-
27
- /* NOTE: g_async_result_get_user_data isn't of any use from Ruby. */
28
-
29
- static VALUE
30
- rg_source_object(VALUE self)
31
- {
32
- return GOBJ2RVAL_UNREF(g_async_result_get_source_object(_SELF(self)));
33
- }
34
-
35
- void
36
- Init_gasyncresult(VALUE mGio)
37
- {
38
- VALUE RG_TARGET_NAMESPACE = G_DEF_INTERFACE(G_TYPE_ASYNC_RESULT, "AsyncResult", mGio);
39
-
40
- RG_DEF_METHOD(source_object, 0);
41
- }
@@ -1,167 +0,0 @@
1
- /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
- * Copyright (C) 2008-2009 Ruby-GNOME2 Project Team
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
- * MA 02110-1301 USA
20
- */
21
-
22
- #include "rbgio2private.h"
23
-
24
- #define RG_TARGET_NAMESPACE cBufferedInputStream
25
- #define _SELF(value) RVAL2GBUFFEREDINPUTSTREAM(value)
26
-
27
- static VALUE
28
- rg_initialize(int argc, VALUE *argv, VALUE self)
29
- {
30
- VALUE rbbase_stream, size;
31
- GInputStream *base_stream, *stream;
32
-
33
- rb_scan_args(argc, argv, "11", &rbbase_stream, &size);
34
- base_stream = RVAL2GINPUTSTREAM(rbbase_stream);
35
-
36
- stream = NIL_P(size) ?
37
- g_buffered_input_stream_new(base_stream) :
38
- g_buffered_input_stream_new_sized(base_stream, RVAL2GSIZE(size));
39
- G_INITIALIZE(self, stream);
40
-
41
- return Qnil;
42
- }
43
-
44
- static VALUE
45
- rg_available(VALUE self)
46
- {
47
- return GSIZE2RVAL(g_buffered_input_stream_get_available(_SELF(self)));
48
- }
49
-
50
- static VALUE
51
- rg_peek_buffer(VALUE self)
52
- {
53
- gsize size;
54
- const void *buffer;
55
-
56
- buffer = g_buffered_input_stream_peek_buffer(_SELF(self), &size);
57
-
58
- return CSTR2RVAL_TAINTED(buffer, size);
59
- }
60
-
61
- static VALUE
62
- rg_peek(VALUE self, VALUE rboffset, VALUE rbcount)
63
- {
64
- gsize offset = RVAL2GSIZE(rboffset);
65
- gsize count = RVAL2GSIZE(rbcount);
66
- VALUE result = rb_str_new(NULL, count);
67
- gsize bytes_peeked = g_buffered_input_stream_peek(_SELF(self),
68
- RSTRING_PTR(result),
69
- offset,
70
- count);
71
-
72
- rb_str_set_len(result, bytes_peeked);
73
- rb_str_resize(result, bytes_peeked);
74
- OBJ_TAINT(result);
75
-
76
- return result;
77
- }
78
-
79
- static VALUE
80
- rg_fill(int argc, VALUE *argv, VALUE self)
81
- {
82
- VALUE count, cancellable;
83
- GError *error = NULL;
84
- gsize bytes_read;
85
-
86
- rb_scan_args(argc, argv, "02", &count, &cancellable);
87
- bytes_read = g_buffered_input_stream_fill(_SELF(self),
88
- NIL_P(count) ?
89
- -1 :
90
- RVAL2GSSIZE(count),
91
- RVAL2GCANCELLABLE(cancellable),
92
- &error);
93
- if (error != NULL)
94
- rbgio_raise_error(error);
95
-
96
- return GSSIZE2RVAL(bytes_read);
97
- }
98
-
99
- static VALUE
100
- rg_fill_async(int argc, VALUE *argv, VALUE self)
101
- {
102
- VALUE rbcount, rbio_priority, rbcancellable, block;
103
- gssize count;
104
- int io_priority;
105
- GCancellable *cancellable;
106
-
107
- rb_scan_args(argc, argv, "03&", &rbcount, &rbio_priority, &rbcancellable, &block);
108
- count = NIL_P(rbcount) ? -1 : RVAL2GSSIZE(rbcount);
109
- io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
110
- cancellable = RVAL2GCANCELLABLE(rbcancellable);
111
- SAVE_BLOCK(block);
112
- g_buffered_input_stream_fill_async(_SELF(self),
113
- count,
114
- io_priority,
115
- cancellable,
116
- rbgio_async_ready_callback,
117
- (gpointer)block);
118
-
119
- return self;
120
- }
121
-
122
- static VALUE
123
- rg_fill_finish(VALUE self, VALUE result)
124
- {
125
- GError *error = NULL;
126
- gsize bytes_read;
127
-
128
- bytes_read = g_buffered_input_stream_fill_finish(_SELF(self),
129
- RVAL2GASYNCRESULT(result),
130
- &error);
131
- if (error != NULL)
132
- rbgio_raise_error(error);
133
-
134
- return GSSIZE2RVAL(bytes_read);
135
- }
136
-
137
- static VALUE
138
- rg_read_byte(int argc, VALUE *argv, VALUE self)
139
- {
140
- VALUE cancellable;
141
- GError *error = NULL;
142
- int byte;
143
-
144
- rb_scan_args(argc, argv, "01", &cancellable);
145
- byte = g_buffered_input_stream_read_byte(_SELF(self),
146
- RVAL2GCANCELLABLE(cancellable),
147
- &error);
148
- if (error != NULL)
149
- rbgio_raise_error(error);
150
-
151
- return INT2FIX(byte);
152
- }
153
-
154
- void
155
- Init_gbufferedinputstream(VALUE mGio)
156
- {
157
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_BUFFERED_INPUT_STREAM, "BufferedInputStream", mGio);
158
-
159
- RG_DEF_METHOD(initialize, -1);
160
- RG_DEF_METHOD(available, 0);
161
- RG_DEF_METHOD(peek_buffer, 0);
162
- RG_DEF_METHOD(peek, 2);
163
- RG_DEF_METHOD(fill, -1);
164
- RG_DEF_METHOD(fill_async, -1);
165
- RG_DEF_METHOD(fill_finish, 1);
166
- RG_DEF_METHOD(read_byte, -1);
167
- }