blob: 2a3b33910275e3a04da9bd8c9d8cf0b9cd4f32a1 [file] [log] [blame]
nnoble097ef9b2014-12-01 17:06:10 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
nnoble097ef9b2014-12-01 17:06:10 -08004 * 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
Nicolas "Pixel" Nobled51d1212016-01-31 11:33:19 +010034#include <ruby/ruby.h>
Nicolas "Pixel" Noble9fcdc872016-05-05 06:15:34 +020035
Craig Tiller5b1c5f22017-04-19 09:52:18 -070036#include "rb_grpc_imports.generated.h"
Alexander Polcynf5521c32017-04-26 14:18:39 -070037#include "rb_grpc.h"
nnoble097ef9b2014-12-01 17:06:10 -080038
39#include <math.h>
Yuki Yugui Sonoda22887912015-04-16 20:57:17 +090040#include <ruby/vm.h>
nnoble097ef9b2014-12-01 17:06:10 -080041#include <sys/time.h>
42
43#include <grpc/grpc.h>
44#include <grpc/support/time.h>
Alexander Polcyn5c6dda82017-05-17 13:08:34 -070045#include <grpc/support/log.h>
nnoble097ef9b2014-12-01 17:06:10 -080046#include "rb_call.h"
murgatroid999946f2b2015-12-04 14:36:27 -080047#include "rb_call_credentials.h"
nnoble097ef9b2014-12-01 17:06:10 -080048#include "rb_channel.h"
Tim Emiola9332ea62015-10-27 23:48:29 -070049#include "rb_channel_credentials.h"
Nicolas "Pixel" Nobled51d1212016-01-31 11:33:19 +010050#include "rb_loader.h"
nnoble097ef9b2014-12-01 17:06:10 -080051#include "rb_server.h"
nnoble0c475f02014-12-05 15:37:39 -080052#include "rb_server_credentials.h"
Alexander Polcynf5521c32017-04-26 14:18:39 -070053#include "rb_compression_options.h"
54#include "rb_event_thread.h"
55#include "rb_channel.h"
nnoble097ef9b2014-12-01 17:06:10 -080056
Yuki Yugui Sonoda3c88e5d2015-04-16 20:09:00 +090057static VALUE grpc_rb_cTimeVal = Qnil;
nnoble097ef9b2014-12-01 17:06:10 -080058
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +090059static rb_data_type_t grpc_rb_timespec_data_type = {
60 "gpr_timespec",
Alexander Polcynf5521c32017-04-26 14:18:39 -070061 {GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, GRPC_RB_MEMSIZE_UNAVAILABLE,
murgatroid9987afb5d2015-07-16 16:01:02 -070062 {NULL, NULL}},
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +090063 NULL,
64 NULL,
Tim Emiola9161a822015-11-11 15:58:44 -080065#ifdef RUBY_TYPED_FREE_IMMEDIATELY
66 RUBY_TYPED_FREE_IMMEDIATELY
67#endif
68};
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +090069
nnoble097ef9b2014-12-01 17:06:10 -080070/* Alloc func that blocks allocation of a given object by raising an
71 * exception. */
72VALUE grpc_rb_cannot_alloc(VALUE cls) {
73 rb_raise(rb_eTypeError,
74 "allocation of %s only allowed from the gRPC native layer",
75 rb_class2name(cls));
76 return Qnil;
77}
78
79/* Init func that fails by raising an exception. */
80VALUE grpc_rb_cannot_init(VALUE self) {
81 rb_raise(rb_eTypeError,
82 "initialization of %s only allowed from the gRPC native layer",
83 rb_obj_classname(self));
84 return Qnil;
85}
86
87/* Init/Clone func that fails by raising an exception. */
88VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self) {
murgatroid9987afb5d2015-07-16 16:01:02 -070089 (void)self;
Alexander Polcynf5521c32017-04-26 14:18:39 -070090 rb_raise(rb_eTypeError,
91 "Copy initialization of %s is not supported",
nnoble097ef9b2014-12-01 17:06:10 -080092 rb_obj_classname(copy));
93 return Qnil;
94}
95
96/* id_tv_{,u}sec are accessor methods on Ruby Time instances. */
97static ID id_tv_sec;
98static ID id_tv_nsec;
99
100/**
Jan Tattermusch88086372015-12-10 10:54:12 -0800101 * grpc_rb_time_timeval creates a timeval from a ruby time object.
nnoble097ef9b2014-12-01 17:06:10 -0800102 *
103 * This func is copied from ruby source, MRI/source/time.c, which is published
104 * under the same license as the ruby.h, on which the entire extensions is
105 * based.
106 */
107gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
108 gpr_timespec t;
109 gpr_timespec *time_const;
110 const char *tstr = interval ? "time interval" : "time";
111 const char *want = " want <secs from epoch>|<Time>|<GRPC::TimeConst.*>";
112
Craig Tiller5a1e7fd2015-07-14 07:14:47 -0700113 t.clock_type = GPR_CLOCK_REALTIME;
nnoble097ef9b2014-12-01 17:06:10 -0800114 switch (TYPE(time)) {
nnoble097ef9b2014-12-01 17:06:10 -0800115 case T_DATA:
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900116 if (CLASS_OF(time) == grpc_rb_cTimeVal) {
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +0900117 TypedData_Get_Struct(time, gpr_timespec, &grpc_rb_timespec_data_type,
118 time_const);
nnoble097ef9b2014-12-01 17:06:10 -0800119 t = *time_const;
120 } else if (CLASS_OF(time) == rb_cTime) {
Craig Tillerb5dcec52015-01-13 11:13:42 -0800121 t.tv_sec = NUM2INT(rb_funcall(time, id_tv_sec, 0));
nnoble097ef9b2014-12-01 17:06:10 -0800122 t.tv_nsec = NUM2INT(rb_funcall(time, id_tv_nsec, 0));
123 } else {
Craig Tillerb5dcec52015-01-13 11:13:42 -0800124 rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr,
125 rb_obj_classname(time), want);
nnoble097ef9b2014-12-01 17:06:10 -0800126 }
127 break;
128
129 case T_FIXNUM:
130 t.tv_sec = FIX2LONG(time);
131 if (interval && t.tv_sec < 0)
132 rb_raise(rb_eArgError, "%s must be positive", tstr);
133 t.tv_nsec = 0;
134 break;
135
136 case T_FLOAT:
mattnb9e15632015-02-28 23:45:58 +0900137 if (interval && RFLOAT_VALUE(time) < 0.0)
nnoble097ef9b2014-12-01 17:06:10 -0800138 rb_raise(rb_eArgError, "%s must be positive", tstr);
139 else {
140 double f, d;
141
mattnb9e15632015-02-28 23:45:58 +0900142 d = modf(RFLOAT_VALUE(time), &f);
nnoble097ef9b2014-12-01 17:06:10 -0800143 if (d < 0) {
144 d += 1;
145 f -= 1;
146 }
Craig Tiller7536af02015-12-22 13:49:30 -0800147 t.tv_sec = (int64_t)f;
nnoble097ef9b2014-12-01 17:06:10 -0800148 if (f != t.tv_sec) {
Alexander Polcynf5521c32017-04-26 14:18:39 -0700149 rb_raise(rb_eRangeError, "%f out of Time range",
150 RFLOAT_VALUE(time));
nnoble097ef9b2014-12-01 17:06:10 -0800151 }
Marcin Wyszynski1a2ac332015-07-23 20:12:33 +0200152 t.tv_nsec = (int)(d * 1e9 + 0.5);
nnoble097ef9b2014-12-01 17:06:10 -0800153 }
154 break;
155
156 case T_BIGNUM:
157 t.tv_sec = NUM2LONG(time);
158 if (interval && t.tv_sec < 0)
159 rb_raise(rb_eArgError, "%s must be positive", tstr);
160 t.tv_nsec = 0;
161 break;
162
163 default:
Craig Tillerb5dcec52015-01-13 11:13:42 -0800164 rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr,
165 rb_obj_classname(time), want);
nnoble097ef9b2014-12-01 17:06:10 -0800166 break;
167 }
168 return t;
169}
170
Yuki Yugui Sonodaf0eee5f2015-04-16 20:25:28 +0900171static void Init_grpc_status_codes() {
temiola58327912014-12-15 17:51:16 -0800172 /* Constants representing the status codes or grpc_status_code in status.h */
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900173 VALUE grpc_rb_mStatusCodes =
174 rb_define_module_under(grpc_rb_mGrpcCore, "StatusCodes");
175 rb_define_const(grpc_rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK));
176 rb_define_const(grpc_rb_mStatusCodes, "CANCELLED",
177 INT2NUM(GRPC_STATUS_CANCELLED));
178 rb_define_const(grpc_rb_mStatusCodes, "UNKNOWN",
179 INT2NUM(GRPC_STATUS_UNKNOWN));
180 rb_define_const(grpc_rb_mStatusCodes, "INVALID_ARGUMENT",
temiola58327912014-12-15 17:51:16 -0800181 INT2NUM(GRPC_STATUS_INVALID_ARGUMENT));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900182 rb_define_const(grpc_rb_mStatusCodes, "DEADLINE_EXCEEDED",
temiola58327912014-12-15 17:51:16 -0800183 INT2NUM(GRPC_STATUS_DEADLINE_EXCEEDED));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900184 rb_define_const(grpc_rb_mStatusCodes, "NOT_FOUND",
185 INT2NUM(GRPC_STATUS_NOT_FOUND));
186 rb_define_const(grpc_rb_mStatusCodes, "ALREADY_EXISTS",
temiola58327912014-12-15 17:51:16 -0800187 INT2NUM(GRPC_STATUS_ALREADY_EXISTS));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900188 rb_define_const(grpc_rb_mStatusCodes, "PERMISSION_DENIED",
temiola58327912014-12-15 17:51:16 -0800189 INT2NUM(GRPC_STATUS_PERMISSION_DENIED));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900190 rb_define_const(grpc_rb_mStatusCodes, "UNAUTHENTICATED",
temiola58327912014-12-15 17:51:16 -0800191 INT2NUM(GRPC_STATUS_UNAUTHENTICATED));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900192 rb_define_const(grpc_rb_mStatusCodes, "RESOURCE_EXHAUSTED",
temiola58327912014-12-15 17:51:16 -0800193 INT2NUM(GRPC_STATUS_RESOURCE_EXHAUSTED));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900194 rb_define_const(grpc_rb_mStatusCodes, "FAILED_PRECONDITION",
temiola58327912014-12-15 17:51:16 -0800195 INT2NUM(GRPC_STATUS_FAILED_PRECONDITION));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900196 rb_define_const(grpc_rb_mStatusCodes, "ABORTED",
197 INT2NUM(GRPC_STATUS_ABORTED));
198 rb_define_const(grpc_rb_mStatusCodes, "OUT_OF_RANGE",
temiola58327912014-12-15 17:51:16 -0800199 INT2NUM(GRPC_STATUS_OUT_OF_RANGE));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900200 rb_define_const(grpc_rb_mStatusCodes, "UNIMPLEMENTED",
temiola58327912014-12-15 17:51:16 -0800201 INT2NUM(GRPC_STATUS_UNIMPLEMENTED));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900202 rb_define_const(grpc_rb_mStatusCodes, "INTERNAL",
203 INT2NUM(GRPC_STATUS_INTERNAL));
204 rb_define_const(grpc_rb_mStatusCodes, "UNAVAILABLE",
temiola58327912014-12-15 17:51:16 -0800205 INT2NUM(GRPC_STATUS_UNAVAILABLE));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900206 rb_define_const(grpc_rb_mStatusCodes, "DATA_LOSS",
207 INT2NUM(GRPC_STATUS_DATA_LOSS));
temiola58327912014-12-15 17:51:16 -0800208}
209
nnoble097ef9b2014-12-01 17:06:10 -0800210/* id_at is the constructor method of the ruby standard Time class. */
211static ID id_at;
212
213/* id_inspect is the inspect method found on various ruby objects. */
214static ID id_inspect;
215
216/* id_to_s is the to_s method found on various ruby objects. */
217static ID id_to_s;
218
Tim Emiola98a32d32015-03-28 01:48:44 -0700219/* Converts a wrapped time constant to a standard time. */
Yuki Yugui Sonodaf0eee5f2015-04-16 20:25:28 +0900220static VALUE grpc_rb_time_val_to_time(VALUE self) {
nnoble097ef9b2014-12-01 17:06:10 -0800221 gpr_timespec *time_const = NULL;
Craig Tiller94329d02015-07-23 09:52:11 -0700222 gpr_timespec real_time;
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +0900223 TypedData_Get_Struct(self, gpr_timespec, &grpc_rb_timespec_data_type,
224 time_const);
Craig Tiller94329d02015-07-23 09:52:11 -0700225 real_time = gpr_convert_clock_type(*time_const, GPR_CLOCK_REALTIME);
226 return rb_funcall(rb_cTime, id_at, 2, INT2NUM(real_time.tv_sec),
Eric Richardson8e769fd2016-07-08 12:36:54 -0400227 INT2NUM(real_time.tv_nsec / 1000));
nnoble097ef9b2014-12-01 17:06:10 -0800228}
229
230/* Invokes inspect on the ctime version of the time val. */
Yuki Yugui Sonodaf0eee5f2015-04-16 20:25:28 +0900231static VALUE grpc_rb_time_val_inspect(VALUE self) {
nnoble097ef9b2014-12-01 17:06:10 -0800232 return rb_funcall(grpc_rb_time_val_to_time(self), id_inspect, 0);
233}
234
235/* Invokes to_s on the ctime version of the time val. */
Yuki Yugui Sonodaf0eee5f2015-04-16 20:25:28 +0900236static VALUE grpc_rb_time_val_to_s(VALUE self) {
nnoble097ef9b2014-12-01 17:06:10 -0800237 return rb_funcall(grpc_rb_time_val_to_time(self), id_to_s, 0);
238}
239
Craig Tiller354398f2015-07-13 09:16:03 -0700240static gpr_timespec zero_realtime;
241static gpr_timespec inf_future_realtime;
242static gpr_timespec inf_past_realtime;
243
nnoble097ef9b2014-12-01 17:06:10 -0800244/* Adds a module with constants that map to gpr's static timeval structs. */
Yuki Yugui Sonodaf0eee5f2015-04-16 20:25:28 +0900245static void Init_grpc_time_consts() {
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900246 VALUE grpc_rb_mTimeConsts =
247 rb_define_module_under(grpc_rb_mGrpcCore, "TimeConsts");
248 grpc_rb_cTimeVal =
249 rb_define_class_under(grpc_rb_mGrpcCore, "TimeSpec", rb_cObject);
Craig Tiller354398f2015-07-13 09:16:03 -0700250 zero_realtime = gpr_time_0(GPR_CLOCK_REALTIME);
251 inf_future_realtime = gpr_inf_future(GPR_CLOCK_REALTIME);
252 inf_past_realtime = gpr_inf_past(GPR_CLOCK_REALTIME);
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +0900253 rb_define_const(
254 grpc_rb_mTimeConsts, "ZERO",
255 TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type,
Craig Tiller354398f2015-07-13 09:16:03 -0700256 (void *)&zero_realtime));
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +0900257 rb_define_const(
258 grpc_rb_mTimeConsts, "INFINITE_FUTURE",
259 TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type,
Craig Tiller354398f2015-07-13 09:16:03 -0700260 (void *)&inf_future_realtime));
Yuki Yugui Sonodad441c2e2015-04-11 15:33:58 +0900261 rb_define_const(
262 grpc_rb_mTimeConsts, "INFINITE_PAST",
263 TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type,
Craig Tiller354398f2015-07-13 09:16:03 -0700264 (void *)&inf_past_realtime));
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900265 rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0);
266 rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0);
267 rb_define_method(grpc_rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0);
nnoble097ef9b2014-12-01 17:06:10 -0800268 id_at = rb_intern("at");
269 id_inspect = rb_intern("inspect");
270 id_to_s = rb_intern("to_s");
271 id_tv_sec = rb_intern("tv_sec");
272 id_tv_nsec = rb_intern("tv_nsec");
273}
274
Alexander Polcynf5521c32017-04-26 14:18:39 -0700275static void grpc_rb_shutdown(void) {
276 grpc_shutdown();
277}
nnoble097ef9b2014-12-01 17:06:10 -0800278
Tim Emiola409e6c82015-02-17 17:46:35 -0800279/* Initialize the GRPC module structs */
temiola21bb60c2014-12-18 10:58:22 -0800280
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900281/* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
282VALUE grpc_rb_sNewServerRpc = Qnil;
283/* grpc_rb_sStatus is the struct that holds status details. */
284VALUE grpc_rb_sStatus = Qnil;
temiola21bb60c2014-12-18 10:58:22 -0800285
Tim Emiola409e6c82015-02-17 17:46:35 -0800286/* Initialize the GRPC module. */
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900287VALUE grpc_rb_mGRPC = Qnil;
288VALUE grpc_rb_mGrpcCore = Qnil;
temiola21bb60c2014-12-18 10:58:22 -0800289
Yuki Yugui Sonoda99eb9f92015-04-16 20:09:55 +0900290/* cached Symbols for members in Status struct */
291VALUE sym_code = Qundef;
292VALUE sym_details = Qundef;
293VALUE sym_metadata = Qundef;
294
Nicolas "Pixel" Noblecb903972016-02-21 22:58:26 +0100295static gpr_once g_once_init = GPR_ONCE_INIT;
296
Alexander Polcyn2a9b5d72017-04-14 12:10:55 -0700297static void grpc_ruby_once_init_internal() {
Nicolas "Pixel" Noblecb903972016-02-21 22:58:26 +0100298 grpc_init();
299 atexit(grpc_rb_shutdown);
300}
301
Alexander Polcyn5c6dda82017-05-17 13:08:34 -0700302static VALUE bg_thread_init_rb_mu = Qundef;
303static int bg_thread_init_done = 0;
304
Alexander Polcyn2a9b5d72017-04-14 12:10:55 -0700305void grpc_ruby_once_init() {
Nicolas "Pixel" Noble88dc3c52016-02-22 03:21:08 +0100306 /* ruby_vm_at_exit doesn't seem to be working. It would crash once every
307 * blue moon, and some users are getting it repeatedly. See the discussions
308 * - https://github.com/grpc/grpc/pull/5337
309 * - https://bugs.ruby-lang.org/issues/12095
310 *
311 * In order to still be able to handle the (unlikely) situation where the
312 * extension is loaded by a first Ruby VM that is subsequently destroyed,
313 * then loaded again by another VM within the same process, we need to
314 * schedule our initialization and destruction only once.
315 */
Alexander Polcyn2a9b5d72017-04-14 12:10:55 -0700316 gpr_once_init(&g_once_init, grpc_ruby_once_init_internal);
Alexander Polcyn5c6dda82017-05-17 13:08:34 -0700317
318 // Avoid calling calling into ruby library (when creating threads here)
319 // in gpr_once_init. In general, it appears to be unsafe to call
320 // into the ruby library while holding a non-ruby mutex, because a gil yield
321 // could end up trying to lock onto that same mutex and deadlocking.
322 rb_mutex_lock(bg_thread_init_rb_mu);
323 if (!bg_thread_init_done) {
324 grpc_rb_event_queue_thread_start();
325 grpc_rb_channel_polling_thread_start();
326 bg_thread_init_done = 1;
327 }
328 rb_mutex_unlock(bg_thread_init_rb_mu);
Alexander Polcyn2a9b5d72017-04-14 12:10:55 -0700329}
330
331void Init_grpc_c() {
332 if (!grpc_rb_load_core()) {
333 rb_raise(rb_eLoadError, "Couldn't find or load gRPC's dynamic C core");
334 return;
335 }
Tim Emiola9161a822015-11-11 15:58:44 -0800336
Alexander Polcyn5c6dda82017-05-17 13:08:34 -0700337 bg_thread_init_rb_mu = rb_mutex_new();
338 rb_global_variable(&bg_thread_init_rb_mu);
339
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900340 grpc_rb_mGRPC = rb_define_module("GRPC");
341 grpc_rb_mGrpcCore = rb_define_module_under(grpc_rb_mGRPC, "Core");
Alexander Polcynf5521c32017-04-26 14:18:39 -0700342 grpc_rb_sNewServerRpc =
343 rb_struct_define("NewServerRpc", "method", "host",
344 "deadline", "metadata", "call", NULL);
Yuki Yugui Sonodaa7d369e2015-04-11 11:48:36 +0900345 grpc_rb_sStatus =
346 rb_struct_define("Status", "code", "details", "metadata", NULL);
Tim Emiola98a32d32015-03-28 01:48:44 -0700347 sym_code = ID2SYM(rb_intern("code"));
348 sym_details = ID2SYM(rb_intern("details"));
349 sym_metadata = ID2SYM(rb_intern("metadata"));
nnoble097ef9b2014-12-01 17:06:10 -0800350
Tim Emiola409e6c82015-02-17 17:46:35 -0800351 Init_grpc_channel();
Tim Emiola409e6c82015-02-17 17:46:35 -0800352 Init_grpc_call();
murgatroid999946f2b2015-12-04 14:36:27 -0800353 Init_grpc_call_credentials();
Tim Emiola9332ea62015-10-27 23:48:29 -0700354 Init_grpc_channel_credentials();
Tim Emiola409e6c82015-02-17 17:46:35 -0800355 Init_grpc_server();
356 Init_grpc_server_credentials();
357 Init_grpc_status_codes();
358 Init_grpc_time_consts();
Alexander Polcyn0dccf102016-06-27 13:11:07 -0700359 Init_grpc_compression_options();
nnoble097ef9b2014-12-01 17:06:10 -0800360}