nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 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_grpc.h" |
| 35 | |
| 36 | #include <math.h> |
Yuki Yugui Sonoda | 2288791 | 2015-04-16 20:57:17 +0900 | [diff] [blame] | 37 | #include <ruby/ruby.h> |
| 38 | #include <ruby/vm.h> |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 39 | #include <sys/time.h> |
| 40 | |
| 41 | #include <grpc/grpc.h> |
| 42 | #include <grpc/support/time.h> |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 43 | #include "rb_call.h" |
| 44 | #include "rb_channel.h" |
| 45 | #include "rb_completion_queue.h" |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 46 | #include "rb_server.h" |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 47 | #include "rb_credentials.h" |
| 48 | #include "rb_server_credentials.h" |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 49 | |
Yuki Yugui Sonoda | 3c88e5d | 2015-04-16 20:09:00 +0900 | [diff] [blame] | 50 | static VALUE grpc_rb_cTimeVal = Qnil; |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 51 | |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 52 | static rb_data_type_t grpc_rb_timespec_data_type = { |
| 53 | "gpr_timespec", |
murgatroid99 | 87afb5d | 2015-07-16 16:01:02 -0700 | [diff] [blame] | 54 | {GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, GRPC_RB_MEMSIZE_UNAVAILABLE, |
| 55 | {NULL, NULL}}, |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 56 | NULL, |
| 57 | NULL, |
| 58 | RUBY_TYPED_FREE_IMMEDIATELY}; |
| 59 | |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 60 | /* Alloc func that blocks allocation of a given object by raising an |
| 61 | * exception. */ |
| 62 | VALUE grpc_rb_cannot_alloc(VALUE cls) { |
| 63 | rb_raise(rb_eTypeError, |
| 64 | "allocation of %s only allowed from the gRPC native layer", |
| 65 | rb_class2name(cls)); |
| 66 | return Qnil; |
| 67 | } |
| 68 | |
| 69 | /* Init func that fails by raising an exception. */ |
| 70 | VALUE grpc_rb_cannot_init(VALUE self) { |
| 71 | rb_raise(rb_eTypeError, |
| 72 | "initialization of %s only allowed from the gRPC native layer", |
| 73 | rb_obj_classname(self)); |
| 74 | return Qnil; |
| 75 | } |
| 76 | |
| 77 | /* Init/Clone func that fails by raising an exception. */ |
| 78 | VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self) { |
murgatroid99 | 87afb5d | 2015-07-16 16:01:02 -0700 | [diff] [blame] | 79 | (void)self; |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 80 | rb_raise(rb_eTypeError, |
| 81 | "initialization of %s only allowed from the gRPC native layer", |
| 82 | rb_obj_classname(copy)); |
| 83 | return Qnil; |
| 84 | } |
| 85 | |
| 86 | /* id_tv_{,u}sec are accessor methods on Ruby Time instances. */ |
| 87 | static ID id_tv_sec; |
| 88 | static ID id_tv_nsec; |
| 89 | |
| 90 | /** |
| 91 | * grpc_rb_time_timeval creates a time_eval from a ruby time object. |
| 92 | * |
| 93 | * This func is copied from ruby source, MRI/source/time.c, which is published |
| 94 | * under the same license as the ruby.h, on which the entire extensions is |
| 95 | * based. |
| 96 | */ |
| 97 | gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) { |
| 98 | gpr_timespec t; |
| 99 | gpr_timespec *time_const; |
| 100 | const char *tstr = interval ? "time interval" : "time"; |
| 101 | const char *want = " want <secs from epoch>|<Time>|<GRPC::TimeConst.*>"; |
| 102 | |
Craig Tiller | 5a1e7fd | 2015-07-14 07:14:47 -0700 | [diff] [blame] | 103 | t.clock_type = GPR_CLOCK_REALTIME; |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 104 | switch (TYPE(time)) { |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 105 | case T_DATA: |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 106 | if (CLASS_OF(time) == grpc_rb_cTimeVal) { |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 107 | TypedData_Get_Struct(time, gpr_timespec, &grpc_rb_timespec_data_type, |
| 108 | time_const); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 109 | t = *time_const; |
| 110 | } else if (CLASS_OF(time) == rb_cTime) { |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 111 | t.tv_sec = NUM2INT(rb_funcall(time, id_tv_sec, 0)); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 112 | t.tv_nsec = NUM2INT(rb_funcall(time, id_tv_nsec, 0)); |
| 113 | } else { |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 114 | rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr, |
| 115 | rb_obj_classname(time), want); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 116 | } |
| 117 | break; |
| 118 | |
| 119 | case T_FIXNUM: |
| 120 | t.tv_sec = FIX2LONG(time); |
| 121 | if (interval && t.tv_sec < 0) |
| 122 | rb_raise(rb_eArgError, "%s must be positive", tstr); |
| 123 | t.tv_nsec = 0; |
| 124 | break; |
| 125 | |
| 126 | case T_FLOAT: |
mattn | b9e1563 | 2015-02-28 23:45:58 +0900 | [diff] [blame] | 127 | if (interval && RFLOAT_VALUE(time) < 0.0) |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 128 | rb_raise(rb_eArgError, "%s must be positive", tstr); |
| 129 | else { |
| 130 | double f, d; |
| 131 | |
mattn | b9e1563 | 2015-02-28 23:45:58 +0900 | [diff] [blame] | 132 | d = modf(RFLOAT_VALUE(time), &f); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 133 | if (d < 0) { |
| 134 | d += 1; |
| 135 | f -= 1; |
| 136 | } |
| 137 | t.tv_sec = (time_t)f; |
| 138 | if (f != t.tv_sec) { |
| 139 | rb_raise(rb_eRangeError, "%f out of Time range", |
mattn | b9e1563 | 2015-02-28 23:45:58 +0900 | [diff] [blame] | 140 | RFLOAT_VALUE(time)); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 141 | } |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 142 | t.tv_nsec = (time_t)(d * 1e9 + 0.5); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 143 | } |
| 144 | break; |
| 145 | |
| 146 | case T_BIGNUM: |
| 147 | t.tv_sec = NUM2LONG(time); |
| 148 | if (interval && t.tv_sec < 0) |
| 149 | rb_raise(rb_eArgError, "%s must be positive", tstr); |
| 150 | t.tv_nsec = 0; |
| 151 | break; |
| 152 | |
| 153 | default: |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 154 | rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr, |
| 155 | rb_obj_classname(time), want); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 156 | break; |
| 157 | } |
| 158 | return t; |
| 159 | } |
| 160 | |
Yuki Yugui Sonoda | f0eee5f | 2015-04-16 20:25:28 +0900 | [diff] [blame] | 161 | static void Init_grpc_status_codes() { |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 162 | /* Constants representing the status codes or grpc_status_code in status.h */ |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 163 | VALUE grpc_rb_mStatusCodes = |
| 164 | rb_define_module_under(grpc_rb_mGrpcCore, "StatusCodes"); |
| 165 | rb_define_const(grpc_rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK)); |
| 166 | rb_define_const(grpc_rb_mStatusCodes, "CANCELLED", |
| 167 | INT2NUM(GRPC_STATUS_CANCELLED)); |
| 168 | rb_define_const(grpc_rb_mStatusCodes, "UNKNOWN", |
| 169 | INT2NUM(GRPC_STATUS_UNKNOWN)); |
| 170 | rb_define_const(grpc_rb_mStatusCodes, "INVALID_ARGUMENT", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 171 | INT2NUM(GRPC_STATUS_INVALID_ARGUMENT)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 172 | rb_define_const(grpc_rb_mStatusCodes, "DEADLINE_EXCEEDED", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 173 | INT2NUM(GRPC_STATUS_DEADLINE_EXCEEDED)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 174 | rb_define_const(grpc_rb_mStatusCodes, "NOT_FOUND", |
| 175 | INT2NUM(GRPC_STATUS_NOT_FOUND)); |
| 176 | rb_define_const(grpc_rb_mStatusCodes, "ALREADY_EXISTS", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 177 | INT2NUM(GRPC_STATUS_ALREADY_EXISTS)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 178 | rb_define_const(grpc_rb_mStatusCodes, "PERMISSION_DENIED", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 179 | INT2NUM(GRPC_STATUS_PERMISSION_DENIED)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 180 | rb_define_const(grpc_rb_mStatusCodes, "UNAUTHENTICATED", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 181 | INT2NUM(GRPC_STATUS_UNAUTHENTICATED)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 182 | rb_define_const(grpc_rb_mStatusCodes, "RESOURCE_EXHAUSTED", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 183 | INT2NUM(GRPC_STATUS_RESOURCE_EXHAUSTED)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 184 | rb_define_const(grpc_rb_mStatusCodes, "FAILED_PRECONDITION", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 185 | INT2NUM(GRPC_STATUS_FAILED_PRECONDITION)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 186 | rb_define_const(grpc_rb_mStatusCodes, "ABORTED", |
| 187 | INT2NUM(GRPC_STATUS_ABORTED)); |
| 188 | rb_define_const(grpc_rb_mStatusCodes, "OUT_OF_RANGE", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 189 | INT2NUM(GRPC_STATUS_OUT_OF_RANGE)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 190 | rb_define_const(grpc_rb_mStatusCodes, "UNIMPLEMENTED", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 191 | INT2NUM(GRPC_STATUS_UNIMPLEMENTED)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 192 | rb_define_const(grpc_rb_mStatusCodes, "INTERNAL", |
| 193 | INT2NUM(GRPC_STATUS_INTERNAL)); |
| 194 | rb_define_const(grpc_rb_mStatusCodes, "UNAVAILABLE", |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 195 | INT2NUM(GRPC_STATUS_UNAVAILABLE)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 196 | rb_define_const(grpc_rb_mStatusCodes, "DATA_LOSS", |
| 197 | INT2NUM(GRPC_STATUS_DATA_LOSS)); |
temiola | 5832791 | 2014-12-15 17:51:16 -0800 | [diff] [blame] | 198 | } |
| 199 | |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 200 | /* id_at is the constructor method of the ruby standard Time class. */ |
| 201 | static ID id_at; |
| 202 | |
| 203 | /* id_inspect is the inspect method found on various ruby objects. */ |
| 204 | static ID id_inspect; |
| 205 | |
| 206 | /* id_to_s is the to_s method found on various ruby objects. */ |
| 207 | static ID id_to_s; |
| 208 | |
Tim Emiola | 98a32d3 | 2015-03-28 01:48:44 -0700 | [diff] [blame] | 209 | /* Converts a wrapped time constant to a standard time. */ |
Yuki Yugui Sonoda | f0eee5f | 2015-04-16 20:25:28 +0900 | [diff] [blame] | 210 | static VALUE grpc_rb_time_val_to_time(VALUE self) { |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 211 | gpr_timespec *time_const = NULL; |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 212 | TypedData_Get_Struct(self, gpr_timespec, &grpc_rb_timespec_data_type, |
| 213 | time_const); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 214 | return rb_funcall(rb_cTime, id_at, 2, INT2NUM(time_const->tv_sec), |
| 215 | INT2NUM(time_const->tv_nsec)); |
| 216 | } |
| 217 | |
| 218 | /* Invokes inspect on the ctime version of the time val. */ |
Yuki Yugui Sonoda | f0eee5f | 2015-04-16 20:25:28 +0900 | [diff] [blame] | 219 | static VALUE grpc_rb_time_val_inspect(VALUE self) { |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 220 | return rb_funcall(grpc_rb_time_val_to_time(self), id_inspect, 0); |
| 221 | } |
| 222 | |
| 223 | /* Invokes to_s on the ctime version of the time val. */ |
Yuki Yugui Sonoda | f0eee5f | 2015-04-16 20:25:28 +0900 | [diff] [blame] | 224 | static VALUE grpc_rb_time_val_to_s(VALUE self) { |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 225 | return rb_funcall(grpc_rb_time_val_to_time(self), id_to_s, 0); |
| 226 | } |
| 227 | |
Craig Tiller | 354398f | 2015-07-13 09:16:03 -0700 | [diff] [blame] | 228 | static gpr_timespec zero_realtime; |
| 229 | static gpr_timespec inf_future_realtime; |
| 230 | static gpr_timespec inf_past_realtime; |
| 231 | |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 232 | /* Adds a module with constants that map to gpr's static timeval structs. */ |
Yuki Yugui Sonoda | f0eee5f | 2015-04-16 20:25:28 +0900 | [diff] [blame] | 233 | static void Init_grpc_time_consts() { |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 234 | VALUE grpc_rb_mTimeConsts = |
| 235 | rb_define_module_under(grpc_rb_mGrpcCore, "TimeConsts"); |
| 236 | grpc_rb_cTimeVal = |
| 237 | rb_define_class_under(grpc_rb_mGrpcCore, "TimeSpec", rb_cObject); |
Craig Tiller | 354398f | 2015-07-13 09:16:03 -0700 | [diff] [blame] | 238 | zero_realtime = gpr_time_0(GPR_CLOCK_REALTIME); |
| 239 | inf_future_realtime = gpr_inf_future(GPR_CLOCK_REALTIME); |
| 240 | inf_past_realtime = gpr_inf_past(GPR_CLOCK_REALTIME); |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 241 | rb_define_const( |
| 242 | grpc_rb_mTimeConsts, "ZERO", |
| 243 | TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, |
Craig Tiller | 354398f | 2015-07-13 09:16:03 -0700 | [diff] [blame] | 244 | (void *)&zero_realtime)); |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 245 | rb_define_const( |
| 246 | grpc_rb_mTimeConsts, "INFINITE_FUTURE", |
| 247 | TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, |
Craig Tiller | 354398f | 2015-07-13 09:16:03 -0700 | [diff] [blame] | 248 | (void *)&inf_future_realtime)); |
Yuki Yugui Sonoda | d441c2e | 2015-04-11 15:33:58 +0900 | [diff] [blame] | 249 | rb_define_const( |
| 250 | grpc_rb_mTimeConsts, "INFINITE_PAST", |
| 251 | TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, |
Craig Tiller | 354398f | 2015-07-13 09:16:03 -0700 | [diff] [blame] | 252 | (void *)&inf_past_realtime)); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 253 | rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0); |
| 254 | rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0); |
| 255 | rb_define_method(grpc_rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 256 | id_at = rb_intern("at"); |
| 257 | id_inspect = rb_intern("inspect"); |
| 258 | id_to_s = rb_intern("to_s"); |
| 259 | id_tv_sec = rb_intern("tv_sec"); |
| 260 | id_tv_nsec = rb_intern("tv_nsec"); |
| 261 | } |
| 262 | |
murgatroid99 | 87afb5d | 2015-07-16 16:01:02 -0700 | [diff] [blame] | 263 | static void grpc_rb_shutdown(ruby_vm_t *vm) { |
| 264 | (void)vm; |
| 265 | grpc_shutdown(); |
| 266 | } |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 267 | |
Tim Emiola | 409e6c8 | 2015-02-17 17:46:35 -0800 | [diff] [blame] | 268 | /* Initialize the GRPC module structs */ |
temiola | 21bb60c | 2014-12-18 10:58:22 -0800 | [diff] [blame] | 269 | |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 270 | /* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */ |
| 271 | VALUE grpc_rb_sNewServerRpc = Qnil; |
| 272 | /* grpc_rb_sStatus is the struct that holds status details. */ |
| 273 | VALUE grpc_rb_sStatus = Qnil; |
temiola | 21bb60c | 2014-12-18 10:58:22 -0800 | [diff] [blame] | 274 | |
Tim Emiola | 409e6c8 | 2015-02-17 17:46:35 -0800 | [diff] [blame] | 275 | /* Initialize the GRPC module. */ |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 276 | VALUE grpc_rb_mGRPC = Qnil; |
| 277 | VALUE grpc_rb_mGrpcCore = Qnil; |
temiola | 21bb60c | 2014-12-18 10:58:22 -0800 | [diff] [blame] | 278 | |
Yuki Yugui Sonoda | 99eb9f9 | 2015-04-16 20:09:55 +0900 | [diff] [blame] | 279 | /* cached Symbols for members in Status struct */ |
| 280 | VALUE sym_code = Qundef; |
| 281 | VALUE sym_details = Qundef; |
| 282 | VALUE sym_metadata = Qundef; |
| 283 | |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 284 | void Init_grpc() { |
| 285 | grpc_init(); |
| 286 | ruby_vm_at_exit(grpc_rb_shutdown); |
Yuki Yugui Sonoda | a7d369e | 2015-04-11 11:48:36 +0900 | [diff] [blame] | 287 | grpc_rb_mGRPC = rb_define_module("GRPC"); |
| 288 | grpc_rb_mGrpcCore = rb_define_module_under(grpc_rb_mGRPC, "Core"); |
| 289 | grpc_rb_sNewServerRpc = |
| 290 | rb_struct_define("NewServerRpc", "method", "host", |
| 291 | "deadline", "metadata", "call", NULL); |
| 292 | grpc_rb_sStatus = |
| 293 | rb_struct_define("Status", "code", "details", "metadata", NULL); |
Tim Emiola | 98a32d3 | 2015-03-28 01:48:44 -0700 | [diff] [blame] | 294 | sym_code = ID2SYM(rb_intern("code")); |
| 295 | sym_details = ID2SYM(rb_intern("details")); |
| 296 | sym_metadata = ID2SYM(rb_intern("metadata")); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 297 | |
Tim Emiola | 409e6c8 | 2015-02-17 17:46:35 -0800 | [diff] [blame] | 298 | Init_grpc_channel(); |
| 299 | Init_grpc_completion_queue(); |
| 300 | Init_grpc_call(); |
| 301 | Init_grpc_credentials(); |
Tim Emiola | 409e6c8 | 2015-02-17 17:46:35 -0800 | [diff] [blame] | 302 | Init_grpc_server(); |
| 303 | Init_grpc_server_credentials(); |
| 304 | Init_grpc_status_codes(); |
| 305 | Init_grpc_time_consts(); |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 306 | } |