gio2 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,118 +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 mInetAddress
25
- #define _SELF(value) RVAL2GINETADDRESS(value)
26
-
27
- static VALUE
28
- rg_s_new_from_string(G_GNUC_UNUSED VALUE self, VALUE string)
29
- {
30
- return GOBJ2RVAL_UNREF(g_inet_address_new_from_string(RVAL2CSTR(string)));
31
- }
32
-
33
- /* TODO: Should this take an array instead? */
34
- static VALUE
35
- rg_s_new_from_bytes(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
36
- {
37
- VALUE rbbytes, rbfamily;
38
- guint8 *bytes;
39
- GSocketFamily family;
40
-
41
- rb_scan_args(argc, argv, "11", &rbbytes, &rbfamily);
42
- bytes = (guint8 *)RVAL2CSTR(rbbytes);
43
- family = RVAL2GSOCKETFAMILY(rbfamily);
44
-
45
- /* TODO: Should check encoding. */
46
- /* TODO: We can't pass bytes as such, as it will be NULL-terminated. */
47
- /* TODO: Do we need to deal with G_SOCKET_FAMILY_UNIX? */
48
- switch (family) {
49
- case G_SOCKET_FAMILY_IPV4:
50
- if (RSTRING_LEN(rbbytes) != 4)
51
- rb_raise(rb_eArgError, "string containing 4 bytes expected");
52
- break;
53
- case G_SOCKET_FAMILY_IPV6:
54
- if (RSTRING_LEN(rbbytes) != 16)
55
- rb_raise(rb_eArgError, "string containing 16 bytes expected");
56
- break;
57
- case G_SOCKET_FAMILY_INVALID:
58
- case G_SOCKET_FAMILY_UNIX:
59
- rb_raise(rb_eArgError, "invalid family: %d", family);
60
- default:
61
- rb_raise(rb_eArgError, "unknown family: %d", family);
62
- break;
63
- }
64
-
65
- return GOBJ2RVAL_UNREF(g_inet_address_new_from_bytes(bytes, family));
66
- }
67
-
68
- static VALUE
69
- rg_s_new_any(G_GNUC_UNUSED VALUE self, VALUE family)
70
- {
71
- return GOBJ2RVAL_UNREF(g_inet_address_new_any(RVAL2GSOCKETFAMILY(family)));
72
- }
73
-
74
- static VALUE
75
- rg_s_new_loopback(G_GNUC_UNUSED VALUE self, VALUE family)
76
- {
77
- return GOBJ2RVAL_UNREF(g_inet_address_new_loopback(RVAL2GSOCKETFAMILY(family)));
78
- }
79
-
80
- /* TODO: Return array of bytes instead? */
81
- static VALUE
82
- rg_to_bytes(VALUE self)
83
- {
84
- gsize size;
85
-
86
- size = g_inet_address_get_native_size(_SELF(self));
87
- return rb_str_new((const gchar *)g_inet_address_to_bytes(_SELF(self)),
88
- size);
89
- }
90
-
91
- static VALUE
92
- rg_get_native_size(VALUE self)
93
- {
94
- return GSIZE2RVAL(g_inet_address_get_native_size(_SELF(self)));
95
- }
96
-
97
- static VALUE
98
- rg_to_string(VALUE self)
99
- {
100
- return CSTR2RVAL_FREE(g_inet_address_to_string(_SELF(self)));
101
- }
102
-
103
- void
104
- Init_ginetaddress(VALUE mGio)
105
- {
106
- VALUE RG_TARGET_NAMESPACE = G_DEF_INTERFACE(G_TYPE_INET_ADDRESS, "InetAddress", mGio);
107
-
108
- RG_DEF_SMETHOD(new_from_string, 1);
109
- RG_DEF_SMETHOD(new_from_bytes, -1);
110
- RG_DEF_SMETHOD(new_any, 1);
111
- RG_DEF_SMETHOD(new_loopback, 1);
112
-
113
- RG_DEF_METHOD(to_bytes, 0);
114
- RG_DEF_METHOD(get_native_size, 0);
115
- RG_DEF_METHOD(to_string, 0);
116
- RG_DEF_ALIAS("to_str", "to_string");
117
- RG_DEF_ALIAS("to_s", "to_string");
118
- }
@@ -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 cInetSocketAddress
25
-
26
- static VALUE
27
- rg_initialize(VALUE self, VALUE address, VALUE port)
28
- {
29
- G_INITIALIZE(self, g_inet_socket_address_new(RVAL2GINETADDRESS(address),
30
- RVAL2GUINT16(port)));
31
-
32
- return Qnil;
33
- }
34
-
35
- void
36
- Init_ginetsocketaddress(VALUE mGio)
37
- {
38
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_INET_SOCKET_ADDRESS, "InetSocketAddress", mGio);
39
-
40
- RG_DEF_METHOD(initialize, 2);
41
- }
@@ -1,199 +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 mInitable
25
- #define _SELF(value) RVAL2GINITABLE(value)
26
-
27
- static VALUE
28
- rg_init(int argc, VALUE *argv, VALUE self)
29
- {
30
- VALUE cancellable;
31
- GError *error = NULL;
32
-
33
- rb_scan_args(argc, argv, "01", &cancellable);
34
- if (!g_initable_init(_SELF(self),
35
- RVAL2GCANCELLABLE(cancellable),
36
- &error))
37
- rbgio_raise_error(error);
38
-
39
- return self;
40
- }
41
-
42
- struct rbgio_ginitable_new_data {
43
- GObjectClass *gclass;
44
- GCancellable *cancellable;
45
- VALUE rbparameters;
46
- guint index;
47
- guint n_parameters;
48
- GParameter *parameters;
49
- GError *error;
50
- };
51
-
52
- static VALUE
53
- rbgio_ginitiable_new_parameters_initialize(VALUE key_value,
54
- struct rbgio_ginitable_new_data *data)
55
- {
56
- VALUE key, value;
57
- GParamSpec *spec;
58
-
59
- if (data->index >= data->n_parameters)
60
- rb_raise(rb_eArgError,
61
- "too many parameters (%d >= %d)",
62
- data->index, data->n_parameters);
63
-
64
- key = rb_ary_entry(key_value, 0);
65
- value = rb_ary_entry(key_value, 1);
66
-
67
- data->parameters[data->index].name = SYMBOL_P(key) ?
68
- rb_id2name(SYM2ID(key)) :
69
- StringValuePtr(key);
70
- spec = g_object_class_find_property(data->gclass,
71
- data->parameters[data->index].name);
72
- if (spec == NULL)
73
- rb_raise(rb_eArgError,
74
- "%s: no such property",
75
- data->parameters[data->index].name);
76
- g_value_init(&(data->parameters[data->index].value),
77
- G_PARAM_SPEC_VALUE_TYPE(spec));
78
- rbgobj_rvalue_to_gvalue(value, &(data->parameters[data->index].value));
79
-
80
- data->index++;
81
-
82
- return Qnil;
83
- }
84
-
85
- static VALUE
86
- rbgio_ginitable_new_body(struct rbgio_ginitable_new_data *data)
87
- {
88
- rb_iterate(rb_each,
89
- data->rbparameters,
90
- rbgio_ginitiable_new_parameters_initialize,
91
- (VALUE)data);
92
-
93
- return (VALUE)g_initable_newv(G_TYPE_FROM_CLASS(data->gclass),
94
- data->n_parameters,
95
- data->parameters,
96
- data->cancellable,
97
- &data->error);
98
- }
99
-
100
- static VALUE
101
- rbgio_ginitable_new_ensure(struct rbgio_ginitable_new_data *data)
102
- {
103
- guint i;
104
-
105
- g_type_class_unref(data->gclass);
106
- for (i = 0; i < data->n_parameters; i++)
107
- if (G_IS_VALUE(&data->parameters[i].value))
108
- g_value_unset(&data->parameters[i].value);
109
-
110
- g_free(data->parameters);
111
-
112
- return Qnil;
113
- }
114
-
115
- GObject *
116
- rbgio_ginitable_new(GType type, VALUE parameters, VALUE cancellable)
117
- {
118
- static ID s_id_length;
119
- GError *error = NULL;
120
- GObject *object;
121
- struct rbgio_ginitable_new_data data;
122
-
123
- if (s_id_length == 0)
124
- s_id_length = rb_intern("length");
125
-
126
- if (!g_type_is_a(type, G_TYPE_OBJECT))
127
- rb_raise(rb_eArgError,
128
- "%s is not a descendant of GObject",
129
- g_type_name(type));
130
-
131
- if (NIL_P(parameters)) {
132
- object = g_initable_newv(type,
133
- 0,
134
- NULL,
135
- RVAL2GCANCELLABLE(cancellable),
136
- &error);
137
- if (object == NULL)
138
- rbgio_raise_error(error);
139
-
140
- return object;
141
- } else {
142
- parameters = rb_convert_type(parameters,
143
- T_HASH,
144
- "Hash",
145
- "to_hash");
146
- }
147
-
148
- data.gclass = G_OBJECT_CLASS(g_type_class_ref(type));
149
- data.cancellable = RVAL2GCANCELLABLE(cancellable);
150
- data.rbparameters = parameters;
151
- data.index = 0;
152
- data.n_parameters = RVAL2GUINT(rb_funcall(parameters, s_id_length, 0));
153
- data.parameters = g_new(GParameter, data.n_parameters);
154
- data.error = NULL;
155
-
156
- object = (GObject *)rb_ensure(rbgio_ginitable_new_body, (VALUE)&data,
157
- rbgio_ginitable_new_ensure, (VALUE)&data);
158
- if (object == NULL)
159
- rbgio_raise_error(data.error);
160
-
161
- return object;
162
- }
163
-
164
- /* NOTE: We don't implement g_initable_new. */
165
-
166
- /* NOTE: We don't implement g_initable_new_valist. */
167
-
168
- static VALUE
169
- rg_s_new(int argc, VALUE *argv, VALUE self)
170
- {
171
- const RGObjClassInfo* info;
172
- VALUE cancellable, parameters;
173
- GObject *object;
174
- VALUE result;
175
-
176
- rb_scan_args(argc, argv, "02", &cancellable, &parameters);
177
-
178
- info = CLASS2CINFO(self);
179
- if (info->klass != self)
180
- rb_raise(rb_eTypeError,
181
- "%s: class not registered with GLib",
182
- rb_class2name(self));
183
-
184
- object = rbgio_ginitable_new(info->gtype, parameters, cancellable);
185
- result = GOBJ2RVAL(object);
186
- g_object_unref(object);
187
-
188
- return result;
189
- }
190
-
191
- void
192
- Init_ginitable(VALUE mGio)
193
- {
194
- VALUE RG_TARGET_NAMESPACE = G_DEF_INTERFACE(G_TYPE_INITABLE, "Initable", mGio);
195
-
196
- RG_DEF_SMETHOD(new, -1);
197
-
198
- RG_DEF_METHOD(init, -1);
199
- }
@@ -1,341 +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 cInputStream
25
- #define _SELF(value) RVAL2GINPUTSTREAM(value)
26
-
27
- static VALUE s_cReadAsyncResult;
28
-
29
- static VALUE
30
- rg_read(int argc, VALUE *argv, VALUE self)
31
- {
32
- VALUE rbcount, cancellable, result;
33
- gsize count;
34
- GError *error = NULL;
35
- gssize bytes_read;
36
-
37
- rb_scan_args(argc, argv, "11", &rbcount, &cancellable);
38
- count = RVAL2GSIZE(rbcount);
39
- result = rb_str_new(NULL, count);
40
- bytes_read = g_input_stream_read(_SELF(self),
41
- RSTRING_PTR(result),
42
- count,
43
- RVAL2GCANCELLABLE(cancellable),
44
- &error);
45
- if (bytes_read == -1)
46
- rbgio_raise_error(error);
47
-
48
- rb_str_set_len(result, bytes_read);
49
- rb_str_resize(result, bytes_read);
50
- OBJ_TAINT(result);
51
-
52
- return result;
53
- }
54
-
55
- static VALUE
56
- rg_read_all(int argc, VALUE *argv, VALUE self)
57
- {
58
- VALUE rbcount, cancellable, result;
59
- gsize count;
60
- GError *error = NULL;
61
- gsize bytes_read;
62
-
63
- rb_scan_args(argc, argv, "11", &rbcount, &cancellable);
64
- count = RVAL2GSIZE(rbcount);
65
- result = rb_str_new(NULL, count);
66
- if (!g_input_stream_read_all(_SELF(self),
67
- RSTRING_PTR(result),
68
- count,
69
- &bytes_read,
70
- RVAL2GCANCELLABLE(cancellable),
71
- &error))
72
- rbgio_raise_error(error);
73
-
74
- rb_str_set_len(result, bytes_read);
75
- rb_str_resize(result, bytes_read);
76
- OBJ_TAINT(result);
77
-
78
- return result;
79
- }
80
-
81
- static VALUE
82
- rg_skip(int argc, VALUE *argv, VALUE self)
83
- {
84
- VALUE count, cancellable;
85
- GError *error = NULL;
86
- gssize bytes_skipped;
87
-
88
- rb_scan_args(argc, argv, "11", &count, &cancellable);
89
- bytes_skipped = g_input_stream_skip(_SELF(self),
90
- RVAL2GSIZE(count),
91
- RVAL2GCANCELLABLE(cancellable),
92
- &error);
93
- if (bytes_skipped == -1)
94
- rbgio_raise_error(error);
95
-
96
- return GSSIZE2RVAL(bytes_skipped);
97
- }
98
-
99
- static VALUE
100
- rg_close(int argc, VALUE *argv, VALUE self)
101
- {
102
- VALUE cancellable;
103
- GError *error = NULL;
104
-
105
- rb_scan_args(argc, argv, "01", &cancellable);
106
- if (!g_input_stream_close(_SELF(self),
107
- RVAL2GCANCELLABLE(cancellable),
108
- &error))
109
- rbgio_raise_error(error);
110
-
111
- return self;
112
- }
113
-
114
- struct read_async_result
115
- {
116
- VALUE string;
117
- GAsyncResult *result;
118
- };
119
-
120
- static void
121
- read_async_result_mark(struct read_async_result *result)
122
- {
123
- rb_gc_mark(result->string);
124
- }
125
-
126
- struct read_async_callback_data
127
- {
128
- GAsyncResult *result;
129
- gpointer user_data;
130
- };
131
-
132
- static VALUE
133
- read_async_callback_call(VALUE data)
134
- {
135
- static ID s_id_call;
136
- struct read_async_callback_data *real;
137
- VALUE ary;
138
- struct read_async_result *result;
139
-
140
- if (s_id_call == 0)
141
- s_id_call = rb_intern("call");
142
-
143
- real = (struct read_async_callback_data *)data;
144
-
145
- ary = (VALUE)real->user_data;
146
- G_CHILD_REMOVE(mGLib, ary);
147
- if (NIL_P(RARRAY_PTR(ary)[1]))
148
- return Qnil;
149
-
150
- result = g_new(struct read_async_result, 1);
151
- result->string = RARRAY_PTR(ary)[0];
152
- result->result = real->result;
153
-
154
- rb_funcall(RARRAY_PTR(ary)[1], s_id_call, 1,
155
- Data_Wrap_Struct(s_cReadAsyncResult,
156
- read_async_result_mark,
157
- g_free,
158
- result));
159
-
160
- return Qnil;
161
- }
162
-
163
- static void
164
- read_async_callback(G_GNUC_UNUSED GObject *source,
165
- GAsyncResult *result,
166
- gpointer user_data)
167
- {
168
- struct read_async_callback_data real = { result, user_data };
169
-
170
- G_PROTECT_CALLBACK(read_async_callback_call, &real);
171
- }
172
-
173
- static VALUE
174
- rg_read_async(int argc, VALUE *argv, VALUE self)
175
- {
176
- VALUE rbcount, rbio_priority, rbcancellable, block, data;
177
- gsize count;
178
- int io_priority;
179
- GCancellable *cancellable;
180
-
181
- rb_scan_args(argc, argv, "12&", &rbcount, &rbio_priority, &rbcancellable, &block);
182
- count = RVAL2GSIZE(rbcount);
183
- io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
184
- cancellable = RVAL2GCANCELLABLE(rbcancellable);
185
- data = rb_assoc_new(rb_str_new(NULL, count), block);
186
- G_CHILD_ADD(mGLib, data);
187
- g_input_stream_read_async(_SELF(self),
188
- RSTRING_PTR(RARRAY_PTR(data)[0]),
189
- count,
190
- io_priority,
191
- cancellable,
192
- read_async_callback,
193
- (gpointer)data);
194
-
195
- return self;
196
- }
197
-
198
- static VALUE
199
- rg_read_finish(VALUE self, VALUE rbresult)
200
- {
201
- struct read_async_result *result;
202
- GError *error = NULL;
203
- gssize bytes_read;
204
-
205
- Data_Get_Struct(rbresult, struct read_async_result, result);
206
- bytes_read = g_input_stream_read_finish(_SELF(self),
207
- result->result,
208
- &error);
209
- if (bytes_read == -1)
210
- rbgio_raise_error(error);
211
-
212
- rb_str_set_len(result->string, bytes_read);
213
- rb_str_resize(result->string, bytes_read);
214
- OBJ_TAINT(result->string);
215
-
216
- return result->string;
217
- }
218
-
219
- static VALUE
220
- rg_skip_async(int argc, VALUE *argv, VALUE self)
221
- {
222
- VALUE rbcount, rbio_priority, rbcancellable, block;
223
- gsize count;
224
- int io_priority;
225
- GCancellable *cancellable;
226
-
227
- rb_scan_args(argc, argv, "12&", &rbcount, &rbio_priority, &rbcancellable, &block);
228
- count = RVAL2GSIZE(rbcount);
229
- io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
230
- cancellable = RVAL2GCANCELLABLE(rbcancellable);
231
- SAVE_BLOCK(block);
232
- g_input_stream_skip_async(_SELF(self),
233
- count,
234
- io_priority,
235
- cancellable,
236
- rbgio_async_ready_callback,
237
- (gpointer)block);
238
-
239
- return self;
240
- }
241
-
242
- static VALUE
243
- rg_skip_finish(VALUE self, VALUE result)
244
- {
245
- GError *error = NULL;
246
- gssize skipped_bytes;
247
-
248
- skipped_bytes = g_input_stream_skip_finish(_SELF(self),
249
- RVAL2GASYNCRESULT(result),
250
- &error);
251
- if (skipped_bytes == -1)
252
- rbgio_raise_error(error);
253
-
254
- return GSSIZE2RVAL(skipped_bytes);
255
- }
256
-
257
- static VALUE
258
- rg_close_async(int argc, VALUE *argv, VALUE self)
259
- {
260
- VALUE rbio_priority, rbcancellable, block;
261
- int io_priority;
262
- GCancellable *cancellable;
263
-
264
- rb_scan_args(argc, argv, "02&", &rbio_priority, &rbcancellable, &block);
265
- io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
266
- cancellable = RVAL2GCANCELLABLE(rbcancellable);
267
- SAVE_BLOCK(block);
268
- g_input_stream_close_async(_SELF(self),
269
- io_priority,
270
- cancellable,
271
- rbgio_async_ready_callback,
272
- (gpointer)block);
273
-
274
- return self;
275
- }
276
-
277
- static VALUE
278
- rg_close_finish(VALUE self, VALUE result)
279
- {
280
- GError *error = NULL;
281
- if (!g_input_stream_skip_finish(_SELF(self),
282
- RVAL2GASYNCRESULT(result),
283
- &error))
284
- rbgio_raise_error(error);
285
-
286
- return self;
287
- }
288
-
289
- static VALUE
290
- rg_closed_p(VALUE self)
291
- {
292
- return CBOOL2RVAL(g_input_stream_is_closed(_SELF(self)));
293
- }
294
-
295
- static VALUE
296
- rg_has_pending_p(VALUE self)
297
- {
298
- return CBOOL2RVAL(g_input_stream_has_pending(_SELF(self)));
299
- }
300
-
301
- static VALUE
302
- rg_set_pending(VALUE self)
303
- {
304
- GError *error = NULL;
305
-
306
- if (!g_input_stream_set_pending(_SELF(self), &error))
307
- rbgio_raise_error(error);
308
-
309
- return self;
310
- }
311
-
312
- static VALUE
313
- rg_clear_pending(VALUE self)
314
- {
315
- g_input_stream_clear_pending(_SELF(self));
316
-
317
- return self;
318
- }
319
-
320
- void
321
- Init_ginputstream(VALUE mGio)
322
- {
323
- VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_INPUT_STREAM, "InputStream", mGio);
324
-
325
- s_cReadAsyncResult = rb_define_class_under(RG_TARGET_NAMESPACE, "ReadAsyncResult", rb_cObject);
326
-
327
- RG_DEF_METHOD(read, -1);
328
- RG_DEF_METHOD(read_all, -1);
329
- RG_DEF_METHOD(skip, -1);
330
- RG_DEF_METHOD(close, -1);
331
- RG_DEF_METHOD(read_async, -1);
332
- RG_DEF_METHOD(read_finish, 1);
333
- RG_DEF_METHOD(skip_async, -1);
334
- RG_DEF_METHOD(skip_finish, 1);
335
- RG_DEF_METHOD(close_async, -1);
336
- RG_DEF_METHOD(close_finish, 1);
337
- RG_DEF_METHOD_P(closed, 0);
338
- RG_DEF_METHOD_P(has_pending, 0);
339
- RG_DEF_METHOD(set_pending, 0);
340
- RG_DEF_METHOD(clear_pending, 0);
341
- }