grpc 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +52 -0
- data/Gemfile +4 -0
- data/README.md +82 -0
- data/Rakefile +54 -0
- data/bin/apis/google/protobuf/empty.rb +44 -0
- data/bin/apis/pubsub_demo.rb +267 -0
- data/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
- data/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
- data/bin/interop/README.md +8 -0
- data/bin/interop/interop_client.rb +334 -0
- data/bin/interop/interop_server.rb +192 -0
- data/bin/interop/test/cpp/interop/empty.rb +44 -0
- data/bin/interop/test/cpp/interop/messages.rb +89 -0
- data/bin/interop/test/cpp/interop/test.rb +43 -0
- data/bin/interop/test/cpp/interop/test_services.rb +60 -0
- data/bin/math.proto +80 -0
- data/bin/math.rb +61 -0
- data/bin/math_client.rb +147 -0
- data/bin/math_server.rb +190 -0
- data/bin/math_services.rb +56 -0
- data/bin/noproto_client.rb +108 -0
- data/bin/noproto_server.rb +112 -0
- data/ext/grpc/extconf.rb +76 -0
- data/ext/grpc/rb_byte_buffer.c +241 -0
- data/ext/grpc/rb_byte_buffer.h +54 -0
- data/ext/grpc/rb_call.c +569 -0
- data/ext/grpc/rb_call.h +59 -0
- data/ext/grpc/rb_channel.c +264 -0
- data/ext/grpc/rb_channel.h +49 -0
- data/ext/grpc/rb_channel_args.c +154 -0
- data/ext/grpc/rb_channel_args.h +52 -0
- data/ext/grpc/rb_completion_queue.c +185 -0
- data/ext/grpc/rb_completion_queue.h +50 -0
- data/ext/grpc/rb_credentials.c +281 -0
- data/ext/grpc/rb_credentials.h +50 -0
- data/ext/grpc/rb_event.c +361 -0
- data/ext/grpc/rb_event.h +53 -0
- data/ext/grpc/rb_grpc.c +274 -0
- data/ext/grpc/rb_grpc.h +74 -0
- data/ext/grpc/rb_metadata.c +215 -0
- data/ext/grpc/rb_metadata.h +53 -0
- data/ext/grpc/rb_server.c +278 -0
- data/ext/grpc/rb_server.h +50 -0
- data/ext/grpc/rb_server_credentials.c +210 -0
- data/ext/grpc/rb_server_credentials.h +50 -0
- data/grpc.gemspec +41 -0
- data/lib/grpc.rb +39 -0
- data/lib/grpc/core/event.rb +44 -0
- data/lib/grpc/core/time_consts.rb +71 -0
- data/lib/grpc/errors.rb +61 -0
- data/lib/grpc/generic/active_call.rb +536 -0
- data/lib/grpc/generic/bidi_call.rb +221 -0
- data/lib/grpc/generic/client_stub.rb +413 -0
- data/lib/grpc/generic/rpc_desc.rb +150 -0
- data/lib/grpc/generic/rpc_server.rb +404 -0
- data/lib/grpc/generic/service.rb +235 -0
- data/lib/grpc/logconfig.rb +40 -0
- data/lib/grpc/version.rb +33 -0
- data/spec/alloc_spec.rb +44 -0
- data/spec/byte_buffer_spec.rb +67 -0
- data/spec/call_spec.rb +163 -0
- data/spec/channel_spec.rb +181 -0
- data/spec/client_server_spec.rb +372 -0
- data/spec/completion_queue_spec.rb +74 -0
- data/spec/credentials_spec.rb +71 -0
- data/spec/event_spec.rb +53 -0
- data/spec/generic/active_call_spec.rb +373 -0
- data/spec/generic/client_stub_spec.rb +519 -0
- data/spec/generic/rpc_desc_spec.rb +357 -0
- data/spec/generic/rpc_server_pool_spec.rb +139 -0
- data/spec/generic/rpc_server_spec.rb +404 -0
- data/spec/generic/service_spec.rb +342 -0
- data/spec/metadata_spec.rb +64 -0
- data/spec/server_credentials_spec.rb +69 -0
- data/spec/server_spec.rb +212 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/testdata/README +1 -0
- data/spec/testdata/ca.pem +15 -0
- data/spec/testdata/server1.key +16 -0
- data/spec/testdata/server1.pem +16 -0
- data/spec/time_consts_spec.rb +89 -0
- metadata +353 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_RB_CREDENTIALS_H_
|
35
|
+
#define GRPC_RB_CREDENTIALS_H_
|
36
|
+
|
37
|
+
#include <ruby.h>
|
38
|
+
#include <grpc/grpc_security.h>
|
39
|
+
|
40
|
+
/* rb_cCredentials is the ruby class whose instances proxy
|
41
|
+
grpc_credentials. */
|
42
|
+
extern VALUE rb_cCredentials;
|
43
|
+
|
44
|
+
/* Initializes the ruby Credentials class. */
|
45
|
+
void Init_grpc_credentials();
|
46
|
+
|
47
|
+
/* Gets the wrapped credentials from the ruby wrapper */
|
48
|
+
grpc_credentials* grpc_rb_get_wrapped_credentials(VALUE v);
|
49
|
+
|
50
|
+
#endif /* GRPC_RB_CREDENTIALS_H_ */
|
data/ext/grpc/rb_event.c
ADDED
@@ -0,0 +1,361 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include "rb_event.h"
|
35
|
+
|
36
|
+
#include <ruby.h>
|
37
|
+
|
38
|
+
#include <grpc/grpc.h>
|
39
|
+
#include "rb_grpc.h"
|
40
|
+
#include "rb_byte_buffer.h"
|
41
|
+
#include "rb_call.h"
|
42
|
+
#include "rb_metadata.h"
|
43
|
+
|
44
|
+
/* grpc_rb_event wraps a grpc_event. It provides a peer ruby object,
|
45
|
+
* 'mark' to minimize copying when an event is created from ruby. */
|
46
|
+
typedef struct grpc_rb_event {
|
47
|
+
/* Holder of ruby objects involved in constructing the channel */
|
48
|
+
VALUE mark;
|
49
|
+
/* The actual event */
|
50
|
+
grpc_event *wrapped;
|
51
|
+
} grpc_rb_event;
|
52
|
+
|
53
|
+
/* rb_mCompletionType is a ruby module that holds the completion type values */
|
54
|
+
VALUE rb_mCompletionType = Qnil;
|
55
|
+
|
56
|
+
/* Destroys Event instances. */
|
57
|
+
static void grpc_rb_event_free(void *p) {
|
58
|
+
grpc_rb_event *ev = NULL;
|
59
|
+
if (p == NULL) {
|
60
|
+
return;
|
61
|
+
};
|
62
|
+
ev = (grpc_rb_event *)p;
|
63
|
+
|
64
|
+
/* Deletes the wrapped object if the mark object is Qnil, which indicates
|
65
|
+
* that no other object is the actual owner. */
|
66
|
+
if (ev->wrapped != NULL && ev->mark == Qnil) {
|
67
|
+
grpc_event_finish(ev->wrapped);
|
68
|
+
rb_warning("event gc: destroyed the c event");
|
69
|
+
} else {
|
70
|
+
rb_warning("event gc: did not destroy the c event");
|
71
|
+
}
|
72
|
+
|
73
|
+
xfree(p);
|
74
|
+
}
|
75
|
+
|
76
|
+
/* Protects the mark object from GC */
|
77
|
+
static void grpc_rb_event_mark(void *p) {
|
78
|
+
grpc_rb_event *event = NULL;
|
79
|
+
if (p == NULL) {
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
event = (grpc_rb_event *)p;
|
83
|
+
if (event->mark != Qnil) {
|
84
|
+
rb_gc_mark(event->mark);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE grpc_rb_event_result(VALUE self);
|
89
|
+
|
90
|
+
/* Obtains the type of an event. */
|
91
|
+
static VALUE grpc_rb_event_type(VALUE self) {
|
92
|
+
grpc_event *event = NULL;
|
93
|
+
grpc_rb_event *wrapper = NULL;
|
94
|
+
Data_Get_Struct(self, grpc_rb_event, wrapper);
|
95
|
+
if (wrapper->wrapped == NULL) {
|
96
|
+
rb_raise(rb_eRuntimeError, "finished!");
|
97
|
+
return Qnil;
|
98
|
+
}
|
99
|
+
|
100
|
+
event = wrapper->wrapped;
|
101
|
+
switch (event->type) {
|
102
|
+
case GRPC_QUEUE_SHUTDOWN:
|
103
|
+
return rb_const_get(rb_mCompletionType, rb_intern("QUEUE_SHUTDOWN"));
|
104
|
+
|
105
|
+
case GRPC_READ:
|
106
|
+
return rb_const_get(rb_mCompletionType, rb_intern("READ"));
|
107
|
+
|
108
|
+
case GRPC_WRITE_ACCEPTED:
|
109
|
+
grpc_rb_event_result(self); /* validates the result */
|
110
|
+
return rb_const_get(rb_mCompletionType, rb_intern("WRITE_ACCEPTED"));
|
111
|
+
|
112
|
+
case GRPC_FINISH_ACCEPTED:
|
113
|
+
grpc_rb_event_result(self); /* validates the result */
|
114
|
+
return rb_const_get(rb_mCompletionType, rb_intern("FINISH_ACCEPTED"));
|
115
|
+
|
116
|
+
case GRPC_CLIENT_METADATA_READ:
|
117
|
+
return rb_const_get(rb_mCompletionType,
|
118
|
+
rb_intern("CLIENT_METADATA_READ"));
|
119
|
+
|
120
|
+
case GRPC_FINISHED:
|
121
|
+
return rb_const_get(rb_mCompletionType, rb_intern("FINISHED"));
|
122
|
+
|
123
|
+
case GRPC_SERVER_RPC_NEW:
|
124
|
+
return rb_const_get(rb_mCompletionType, rb_intern("SERVER_RPC_NEW"));
|
125
|
+
|
126
|
+
default:
|
127
|
+
rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d",
|
128
|
+
event->type);
|
129
|
+
}
|
130
|
+
return Qnil; /* should not be reached */
|
131
|
+
}
|
132
|
+
|
133
|
+
/* Obtains the tag associated with an event. */
|
134
|
+
static VALUE grpc_rb_event_tag(VALUE self) {
|
135
|
+
grpc_event *event = NULL;
|
136
|
+
grpc_rb_event *wrapper = NULL;
|
137
|
+
Data_Get_Struct(self, grpc_rb_event, wrapper);
|
138
|
+
if (wrapper->wrapped == NULL) {
|
139
|
+
rb_raise(rb_eRuntimeError, "finished!");
|
140
|
+
return Qnil;
|
141
|
+
}
|
142
|
+
|
143
|
+
event = wrapper->wrapped;
|
144
|
+
if (event->tag == NULL) {
|
145
|
+
return Qnil;
|
146
|
+
}
|
147
|
+
return (VALUE)event->tag;
|
148
|
+
}
|
149
|
+
|
150
|
+
/* Obtains the call associated with an event. */
|
151
|
+
static VALUE grpc_rb_event_call(VALUE self) {
|
152
|
+
grpc_event *event = NULL;
|
153
|
+
grpc_rb_event *wrapper = NULL;
|
154
|
+
Data_Get_Struct(self, grpc_rb_event, wrapper);
|
155
|
+
if (wrapper->wrapped == NULL) {
|
156
|
+
rb_raise(rb_eRuntimeError, "finished!");
|
157
|
+
return Qnil;
|
158
|
+
}
|
159
|
+
|
160
|
+
event = wrapper->wrapped;
|
161
|
+
if (event->call != NULL) {
|
162
|
+
return grpc_rb_wrap_call(event->call);
|
163
|
+
}
|
164
|
+
return Qnil;
|
165
|
+
}
|
166
|
+
|
167
|
+
/* Obtains the metadata associated with an event. */
|
168
|
+
static VALUE grpc_rb_event_metadata(VALUE self) {
|
169
|
+
grpc_event *event = NULL;
|
170
|
+
grpc_rb_event *wrapper = NULL;
|
171
|
+
grpc_metadata *metadata = NULL;
|
172
|
+
VALUE key = Qnil;
|
173
|
+
VALUE new_ary = Qnil;
|
174
|
+
VALUE result = Qnil;
|
175
|
+
VALUE value = Qnil;
|
176
|
+
size_t count = 0;
|
177
|
+
size_t i = 0;
|
178
|
+
Data_Get_Struct(self, grpc_rb_event, wrapper);
|
179
|
+
if (wrapper->wrapped == NULL) {
|
180
|
+
rb_raise(rb_eRuntimeError, "finished!");
|
181
|
+
return Qnil;
|
182
|
+
}
|
183
|
+
|
184
|
+
/* Figure out which metadata to read. */
|
185
|
+
event = wrapper->wrapped;
|
186
|
+
switch (event->type) {
|
187
|
+
case GRPC_CLIENT_METADATA_READ:
|
188
|
+
count = event->data.client_metadata_read.count;
|
189
|
+
metadata = event->data.client_metadata_read.elements;
|
190
|
+
break;
|
191
|
+
|
192
|
+
case GRPC_FINISHED:
|
193
|
+
count = event->data.finished.metadata_count;
|
194
|
+
metadata = event->data.finished.metadata_elements;
|
195
|
+
break;
|
196
|
+
|
197
|
+
case GRPC_SERVER_RPC_NEW:
|
198
|
+
count = event->data.server_rpc_new.metadata_count;
|
199
|
+
metadata = event->data.server_rpc_new.metadata_elements;
|
200
|
+
break;
|
201
|
+
|
202
|
+
default:
|
203
|
+
rb_raise(rb_eRuntimeError,
|
204
|
+
"bug: bad event type metadata. got %d; want %d|%d:%d",
|
205
|
+
event->type, GRPC_CLIENT_METADATA_READ, GRPC_FINISHED,
|
206
|
+
GRPC_SERVER_RPC_NEW);
|
207
|
+
return Qnil;
|
208
|
+
}
|
209
|
+
|
210
|
+
result = rb_hash_new();
|
211
|
+
for (i = 0; i < count; i++) {
|
212
|
+
key = rb_str_new2(metadata[i].key);
|
213
|
+
value = rb_hash_aref(result, key);
|
214
|
+
if (value == Qnil) {
|
215
|
+
value = rb_str_new(metadata[i].value, metadata[i].value_length);
|
216
|
+
rb_hash_aset(result, key, value);
|
217
|
+
} else if (TYPE(value) == T_ARRAY) {
|
218
|
+
/* Add the string to the returned array */
|
219
|
+
rb_ary_push(value,
|
220
|
+
rb_str_new(metadata[i].value, metadata[i].value_length));
|
221
|
+
} else {
|
222
|
+
/* Add the current value with this key and the new one to an array */
|
223
|
+
new_ary = rb_ary_new();
|
224
|
+
rb_ary_push(new_ary, value);
|
225
|
+
rb_ary_push(new_ary,
|
226
|
+
rb_str_new(metadata[i].value, metadata[i].value_length));
|
227
|
+
rb_hash_aset(result, key, new_ary);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
return result;
|
231
|
+
}
|
232
|
+
|
233
|
+
/* Obtains the data associated with an event. */
|
234
|
+
static VALUE grpc_rb_event_result(VALUE self) {
|
235
|
+
grpc_event *event = NULL;
|
236
|
+
grpc_rb_event *wrapper = NULL;
|
237
|
+
Data_Get_Struct(self, grpc_rb_event, wrapper);
|
238
|
+
if (wrapper->wrapped == NULL) {
|
239
|
+
rb_raise(rb_eRuntimeError, "finished!");
|
240
|
+
return Qnil;
|
241
|
+
}
|
242
|
+
event = wrapper->wrapped;
|
243
|
+
|
244
|
+
switch (event->type) {
|
245
|
+
case GRPC_QUEUE_SHUTDOWN:
|
246
|
+
return Qnil;
|
247
|
+
|
248
|
+
case GRPC_READ:
|
249
|
+
return grpc_rb_byte_buffer_create_with_mark(self, event->data.read);
|
250
|
+
|
251
|
+
case GRPC_FINISH_ACCEPTED:
|
252
|
+
if (event->data.finish_accepted == GRPC_OP_OK) {
|
253
|
+
return Qnil;
|
254
|
+
}
|
255
|
+
rb_raise(rb_eEventError, "finish failed, not sure why (code=%d)",
|
256
|
+
event->data.finish_accepted);
|
257
|
+
break;
|
258
|
+
|
259
|
+
case GRPC_WRITE_ACCEPTED:
|
260
|
+
if (event->data.write_accepted == GRPC_OP_OK) {
|
261
|
+
return Qnil;
|
262
|
+
}
|
263
|
+
rb_raise(rb_eEventError, "write failed, not sure why (code=%d)",
|
264
|
+
event->data.write_accepted);
|
265
|
+
break;
|
266
|
+
|
267
|
+
case GRPC_CLIENT_METADATA_READ:
|
268
|
+
return grpc_rb_event_metadata(self);
|
269
|
+
|
270
|
+
case GRPC_FINISHED:
|
271
|
+
return rb_struct_new(rb_sStatus, UINT2NUM(event->data.finished.status),
|
272
|
+
(event->data.finished.details == NULL
|
273
|
+
? Qnil
|
274
|
+
: rb_str_new2(event->data.finished.details)),
|
275
|
+
grpc_rb_event_metadata(self), NULL);
|
276
|
+
break;
|
277
|
+
|
278
|
+
case GRPC_SERVER_RPC_NEW:
|
279
|
+
return rb_struct_new(
|
280
|
+
rb_sNewServerRpc, rb_str_new2(event->data.server_rpc_new.method),
|
281
|
+
rb_str_new2(event->data.server_rpc_new.host),
|
282
|
+
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
|
283
|
+
(void *)&event->data.server_rpc_new.deadline),
|
284
|
+
grpc_rb_event_metadata(self), NULL);
|
285
|
+
|
286
|
+
default:
|
287
|
+
rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d",
|
288
|
+
event->type);
|
289
|
+
}
|
290
|
+
|
291
|
+
return Qfalse;
|
292
|
+
}
|
293
|
+
|
294
|
+
static VALUE grpc_rb_event_finish(VALUE self) {
|
295
|
+
grpc_event *event = NULL;
|
296
|
+
grpc_rb_event *wrapper = NULL;
|
297
|
+
Data_Get_Struct(self, grpc_rb_event, wrapper);
|
298
|
+
if (wrapper->wrapped == NULL) { /* already closed */
|
299
|
+
return Qnil;
|
300
|
+
}
|
301
|
+
event = wrapper->wrapped;
|
302
|
+
grpc_event_finish(event);
|
303
|
+
wrapper->wrapped = NULL;
|
304
|
+
wrapper->mark = Qnil;
|
305
|
+
return Qnil;
|
306
|
+
}
|
307
|
+
|
308
|
+
/* rb_cEvent is the Event class whose instances proxy grpc_event */
|
309
|
+
VALUE rb_cEvent = Qnil;
|
310
|
+
|
311
|
+
/* rb_eEventError is the ruby class of the exception thrown on failures during
|
312
|
+
rpc event processing. */
|
313
|
+
VALUE rb_eEventError = Qnil;
|
314
|
+
|
315
|
+
void Init_grpc_event() {
|
316
|
+
rb_eEventError =
|
317
|
+
rb_define_class_under(rb_mGrpcCore, "EventError", rb_eStandardError);
|
318
|
+
rb_cEvent = rb_define_class_under(rb_mGrpcCore, "Event", rb_cObject);
|
319
|
+
|
320
|
+
/* Prevent allocation or inialization from ruby. */
|
321
|
+
rb_define_alloc_func(rb_cEvent, grpc_rb_cannot_alloc);
|
322
|
+
rb_define_method(rb_cEvent, "initialize", grpc_rb_cannot_init, 0);
|
323
|
+
rb_define_method(rb_cEvent, "initialize_copy", grpc_rb_cannot_init_copy, 1);
|
324
|
+
|
325
|
+
/* Accessors for the data available in an event. */
|
326
|
+
rb_define_method(rb_cEvent, "call", grpc_rb_event_call, 0);
|
327
|
+
rb_define_method(rb_cEvent, "result", grpc_rb_event_result, 0);
|
328
|
+
rb_define_method(rb_cEvent, "tag", grpc_rb_event_tag, 0);
|
329
|
+
rb_define_method(rb_cEvent, "type", grpc_rb_event_type, 0);
|
330
|
+
rb_define_method(rb_cEvent, "finish", grpc_rb_event_finish, 0);
|
331
|
+
rb_define_alias(rb_cEvent, "close", "finish");
|
332
|
+
|
333
|
+
/* Constants representing the completion types */
|
334
|
+
rb_mCompletionType =
|
335
|
+
rb_define_module_under(rb_mGrpcCore, "CompletionType");
|
336
|
+
rb_define_const(rb_mCompletionType, "QUEUE_SHUTDOWN",
|
337
|
+
INT2NUM(GRPC_QUEUE_SHUTDOWN));
|
338
|
+
rb_define_const(rb_mCompletionType, "OP_COMPLETE", INT2NUM(GRPC_OP_COMPLETE));
|
339
|
+
rb_define_const(rb_mCompletionType, "READ", INT2NUM(GRPC_READ));
|
340
|
+
rb_define_const(rb_mCompletionType, "WRITE_ACCEPTED",
|
341
|
+
INT2NUM(GRPC_WRITE_ACCEPTED));
|
342
|
+
rb_define_const(rb_mCompletionType, "FINISH_ACCEPTED",
|
343
|
+
INT2NUM(GRPC_FINISH_ACCEPTED));
|
344
|
+
rb_define_const(rb_mCompletionType, "CLIENT_METADATA_READ",
|
345
|
+
INT2NUM(GRPC_CLIENT_METADATA_READ));
|
346
|
+
rb_define_const(rb_mCompletionType, "FINISHED", INT2NUM(GRPC_FINISHED));
|
347
|
+
rb_define_const(rb_mCompletionType, "SERVER_RPC_NEW",
|
348
|
+
INT2NUM(GRPC_SERVER_RPC_NEW));
|
349
|
+
rb_define_const(rb_mCompletionType, "SERVER_SHUTDOWN",
|
350
|
+
INT2NUM(GRPC_SERVER_SHUTDOWN));
|
351
|
+
rb_define_const(rb_mCompletionType, "RESERVED",
|
352
|
+
INT2NUM(GRPC_COMPLETION_DO_NOT_USE));
|
353
|
+
}
|
354
|
+
|
355
|
+
VALUE grpc_rb_new_event(grpc_event *ev) {
|
356
|
+
grpc_rb_event *wrapper = ALLOC(grpc_rb_event);
|
357
|
+
wrapper->wrapped = ev;
|
358
|
+
wrapper->mark = Qnil;
|
359
|
+
return Data_Wrap_Struct(rb_cEvent, grpc_rb_event_mark, grpc_rb_event_free,
|
360
|
+
wrapper);
|
361
|
+
}
|
data/ext/grpc/rb_event.h
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_RB_EVENT_H_
|
35
|
+
#define GRPC_RB_EVENT_H_
|
36
|
+
|
37
|
+
#include <ruby.h>
|
38
|
+
#include <grpc/grpc.h>
|
39
|
+
|
40
|
+
/* rb_cEvent is the Event class whose instances proxy grpc_event. */
|
41
|
+
extern VALUE rb_cEvent;
|
42
|
+
|
43
|
+
/* rb_cEventError is the ruby class that acts the exception thrown during rpc
|
44
|
+
event processing. */
|
45
|
+
extern VALUE rb_eEventError;
|
46
|
+
|
47
|
+
/* Used to create new ruby event objects */
|
48
|
+
VALUE grpc_rb_new_event(grpc_event *ev);
|
49
|
+
|
50
|
+
/* Initializes the Event and EventError classes. */
|
51
|
+
void Init_grpc_event();
|
52
|
+
|
53
|
+
#endif /* GRPC_RB_EVENT_H_ */
|