Use the prefix "grpc_rb_" rather than just "grpc_".

pull/1245/head
Yuki Yugui Sonoda 10 years ago
parent 0f75ff5d19
commit a7d369ea67
  1. 110
      src/ruby/ext/grpc/rb_call.c
  2. 12
      src/ruby/ext/grpc/rb_call.h
  3. 36
      src/ruby/ext/grpc/rb_channel.c
  4. 4
      src/ruby/ext/grpc/rb_channel.h
  5. 4
      src/ruby/ext/grpc/rb_channel_args.c
  6. 20
      src/ruby/ext/grpc/rb_completion_queue.c
  7. 4
      src/ruby/ext/grpc/rb_completion_queue.h
  8. 25
      src/ruby/ext/grpc/rb_credentials.c
  9. 4
      src/ruby/ext/grpc/rb_credentials.h
  10. 101
      src/ruby/ext/grpc/rb_grpc.c
  11. 20
      src/ruby/ext/grpc/rb_grpc.h
  12. 35
      src/ruby/ext/grpc/rb_server.c
  13. 4
      src/ruby/ext/grpc/rb_server.h
  14. 17
      src/ruby/ext/grpc/rb_server_credentials.c
  15. 4
      src/ruby/ext/grpc/rb_server_credentials.h

@ -42,12 +42,13 @@
#include "rb_completion_queue.h" #include "rb_completion_queue.h"
#include "rb_grpc.h" #include "rb_grpc.h"
/* grpc_sBatchResult is struct class used to hold the results of a batch call */ /* grpc_rb_sBatchResult is struct class used to hold the results of a batch
static VALUE grpc_sBatchResult; * call. */
static VALUE grpc_rb_sBatchResult;
/* grpc_cMdAry is the MetadataArray class whose instances proxy /* grpc_rb_cMdAry is the MetadataArray class whose instances proxy
* grpc_metadata_array. */ * grpc_metadata_array. */
static VALUE grpc_cMdAry; static VALUE grpc_rb_cMdAry;
/* id_cq is the name of the hidden ivar that preserves a reference to a /* id_cq is the name of the hidden ivar that preserves a reference to a
* completion queue */ * completion queue */
@ -70,7 +71,7 @@ static ID id_metadata;
* received by the call and subsequently saved on it. */ * received by the call and subsequently saved on it. */
static ID id_status; static ID id_status;
/* sym_* are the symbol for attributes of grpc_sBatchResult. */ /* sym_* are the symbol for attributes of grpc_rb_sBatchResult. */
static VALUE sym_send_message; static VALUE sym_send_message;
static VALUE sym_send_metadata; static VALUE sym_send_metadata;
static VALUE sym_send_close; static VALUE sym_send_close;
@ -126,7 +127,7 @@ static VALUE grpc_rb_call_cancel(VALUE self) {
Data_Get_Struct(self, grpc_call, call); Data_Get_Struct(self, grpc_call, call);
err = grpc_call_cancel(call); err = grpc_call_cancel(call);
if (err != GRPC_CALL_OK) { if (err != GRPC_CALL_OK) {
rb_raise(grpc_eCallError, "cancel failed: %s (code=%d)", rb_raise(grpc_rb_eCallError, "cancel failed: %s (code=%d)",
grpc_call_error_detail_of(err), err); grpc_call_error_detail_of(err), err);
} }
@ -148,7 +149,7 @@ static VALUE grpc_rb_call_get_status(VALUE self) {
Saves a status object on the call. */ Saves a status object on the call. */
static VALUE grpc_rb_call_set_status(VALUE self, VALUE status) { static VALUE grpc_rb_call_set_status(VALUE self, VALUE status) {
if (!NIL_P(status) && rb_obj_class(status) != grpc_sStatus) { if (!NIL_P(status) && rb_obj_class(status) != grpc_rb_sStatus) {
rb_raise(rb_eTypeError, "bad status: got:<%s> want: <Struct::Status>", rb_raise(rb_eTypeError, "bad status: got:<%s> want: <Struct::Status>",
rb_obj_classname(status)); rb_obj_classname(status));
return Qnil; return Qnil;
@ -257,7 +258,8 @@ void grpc_rb_md_ary_convert(VALUE md_ary_hash, grpc_metadata_array *md_ary) {
/* Initialize the array, compute it's capacity, then fill it. */ /* Initialize the array, compute it's capacity, then fill it. */
grpc_metadata_array_init(md_ary); grpc_metadata_array_init(md_ary);
md_ary_obj = Data_Wrap_Struct(grpc_cMdAry, GC_NOT_MARKED, GC_DONT_FREE, md_ary); md_ary_obj =
Data_Wrap_Struct(grpc_rb_cMdAry, GC_NOT_MARKED, GC_DONT_FREE, md_ary);
rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_capacity_hash_cb, md_ary_obj); rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_capacity_hash_cb, md_ary_obj);
md_ary->metadata = gpr_malloc(md_ary->capacity * sizeof(grpc_metadata)); md_ary->metadata = gpr_malloc(md_ary->capacity * sizeof(grpc_metadata));
rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_fill_hash_cb, md_ary_obj); rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_fill_hash_cb, md_ary_obj);
@ -470,8 +472,8 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack* st, VALUE ops_hash) {
after the results have run */ after the results have run */
static VALUE grpc_run_batch_stack_build_result(run_batch_stack* st) { static VALUE grpc_run_batch_stack_build_result(run_batch_stack* st) {
size_t i = 0; size_t i = 0;
VALUE result = rb_struct_new(grpc_sBatchResult, Qnil, Qnil, Qnil, Qnil, Qnil, VALUE result = rb_struct_new(grpc_rb_sBatchResult, Qnil, Qnil, Qnil, Qnil,
Qnil, Qnil, Qnil, NULL); Qnil, Qnil, Qnil, Qnil, NULL);
for (i = 0; i < st->op_num; i++) { for (i = 0; i < st->op_num; i++) {
switch(st->ops[i].op) { switch(st->ops[i].op) {
case GRPC_OP_SEND_INITIAL_METADATA: case GRPC_OP_SEND_INITIAL_METADATA:
@ -498,7 +500,7 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack* st) {
rb_struct_aset( rb_struct_aset(
result, result,
sym_status, sym_status,
rb_struct_new(grpc_sStatus, rb_struct_new(grpc_rb_sStatus,
UINT2NUM(st->recv_status), UINT2NUM(st->recv_status),
(st->recv_status_details == NULL (st->recv_status_details == NULL
? Qnil ? Qnil
@ -556,19 +558,20 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
err = grpc_call_start_batch(call, st.ops, st.op_num, ROBJECT(tag)); err = grpc_call_start_batch(call, st.ops, st.op_num, ROBJECT(tag));
if (err != GRPC_CALL_OK) { if (err != GRPC_CALL_OK) {
grpc_run_batch_stack_cleanup(&st); grpc_run_batch_stack_cleanup(&st);
rb_raise(grpc_eCallError, "grpc_call_start_batch failed with %s (code=%d)", rb_raise(grpc_rb_eCallError,
"grpc_call_start_batch failed with %s (code=%d)",
grpc_call_error_detail_of(err), err); grpc_call_error_detail_of(err), err);
return; return;
} }
ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout); ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout);
if (ev == NULL) { if (ev == NULL) {
grpc_run_batch_stack_cleanup(&st); grpc_run_batch_stack_cleanup(&st);
rb_raise(grpc_eOutOfTime, "grpc_call_start_batch timed out"); rb_raise(grpc_rb_eOutOfTime, "grpc_call_start_batch timed out");
return; return;
} }
if (ev->data.op_complete != GRPC_OP_OK) { if (ev->data.op_complete != GRPC_OP_OK) {
grpc_run_batch_stack_cleanup(&st); grpc_run_batch_stack_cleanup(&st);
rb_raise(grpc_eCallError, "start_batch completion failed, (code=%d)", rb_raise(grpc_rb_eCallError, "start_batch completion failed, (code=%d)",
ev->data.op_complete); ev->data.op_complete);
return; return;
} }
@ -579,37 +582,38 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
return result; return result;
} }
/* grpc_cCall is the ruby class that proxies grpc_call. */ /* grpc_rb_cCall is the ruby class that proxies grpc_call. */
VALUE grpc_cCall = Qnil; VALUE grpc_rb_cCall = Qnil;
/* grpc_eCallError is the ruby class of the exception thrown during call /* grpc_rb_eCallError is the ruby class of the exception thrown during call
operations; */ operations; */
VALUE grpc_eCallError = Qnil; VALUE grpc_rb_eCallError = Qnil;
/* grpc_eOutOfTime is the ruby class of the exception thrown to indicate /* grpc_rb_eOutOfTime is the ruby class of the exception thrown to indicate
a timeout. */ a timeout. */
VALUE grpc_eOutOfTime = Qnil; VALUE grpc_rb_eOutOfTime = Qnil;
void Init_grpc_error_codes() { void Init_grpc_error_codes() {
/* Constants representing the error codes of grpc_call_error in grpc.h */ /* Constants representing the error codes of grpc_call_error in grpc.h */
VALUE grpc_mRpcErrors = rb_define_module_under(grpc_mGrpcCore, "RpcErrors"); VALUE grpc_rb_mRpcErrors =
rb_define_const(grpc_mRpcErrors, "OK", UINT2NUM(GRPC_CALL_OK)); rb_define_module_under(grpc_rb_mGrpcCore, "RpcErrors");
rb_define_const(grpc_mRpcErrors, "ERROR", UINT2NUM(GRPC_CALL_ERROR)); rb_define_const(grpc_rb_mRpcErrors, "OK", UINT2NUM(GRPC_CALL_OK));
rb_define_const(grpc_mRpcErrors, "NOT_ON_SERVER", rb_define_const(grpc_rb_mRpcErrors, "ERROR", UINT2NUM(GRPC_CALL_ERROR));
rb_define_const(grpc_rb_mRpcErrors, "NOT_ON_SERVER",
UINT2NUM(GRPC_CALL_ERROR_NOT_ON_SERVER)); UINT2NUM(GRPC_CALL_ERROR_NOT_ON_SERVER));
rb_define_const(grpc_mRpcErrors, "NOT_ON_CLIENT", rb_define_const(grpc_rb_mRpcErrors, "NOT_ON_CLIENT",
UINT2NUM(GRPC_CALL_ERROR_NOT_ON_CLIENT)); UINT2NUM(GRPC_CALL_ERROR_NOT_ON_CLIENT));
rb_define_const(grpc_mRpcErrors, "ALREADY_ACCEPTED", rb_define_const(grpc_rb_mRpcErrors, "ALREADY_ACCEPTED",
UINT2NUM(GRPC_CALL_ERROR_ALREADY_ACCEPTED)); UINT2NUM(GRPC_CALL_ERROR_ALREADY_ACCEPTED));
rb_define_const(grpc_mRpcErrors, "ALREADY_INVOKED", rb_define_const(grpc_rb_mRpcErrors, "ALREADY_INVOKED",
UINT2NUM(GRPC_CALL_ERROR_ALREADY_INVOKED)); UINT2NUM(GRPC_CALL_ERROR_ALREADY_INVOKED));
rb_define_const(grpc_mRpcErrors, "NOT_INVOKED", rb_define_const(grpc_rb_mRpcErrors, "NOT_INVOKED",
UINT2NUM(GRPC_CALL_ERROR_NOT_INVOKED)); UINT2NUM(GRPC_CALL_ERROR_NOT_INVOKED));
rb_define_const(grpc_mRpcErrors, "ALREADY_FINISHED", rb_define_const(grpc_rb_mRpcErrors, "ALREADY_FINISHED",
UINT2NUM(GRPC_CALL_ERROR_ALREADY_FINISHED)); UINT2NUM(GRPC_CALL_ERROR_ALREADY_FINISHED));
rb_define_const(grpc_mRpcErrors, "TOO_MANY_OPERATIONS", rb_define_const(grpc_rb_mRpcErrors, "TOO_MANY_OPERATIONS",
UINT2NUM(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS)); UINT2NUM(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
rb_define_const(grpc_mRpcErrors, "INVALID_FLAGS", rb_define_const(grpc_rb_mRpcErrors, "INVALID_FLAGS",
UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS)); UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS));
/* Add the detail strings to a Hash */ /* Add the detail strings to a Hash */
@ -637,13 +641,13 @@ void Init_grpc_error_codes() {
rb_str_new2("outstanding read or write present")); rb_str_new2("outstanding read or write present"));
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS), rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS),
rb_str_new2("a bad flag was given")); rb_str_new2("a bad flag was given"));
rb_define_const(grpc_mRpcErrors, "ErrorMessages", rb_error_code_details); rb_define_const(grpc_rb_mRpcErrors, "ErrorMessages", rb_error_code_details);
rb_obj_freeze(rb_error_code_details); rb_obj_freeze(rb_error_code_details);
} }
void Init_grpc_op_codes() { void Init_grpc_op_codes() {
/* Constants representing operation type codes in grpc.h */ /* Constants representing operation type codes in grpc.h */
VALUE rb_CallOps = rb_define_module_under(grpc_mGrpcCore, "CallOps"); VALUE rb_CallOps = rb_define_module_under(grpc_rb_mGrpcCore, "CallOps");
rb_define_const(rb_CallOps, "SEND_INITIAL_METADATA", rb_define_const(rb_CallOps, "SEND_INITIAL_METADATA",
UINT2NUM(GRPC_OP_SEND_INITIAL_METADATA)); UINT2NUM(GRPC_OP_SEND_INITIAL_METADATA));
rb_define_const(rb_CallOps, "SEND_MESSAGE", UINT2NUM(GRPC_OP_SEND_MESSAGE)); rb_define_const(rb_CallOps, "SEND_MESSAGE", UINT2NUM(GRPC_OP_SEND_MESSAGE));
@ -663,26 +667,27 @@ void Init_grpc_op_codes() {
void Init_grpc_call() { void Init_grpc_call() {
/* CallError inherits from Exception to signal that it is non-recoverable */ /* CallError inherits from Exception to signal that it is non-recoverable */
grpc_eCallError = grpc_rb_eCallError =
rb_define_class_under(grpc_mGrpcCore, "CallError", rb_eException); rb_define_class_under(grpc_rb_mGrpcCore, "CallError", rb_eException);
grpc_eOutOfTime = grpc_rb_eOutOfTime =
rb_define_class_under(grpc_mGrpcCore, "OutOfTime", rb_eException); rb_define_class_under(grpc_rb_mGrpcCore, "OutOfTime", rb_eException);
grpc_cCall = rb_define_class_under(grpc_mGrpcCore, "Call", rb_cObject); grpc_rb_cCall = rb_define_class_under(grpc_rb_mGrpcCore, "Call", rb_cObject);
grpc_cMdAry = rb_define_class_under(grpc_mGrpcCore, "MetadataArray", grpc_rb_cMdAry = rb_define_class_under(grpc_rb_mGrpcCore, "MetadataArray",
rb_cObject); rb_cObject);
/* Prevent allocation or inialization of the Call class */ /* Prevent allocation or inialization of the Call class */
rb_define_alloc_func(grpc_cCall, grpc_rb_cannot_alloc); rb_define_alloc_func(grpc_rb_cCall, grpc_rb_cannot_alloc);
rb_define_method(grpc_cCall, "initialize", grpc_rb_cannot_init, 0); rb_define_method(grpc_rb_cCall, "initialize", grpc_rb_cannot_init, 0);
rb_define_method(grpc_cCall, "initialize_copy", grpc_rb_cannot_init_copy, 1); rb_define_method(grpc_rb_cCall, "initialize_copy",
grpc_rb_cannot_init_copy, 1);
/* Add ruby analogues of the Call methods. */ /* Add ruby analogues of the Call methods. */
rb_define_method(grpc_cCall, "run_batch", grpc_rb_call_run_batch, 4); rb_define_method(grpc_rb_cCall, "run_batch", grpc_rb_call_run_batch, 4);
rb_define_method(grpc_cCall, "cancel", grpc_rb_call_cancel, 0); rb_define_method(grpc_rb_cCall, "cancel", grpc_rb_call_cancel, 0);
rb_define_method(grpc_cCall, "status", grpc_rb_call_get_status, 0); rb_define_method(grpc_rb_cCall, "status", grpc_rb_call_get_status, 0);
rb_define_method(grpc_cCall, "status=", grpc_rb_call_set_status, 1); rb_define_method(grpc_rb_cCall, "status=", grpc_rb_call_set_status, 1);
rb_define_method(grpc_cCall, "metadata", grpc_rb_call_get_metadata, 0); rb_define_method(grpc_rb_cCall, "metadata", grpc_rb_call_get_metadata, 0);
rb_define_method(grpc_cCall, "metadata=", grpc_rb_call_set_metadata, 1); rb_define_method(grpc_rb_cCall, "metadata=", grpc_rb_call_set_metadata, 1);
/* Ids used to support call attributes */ /* Ids used to support call attributes */
id_metadata = rb_intern("metadata"); id_metadata = rb_intern("metadata");
@ -703,7 +708,7 @@ void Init_grpc_call() {
sym_cancelled = ID2SYM(rb_intern("cancelled")); sym_cancelled = ID2SYM(rb_intern("cancelled"));
/* The Struct used to return the run_batch result. */ /* The Struct used to return the run_batch result. */
grpc_sBatchResult = rb_struct_define( grpc_rb_sBatchResult = rb_struct_define(
"BatchResult", "BatchResult",
"send_message", "send_message",
"send_metadata", "send_metadata",
@ -718,7 +723,7 @@ void Init_grpc_call() {
/* The hash for reference counting calls, to ensure they can't be destroyed /* The hash for reference counting calls, to ensure they can't be destroyed
* more than once */ * more than once */
hash_all_calls = rb_hash_new(); hash_all_calls = rb_hash_new();
rb_define_const(grpc_cCall, "INTERNAL_ALL_CALLs", hash_all_calls); rb_define_const(grpc_rb_cCall, "INTERNAL_ALL_CALLs", hash_all_calls);
Init_grpc_error_codes(); Init_grpc_error_codes();
Init_grpc_op_codes(); Init_grpc_op_codes();
@ -744,5 +749,6 @@ VALUE grpc_rb_wrap_call(grpc_call *c) {
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c), rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c),
UINT2NUM(NUM2UINT(obj) + 1)); UINT2NUM(NUM2UINT(obj) + 1));
} }
return Data_Wrap_Struct(grpc_cCall, GC_NOT_MARKED, grpc_rb_call_destroy, c); return Data_Wrap_Struct(grpc_rb_cCall, GC_NOT_MARKED,
grpc_rb_call_destroy, c);
} }

@ -49,16 +49,16 @@ const char* grpc_call_error_detail_of(grpc_call_error err);
/* Converts a metadata array to a hash. */ /* Converts a metadata array to a hash. */
VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary); VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary);
/* grpc_cCall is the Call class whose instances proxy grpc_call. */ /* grpc_rb_cCall is the Call class whose instances proxy grpc_call. */
extern VALUE grpc_cCall; extern VALUE grpc_rb_cCall;
/* grpc_eCallError is the ruby class of the exception thrown during call /* grpc_rb_eCallError is the ruby class of the exception thrown during call
operations. */ operations. */
extern VALUE grpc_eCallError; extern VALUE grpc_rb_eCallError;
/* grpc_eOutOfTime is the ruby class of the exception thrown to indicate /* grpc_rb_eOutOfTime is the ruby class of the exception thrown to indicate
a timeout. */ a timeout. */
extern VALUE grpc_eOutOfTime; extern VALUE grpc_rb_eOutOfTime;
/* Initializes the Call class. */ /* Initializes the Call class. */
void Init_grpc_call(); void Init_grpc_call();

@ -60,7 +60,7 @@ static ID id_cqueue;
/* Used during the conversion of a hash to channel args during channel setup */ /* Used during the conversion of a hash to channel args during channel setup */
static VALUE grpc_cChannelArgs; static VALUE grpc_rb_cChannelArgs;
/* grpc_rb_channel wraps a grpc_channel. It provides a peer ruby object, /* grpc_rb_channel wraps a grpc_channel. It provides a peer ruby object,
* 'mark' to minimize copying when a channel is created from ruby. */ * 'mark' to minimize copying when a channel is created from ruby. */
@ -170,7 +170,7 @@ static VALUE grpc_rb_channel_init_copy(VALUE copy, VALUE orig) {
/* Raise an error if orig is not a channel object or a subclass. */ /* Raise an error if orig is not a channel object or a subclass. */
if (TYPE(orig) != T_DATA || if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_channel_free) { RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_channel_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_cChannel)); rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cChannel));
return Qnil; return Qnil;
} }
@ -240,36 +240,38 @@ static VALUE grpc_rb_channel_destroy(VALUE self) {
return Qnil; return Qnil;
} }
/* grpc_cChannel is the ruby class that proxies grpc_channel. */ /* grpc_rb_cChannel is the ruby class that proxies grpc_channel. */
VALUE grpc_cChannel = Qnil; VALUE grpc_rb_cChannel = Qnil;
void Init_grpc_channel() { void Init_grpc_channel() {
grpc_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject); grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
grpc_cChannel = rb_define_class_under(grpc_mGrpcCore, "Channel", rb_cObject); grpc_rb_cChannel =
rb_define_class_under(grpc_rb_mGrpcCore, "Channel", rb_cObject);
/* Allocates an object managed by the ruby runtime */ /* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(grpc_cChannel, grpc_rb_channel_alloc); rb_define_alloc_func(grpc_rb_cChannel, grpc_rb_channel_alloc);
/* Provides a ruby constructor and support for dup/clone. */ /* Provides a ruby constructor and support for dup/clone. */
rb_define_method(grpc_cChannel, "initialize", grpc_rb_channel_init, -1); rb_define_method(grpc_rb_cChannel, "initialize", grpc_rb_channel_init, -1);
rb_define_method(grpc_cChannel, "initialize_copy", grpc_rb_channel_init_copy, rb_define_method(grpc_rb_cChannel, "initialize_copy",
1); grpc_rb_channel_init_copy, 1);
/* Add ruby analogues of the Channel methods. */ /* Add ruby analogues of the Channel methods. */
rb_define_method(grpc_cChannel, "create_call", grpc_rb_channel_create_call, 4); rb_define_method(grpc_rb_cChannel, "create_call",
rb_define_method(grpc_cChannel, "destroy", grpc_rb_channel_destroy, 0); grpc_rb_channel_create_call, 4);
rb_define_alias(grpc_cChannel, "close", "destroy"); rb_define_method(grpc_rb_cChannel, "destroy", grpc_rb_channel_destroy, 0);
rb_define_alias(grpc_rb_cChannel, "close", "destroy");
id_channel = rb_intern("__channel"); id_channel = rb_intern("__channel");
id_cqueue = rb_intern("__cqueue"); id_cqueue = rb_intern("__cqueue");
id_target = rb_intern("__target"); id_target = rb_intern("__target");
rb_define_const(grpc_cChannel, "SSL_TARGET", rb_define_const(grpc_rb_cChannel, "SSL_TARGET",
ID2SYM(rb_intern(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG))); ID2SYM(rb_intern(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)));
rb_define_const(grpc_cChannel, "ENABLE_CENSUS", rb_define_const(grpc_rb_cChannel, "ENABLE_CENSUS",
ID2SYM(rb_intern(GRPC_ARG_ENABLE_CENSUS))); ID2SYM(rb_intern(GRPC_ARG_ENABLE_CENSUS)));
rb_define_const(grpc_cChannel, "MAX_CONCURRENT_STREAMS", rb_define_const(grpc_rb_cChannel, "MAX_CONCURRENT_STREAMS",
ID2SYM(rb_intern(GRPC_ARG_MAX_CONCURRENT_STREAMS))); ID2SYM(rb_intern(GRPC_ARG_MAX_CONCURRENT_STREAMS)));
rb_define_const(grpc_cChannel, "MAX_MESSAGE_LENGTH", rb_define_const(grpc_rb_cChannel, "MAX_MESSAGE_LENGTH",
ID2SYM(rb_intern(GRPC_ARG_MAX_MESSAGE_LENGTH))); ID2SYM(rb_intern(GRPC_ARG_MAX_MESSAGE_LENGTH)));
} }

@ -37,8 +37,8 @@
#include <ruby.h> #include <ruby.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
/* grpc_cChannel is the Channel class whose instances proxy grpc_channel. */ /* grpc_rb_cChannel is the Channel class whose instances proxy grpc_channel. */
extern VALUE grpc_cChannel; extern VALUE grpc_rb_cChannel;
/* Initializes the Channel class. */ /* Initializes the Channel class. */
void Init_grpc_channel(); void Init_grpc_channel();

@ -109,7 +109,7 @@ typedef struct channel_convert_params {
static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) { static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
ID id_size = rb_intern("size"); ID id_size = rb_intern("size");
VALUE grpc_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject); VALUE grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
channel_convert_params* params = (channel_convert_params*)as_value; channel_convert_params* params = (channel_convert_params*)as_value;
size_t num_args = 0; size_t num_args = 0;
@ -126,7 +126,7 @@ static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
MEMZERO(params->dst->args, grpc_arg, num_args); MEMZERO(params->dst->args, grpc_arg, num_args);
rb_hash_foreach(params->src_hash, rb_hash_foreach(params->src_hash,
grpc_rb_channel_create_in_process_add_args_hash_cb, grpc_rb_channel_create_in_process_add_args_hash_cb,
Data_Wrap_Struct(grpc_cChannelArgs, GC_NOT_MARKED, Data_Wrap_Struct(grpc_rb_cChannelArgs, GC_NOT_MARKED,
GC_DONT_FREE, params->dst)); GC_DONT_FREE, params->dst));
/* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb /* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
* decrements it during has processing */ * decrements it during has processing */

@ -166,25 +166,27 @@ grpc_event* grpc_rb_completion_queue_pluck_event(VALUE self, VALUE tag,
return next_call.event; return next_call.event;
} }
/* grpc_cCompletionQueue is the ruby class that proxies grpc_completion_queue. */ /* grpc_rb_cCompletionQueue is the ruby class that proxies
VALUE grpc_cCompletionQueue = Qnil; * grpc_completion_queue. */
VALUE grpc_rb_cCompletionQueue = Qnil;
void Init_grpc_completion_queue() { void Init_grpc_completion_queue() {
grpc_cCompletionQueue = grpc_rb_cCompletionQueue =
rb_define_class_under(grpc_mGrpcCore, "CompletionQueue", rb_cObject); rb_define_class_under(grpc_rb_mGrpcCore, "CompletionQueue", rb_cObject);
/* constructor: uses an alloc func without an initializer. Using a simple /* constructor: uses an alloc func without an initializer. Using a simple
alloc func works here as the grpc header does not specify any args for alloc func works here as the grpc header does not specify any args for
this func, so no separate initialization step is necessary. */ this func, so no separate initialization step is necessary. */
rb_define_alloc_func(grpc_cCompletionQueue, grpc_rb_completion_queue_alloc); rb_define_alloc_func(grpc_rb_cCompletionQueue,
grpc_rb_completion_queue_alloc);
/* Add the next method that waits for the next event. */ /* Add the next method that waits for the next event. */
rb_define_method(grpc_cCompletionQueue, "next", grpc_rb_completion_queue_next, rb_define_method(grpc_rb_cCompletionQueue, "next",
1); grpc_rb_completion_queue_next, 1);
/* Add the pluck method that waits for the next event of given tag */ /* Add the pluck method that waits for the next event of given tag */
rb_define_method(grpc_cCompletionQueue, "pluck", grpc_rb_completion_queue_pluck, rb_define_method(grpc_rb_cCompletionQueue, "pluck",
2); grpc_rb_completion_queue_pluck, 2);
} }
/* Gets the wrapped completion queue from the ruby wrapper */ /* Gets the wrapped completion queue from the ruby wrapper */

@ -48,9 +48,9 @@ grpc_completion_queue *grpc_rb_get_wrapped_completion_queue(VALUE v);
grpc_event* grpc_rb_completion_queue_pluck_event(VALUE cqueue, VALUE tag, grpc_event* grpc_rb_completion_queue_pluck_event(VALUE cqueue, VALUE tag,
VALUE timeout); VALUE timeout);
/* grpc_cCompletionQueue is the CompletionQueue class whose instances proxy /* grpc_rb_cCompletionQueue is the CompletionQueue class whose instances proxy
grpc_completion_queue. */ grpc_completion_queue. */
extern VALUE grpc_cCompletionQueue; extern VALUE grpc_rb_cCompletionQueue;
/* Initializes the CompletionQueue class. */ /* Initializes the CompletionQueue class. */
void Init_grpc_completion_queue(); void Init_grpc_completion_queue();

@ -107,7 +107,7 @@ static VALUE grpc_rb_credentials_init_copy(VALUE copy, VALUE orig) {
/* Raise an error if orig is not a credentials object or a subclass. */ /* Raise an error if orig is not a credentials object or a subclass. */
if (TYPE(orig) != T_DATA || if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_credentials_free) { RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_credentials_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_cCredentials)); rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cCredentials));
} }
Data_Get_Struct(orig, grpc_rb_credentials, orig_cred); Data_Get_Struct(orig, grpc_rb_credentials, orig_cred);
@ -178,7 +178,7 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) {
} }
wrapper->mark = Qnil; wrapper->mark = Qnil;
return Data_Wrap_Struct(grpc_cCredentials, grpc_rb_credentials_mark, return Data_Wrap_Struct(grpc_rb_cCredentials, grpc_rb_credentials_mark,
grpc_rb_credentials_free, wrapper); grpc_rb_credentials_free, wrapper);
} }
@ -242,30 +242,31 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
return self; return self;
} }
/* grpc_cCredentials is the ruby class that proxies grpc_credentials. */ /* grpc_rb_cCredentials is the ruby class that proxies grpc_credentials. */
VALUE grpc_cCredentials = Qnil; VALUE grpc_rb_cCredentials = Qnil;
void Init_grpc_credentials() { void Init_grpc_credentials() {
grpc_cCredentials = grpc_rb_cCredentials =
rb_define_class_under(grpc_mGrpcCore, "Credentials", rb_cObject); rb_define_class_under(grpc_rb_mGrpcCore, "Credentials", rb_cObject);
/* Allocates an object managed by the ruby runtime */ /* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(grpc_cCredentials, grpc_rb_credentials_alloc); rb_define_alloc_func(grpc_rb_cCredentials, grpc_rb_credentials_alloc);
/* Provides a ruby constructor and support for dup/clone. */ /* Provides a ruby constructor and support for dup/clone. */
rb_define_method(grpc_cCredentials, "initialize", grpc_rb_credentials_init, -1); rb_define_method(grpc_rb_cCredentials, "initialize",
rb_define_method(grpc_cCredentials, "initialize_copy", grpc_rb_credentials_init, -1);
rb_define_method(grpc_rb_cCredentials, "initialize_copy",
grpc_rb_credentials_init_copy, 1); grpc_rb_credentials_init_copy, 1);
/* Provide static funcs that create new special instances. */ /* Provide static funcs that create new special instances. */
rb_define_singleton_method(grpc_cCredentials, "default", rb_define_singleton_method(grpc_rb_cCredentials, "default",
grpc_rb_default_credentials_create, 0); grpc_rb_default_credentials_create, 0);
rb_define_singleton_method(grpc_cCredentials, "compute_engine", rb_define_singleton_method(grpc_rb_cCredentials, "compute_engine",
grpc_rb_compute_engine_credentials_create, 0); grpc_rb_compute_engine_credentials_create, 0);
/* Provide other methods. */ /* Provide other methods. */
rb_define_method(grpc_cCredentials, "compose", rb_define_method(grpc_rb_cCredentials, "compose",
grpc_rb_composite_credentials_create, 1); grpc_rb_composite_credentials_create, 1);
id_pem_cert_chain = rb_intern("__pem_cert_chain"); id_pem_cert_chain = rb_intern("__pem_cert_chain");

@ -37,9 +37,9 @@
#include <ruby.h> #include <ruby.h>
#include <grpc/grpc_security.h> #include <grpc/grpc_security.h>
/* grpc_cCredentials is the ruby class whose instances proxy /* grpc_rb_cCredentials is the ruby class whose instances proxy
grpc_credentials. */ grpc_credentials. */
extern VALUE grpc_cCredentials; extern VALUE grpc_rb_cCredentials;
/* Initializes the ruby Credentials class. */ /* Initializes the ruby Credentials class. */
void Init_grpc_credentials(); void Init_grpc_credentials();

@ -50,7 +50,7 @@
const RUBY_DATA_FUNC GC_NOT_MARKED = NULL; const RUBY_DATA_FUNC GC_NOT_MARKED = NULL;
const RUBY_DATA_FUNC GC_DONT_FREE = NULL; const RUBY_DATA_FUNC GC_DONT_FREE = NULL;
VALUE grpc_cTimeVal = Qnil; VALUE grpc_rb_cTimeVal = Qnil;
/* Alloc func that blocks allocation of a given object by raising an /* Alloc func that blocks allocation of a given object by raising an
* exception. */ * exception. */
@ -96,7 +96,7 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
switch (TYPE(time)) { switch (TYPE(time)) {
case T_DATA: case T_DATA:
if (CLASS_OF(time) == grpc_cTimeVal) { if (CLASS_OF(time) == grpc_rb_cTimeVal) {
Data_Get_Struct(time, gpr_timespec, time_const); Data_Get_Struct(time, gpr_timespec, time_const);
t = *time_const; t = *time_const;
} else if (CLASS_OF(time) == rb_cTime) { } else if (CLASS_OF(time) == rb_cTime) {
@ -152,35 +152,41 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
void Init_grpc_status_codes() { void Init_grpc_status_codes() {
/* Constants representing the status codes or grpc_status_code in status.h */ /* Constants representing the status codes or grpc_status_code in status.h */
VALUE grpc_mStatusCodes = VALUE grpc_rb_mStatusCodes =
rb_define_module_under(grpc_mGrpcCore, "StatusCodes"); rb_define_module_under(grpc_rb_mGrpcCore, "StatusCodes");
rb_define_const(grpc_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK)); rb_define_const(grpc_rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK));
rb_define_const(grpc_mStatusCodes, "CANCELLED", INT2NUM(GRPC_STATUS_CANCELLED)); rb_define_const(grpc_rb_mStatusCodes, "CANCELLED",
rb_define_const(grpc_mStatusCodes, "UNKNOWN", INT2NUM(GRPC_STATUS_UNKNOWN)); INT2NUM(GRPC_STATUS_CANCELLED));
rb_define_const(grpc_mStatusCodes, "INVALID_ARGUMENT", rb_define_const(grpc_rb_mStatusCodes, "UNKNOWN",
INT2NUM(GRPC_STATUS_UNKNOWN));
rb_define_const(grpc_rb_mStatusCodes, "INVALID_ARGUMENT",
INT2NUM(GRPC_STATUS_INVALID_ARGUMENT)); INT2NUM(GRPC_STATUS_INVALID_ARGUMENT));
rb_define_const(grpc_mStatusCodes, "DEADLINE_EXCEEDED", rb_define_const(grpc_rb_mStatusCodes, "DEADLINE_EXCEEDED",
INT2NUM(GRPC_STATUS_DEADLINE_EXCEEDED)); INT2NUM(GRPC_STATUS_DEADLINE_EXCEEDED));
rb_define_const(grpc_mStatusCodes, "NOT_FOUND", INT2NUM(GRPC_STATUS_NOT_FOUND)); rb_define_const(grpc_rb_mStatusCodes, "NOT_FOUND",
rb_define_const(grpc_mStatusCodes, "ALREADY_EXISTS", INT2NUM(GRPC_STATUS_NOT_FOUND));
rb_define_const(grpc_rb_mStatusCodes, "ALREADY_EXISTS",
INT2NUM(GRPC_STATUS_ALREADY_EXISTS)); INT2NUM(GRPC_STATUS_ALREADY_EXISTS));
rb_define_const(grpc_mStatusCodes, "PERMISSION_DENIED", rb_define_const(grpc_rb_mStatusCodes, "PERMISSION_DENIED",
INT2NUM(GRPC_STATUS_PERMISSION_DENIED)); INT2NUM(GRPC_STATUS_PERMISSION_DENIED));
rb_define_const(grpc_mStatusCodes, "UNAUTHENTICATED", rb_define_const(grpc_rb_mStatusCodes, "UNAUTHENTICATED",
INT2NUM(GRPC_STATUS_UNAUTHENTICATED)); INT2NUM(GRPC_STATUS_UNAUTHENTICATED));
rb_define_const(grpc_mStatusCodes, "RESOURCE_EXHAUSTED", rb_define_const(grpc_rb_mStatusCodes, "RESOURCE_EXHAUSTED",
INT2NUM(GRPC_STATUS_RESOURCE_EXHAUSTED)); INT2NUM(GRPC_STATUS_RESOURCE_EXHAUSTED));
rb_define_const(grpc_mStatusCodes, "FAILED_PRECONDITION", rb_define_const(grpc_rb_mStatusCodes, "FAILED_PRECONDITION",
INT2NUM(GRPC_STATUS_FAILED_PRECONDITION)); INT2NUM(GRPC_STATUS_FAILED_PRECONDITION));
rb_define_const(grpc_mStatusCodes, "ABORTED", INT2NUM(GRPC_STATUS_ABORTED)); rb_define_const(grpc_rb_mStatusCodes, "ABORTED",
rb_define_const(grpc_mStatusCodes, "OUT_OF_RANGE", INT2NUM(GRPC_STATUS_ABORTED));
rb_define_const(grpc_rb_mStatusCodes, "OUT_OF_RANGE",
INT2NUM(GRPC_STATUS_OUT_OF_RANGE)); INT2NUM(GRPC_STATUS_OUT_OF_RANGE));
rb_define_const(grpc_mStatusCodes, "UNIMPLEMENTED", rb_define_const(grpc_rb_mStatusCodes, "UNIMPLEMENTED",
INT2NUM(GRPC_STATUS_UNIMPLEMENTED)); INT2NUM(GRPC_STATUS_UNIMPLEMENTED));
rb_define_const(grpc_mStatusCodes, "INTERNAL", INT2NUM(GRPC_STATUS_INTERNAL)); rb_define_const(grpc_rb_mStatusCodes, "INTERNAL",
rb_define_const(grpc_mStatusCodes, "UNAVAILABLE", INT2NUM(GRPC_STATUS_INTERNAL));
rb_define_const(grpc_rb_mStatusCodes, "UNAVAILABLE",
INT2NUM(GRPC_STATUS_UNAVAILABLE)); INT2NUM(GRPC_STATUS_UNAVAILABLE));
rb_define_const(grpc_mStatusCodes, "DATA_LOSS", INT2NUM(GRPC_STATUS_DATA_LOSS)); rb_define_const(grpc_rb_mStatusCodes, "DATA_LOSS",
INT2NUM(GRPC_STATUS_DATA_LOSS));
} }
/* id_at is the constructor method of the ruby standard Time class. */ /* id_at is the constructor method of the ruby standard Time class. */
@ -212,22 +218,25 @@ VALUE grpc_rb_time_val_to_s(VALUE self) {
/* Adds a module with constants that map to gpr's static timeval structs. */ /* Adds a module with constants that map to gpr's static timeval structs. */
void Init_grpc_time_consts() { void Init_grpc_time_consts() {
VALUE grpc_mTimeConsts = VALUE grpc_rb_mTimeConsts =
rb_define_module_under(grpc_mGrpcCore, "TimeConsts"); rb_define_module_under(grpc_rb_mGrpcCore, "TimeConsts");
grpc_cTimeVal = grpc_rb_cTimeVal =
rb_define_class_under(grpc_mGrpcCore, "TimeSpec", rb_cObject); rb_define_class_under(grpc_rb_mGrpcCore, "TimeSpec", rb_cObject);
rb_define_const(grpc_mTimeConsts, "ZERO", rb_define_const(grpc_rb_mTimeConsts, "ZERO",
Data_Wrap_Struct(grpc_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE, Data_Wrap_Struct(grpc_rb_cTimeVal,
GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_time_0)); (void *)&gpr_time_0));
rb_define_const(grpc_mTimeConsts, "INFINITE_FUTURE", rb_define_const(grpc_rb_mTimeConsts, "INFINITE_FUTURE",
Data_Wrap_Struct(grpc_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE, Data_Wrap_Struct(grpc_rb_cTimeVal,
GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_inf_future)); (void *)&gpr_inf_future));
rb_define_const(grpc_mTimeConsts, "INFINITE_PAST", rb_define_const(grpc_rb_mTimeConsts, "INFINITE_PAST",
Data_Wrap_Struct(grpc_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE, Data_Wrap_Struct(grpc_rb_cTimeVal,
GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_inf_past)); (void *)&gpr_inf_past));
rb_define_method(grpc_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0); rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0);
rb_define_method(grpc_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0); rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0);
rb_define_method(grpc_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0); rb_define_method(grpc_rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0);
id_at = rb_intern("at"); id_at = rb_intern("at");
id_inspect = rb_intern("inspect"); id_inspect = rb_intern("inspect");
id_to_s = rb_intern("to_s"); id_to_s = rb_intern("to_s");
@ -239,23 +248,25 @@ void grpc_rb_shutdown(void *vm) { grpc_shutdown(); }
/* Initialize the GRPC module structs */ /* Initialize the GRPC module structs */
/* grpc_sNewServerRpc is the struct that holds new server rpc details. */ /* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
VALUE grpc_sNewServerRpc = Qnil; VALUE grpc_rb_sNewServerRpc = Qnil;
/* grpc_sStatus is the struct that holds status details. */ /* grpc_rb_sStatus is the struct that holds status details. */
VALUE grpc_sStatus = Qnil; VALUE grpc_rb_sStatus = Qnil;
/* Initialize the GRPC module. */ /* Initialize the GRPC module. */
VALUE grpc_mGRPC = Qnil; VALUE grpc_rb_mGRPC = Qnil;
VALUE grpc_mGrpcCore = Qnil; VALUE grpc_rb_mGrpcCore = Qnil;
void Init_grpc() { void Init_grpc() {
grpc_init(); grpc_init();
ruby_vm_at_exit(grpc_rb_shutdown); ruby_vm_at_exit(grpc_rb_shutdown);
grpc_mGRPC = rb_define_module("GRPC"); grpc_rb_mGRPC = rb_define_module("GRPC");
grpc_mGrpcCore = rb_define_module_under(grpc_mGRPC, "Core"); grpc_rb_mGrpcCore = rb_define_module_under(grpc_rb_mGRPC, "Core");
grpc_sNewServerRpc = rb_struct_define("NewServerRpc", "method", "host", grpc_rb_sNewServerRpc =
"deadline", "metadata", "call", NULL); rb_struct_define("NewServerRpc", "method", "host",
grpc_sStatus = rb_struct_define("Status", "code", "details", "metadata", NULL); "deadline", "metadata", "call", NULL);
grpc_rb_sStatus =
rb_struct_define("Status", "code", "details", "metadata", NULL);
sym_code = ID2SYM(rb_intern("code")); sym_code = ID2SYM(rb_intern("code"));
sym_details = ID2SYM(rb_intern("details")); sym_details = ID2SYM(rb_intern("details"));
sym_metadata = ID2SYM(rb_intern("metadata")); sym_metadata = ID2SYM(rb_intern("metadata"));

@ -38,25 +38,25 @@
#include <ruby.h> #include <ruby.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
/* grpc_mGrpcCore is the module containing the ruby wrapper GRPC classes. */ /* grpc_rb_mGrpcCore is the module containing the ruby wrapper GRPC classes. */
extern VALUE grpc_mGrpcCore; extern VALUE grpc_rb_mGrpcCore;
/* Class used to wrap timeval structs. */ /* Class used to wrap timeval structs. */
extern VALUE grpc_cTimeVal; extern VALUE grpc_rb_cTimeVal;
/* grpc_sNewServerRpc is the struct that holds new server rpc details. */ /* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
extern VALUE grpc_sNewServerRpc; extern VALUE grpc_rb_sNewServerRpc;
/* grpc_sStruct is the struct that holds status details. */ /* grpc_rb_sStruct is the struct that holds status details. */
extern VALUE grpc_sStatus; extern VALUE grpc_rb_sStatus;
/* sym_code is the symbol for the code attribute of grpc_sStatus. */ /* sym_code is the symbol for the code attribute of grpc_rb_sStatus. */
VALUE sym_code; VALUE sym_code;
/* sym_details is the symbol for the details attribute of grpc_sStatus. */ /* sym_details is the symbol for the details attribute of grpc_rb_sStatus. */
VALUE sym_details; VALUE sym_details;
/* sym_metadata is the symbol for the metadata attribute of grpc_sStatus. */ /* sym_metadata is the symbol for the metadata attribute of grpc_rb_sStatus. */
VALUE sym_metadata; VALUE sym_metadata;
/* GC_NOT_MARKED is used in calls to Data_Wrap_Struct to indicate that the /* GC_NOT_MARKED is used in calls to Data_Wrap_Struct to indicate that the

@ -43,8 +43,8 @@
#include "rb_server_credentials.h" #include "rb_server_credentials.h"
#include "rb_grpc.h" #include "rb_grpc.h"
/* grpc_cServer is the ruby class that proxies grpc_server. */ /* grpc_rb_cServer is the ruby class that proxies grpc_server. */
VALUE grpc_cServer = Qnil; VALUE grpc_rb_cServer = Qnil;
/* id_at is the constructor method of the ruby standard Time class. */ /* id_at is the constructor method of the ruby standard Time class. */
static ID id_at; static ID id_at;
@ -143,7 +143,7 @@ static VALUE grpc_rb_server_init_copy(VALUE copy, VALUE orig) {
/* Raise an error if orig is not a server object or a subclass. */ /* Raise an error if orig is not a server object or a subclass. */
if (TYPE(orig) != T_DATA || if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_free) { RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_cServer)); rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cServer));
} }
Data_Get_Struct(orig, grpc_rb_server, orig_srv); Data_Get_Struct(orig, grpc_rb_server, orig_srv);
@ -208,7 +208,8 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
ROBJECT(tag_new)); ROBJECT(tag_new));
if (err != GRPC_CALL_OK) { if (err != GRPC_CALL_OK) {
grpc_request_call_stack_cleanup(&st); grpc_request_call_stack_cleanup(&st);
rb_raise(grpc_eCallError, "grpc_server_request_call failed: %s (code=%d)", rb_raise(grpc_rb_eCallError,
"grpc_server_request_call failed: %s (code=%d)",
grpc_call_error_detail_of(err), err); grpc_call_error_detail_of(err), err);
return Qnil; return Qnil;
} }
@ -220,14 +221,14 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
if (ev->data.op_complete != GRPC_OP_OK) { if (ev->data.op_complete != GRPC_OP_OK) {
grpc_request_call_stack_cleanup(&st); grpc_request_call_stack_cleanup(&st);
grpc_event_finish(ev); grpc_event_finish(ev);
rb_raise(grpc_eCallError, "request_call completion failed: (code=%d)", rb_raise(grpc_rb_eCallError, "request_call completion failed: (code=%d)",
ev->data.op_complete); ev->data.op_complete);
return Qnil; return Qnil;
} }
/* build the NewServerRpc struct result */ /* build the NewServerRpc struct result */
result = rb_struct_new( result = rb_struct_new(
grpc_sNewServerRpc, grpc_rb_sNewServerRpc,
rb_str_new2(st.details.method), rb_str_new2(st.details.method),
rb_str_new2(st.details.host), rb_str_new2(st.details.host),
rb_funcall(rb_cTime, id_at, 2, INT2NUM(st.details.deadline.tv_sec), rb_funcall(rb_cTime, id_at, 2, INT2NUM(st.details.deadline.tv_sec),
@ -313,21 +314,25 @@ static VALUE grpc_rb_server_add_http2_port(int argc, VALUE *argv, VALUE self) {
} }
void Init_grpc_server() { void Init_grpc_server() {
grpc_cServer = rb_define_class_under(grpc_mGrpcCore, "Server", rb_cObject); grpc_rb_cServer =
rb_define_class_under(grpc_rb_mGrpcCore, "Server", rb_cObject);
/* Allocates an object managed by the ruby runtime */ /* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(grpc_cServer, grpc_rb_server_alloc); rb_define_alloc_func(grpc_rb_cServer, grpc_rb_server_alloc);
/* Provides a ruby constructor and support for dup/clone. */ /* Provides a ruby constructor and support for dup/clone. */
rb_define_method(grpc_cServer, "initialize", grpc_rb_server_init, 2); rb_define_method(grpc_rb_cServer, "initialize", grpc_rb_server_init, 2);
rb_define_method(grpc_cServer, "initialize_copy", grpc_rb_server_init_copy, 1); rb_define_method(grpc_rb_cServer, "initialize_copy",
grpc_rb_server_init_copy, 1);
/* Add the server methods. */ /* Add the server methods. */
rb_define_method(grpc_cServer, "request_call", grpc_rb_server_request_call, 3); rb_define_method(grpc_rb_cServer, "request_call",
rb_define_method(grpc_cServer, "start", grpc_rb_server_start, 0); grpc_rb_server_request_call, 3);
rb_define_method(grpc_cServer, "destroy", grpc_rb_server_destroy, 0); rb_define_method(grpc_rb_cServer, "start", grpc_rb_server_start, 0);
rb_define_alias(grpc_cServer, "close", "destroy"); rb_define_method(grpc_rb_cServer, "destroy", grpc_rb_server_destroy, 0);
rb_define_method(grpc_cServer, "add_http2_port", grpc_rb_server_add_http2_port, rb_define_alias(grpc_rb_cServer, "close", "destroy");
rb_define_method(grpc_rb_cServer, "add_http2_port",
grpc_rb_server_add_http2_port,
-1); -1);
id_at = rb_intern("at"); id_at = rb_intern("at");
} }

@ -37,9 +37,9 @@
#include <ruby.h> #include <ruby.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
/* grpc_cServer is the Server class whose instances proxy /* grpc_rb_cServer is the Server class whose instances proxy
grpc_byte_buffer. */ grpc_byte_buffer. */
extern VALUE grpc_cServer; extern VALUE grpc_rb_cServer;
/* Initializes the Server class. */ /* Initializes the Server class. */
void Init_grpc_server(); void Init_grpc_server();

@ -109,7 +109,7 @@ static VALUE grpc_rb_server_credentials_init_copy(VALUE copy, VALUE orig) {
if (TYPE(orig) != T_DATA || if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_credentials_free) { RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_credentials_free) {
rb_raise(rb_eTypeError, "not a %s", rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(grpc_cServerCredentials)); rb_obj_classname(grpc_rb_cServerCredentials));
} }
Data_Get_Struct(orig, grpc_rb_server_credentials, orig_ch); Data_Get_Struct(orig, grpc_rb_server_credentials, orig_ch);
@ -180,21 +180,22 @@ static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
return self; return self;
} }
/* grpc_cServerCredentials is the ruby class that proxies /* grpc_rb_cServerCredentials is the ruby class that proxies
grpc_server_credentials. */ grpc_server_credentials. */
VALUE grpc_cServerCredentials = Qnil; VALUE grpc_rb_cServerCredentials = Qnil;
void Init_grpc_server_credentials() { void Init_grpc_server_credentials() {
grpc_cServerCredentials = grpc_rb_cServerCredentials =
rb_define_class_under(grpc_mGrpcCore, "ServerCredentials", rb_cObject); rb_define_class_under(grpc_rb_mGrpcCore, "ServerCredentials", rb_cObject);
/* Allocates an object managed by the ruby runtime */ /* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(grpc_cServerCredentials, grpc_rb_server_credentials_alloc); rb_define_alloc_func(grpc_rb_cServerCredentials,
grpc_rb_server_credentials_alloc);
/* Provides a ruby constructor and support for dup/clone. */ /* Provides a ruby constructor and support for dup/clone. */
rb_define_method(grpc_cServerCredentials, "initialize", rb_define_method(grpc_rb_cServerCredentials, "initialize",
grpc_rb_server_credentials_init, 3); grpc_rb_server_credentials_init, 3);
rb_define_method(grpc_cServerCredentials, "initialize_copy", rb_define_method(grpc_rb_cServerCredentials, "initialize_copy",
grpc_rb_server_credentials_init_copy, 1); grpc_rb_server_credentials_init_copy, 1);
id_pem_cert_chain = rb_intern("__pem_cert_chain"); id_pem_cert_chain = rb_intern("__pem_cert_chain");

@ -37,9 +37,9 @@
#include <ruby.h> #include <ruby.h>
#include <grpc/grpc_security.h> #include <grpc/grpc_security.h>
/* grpc_cServerCredentials is the ruby class whose instances proxy /* grpc_rb_cServerCredentials is the ruby class whose instances proxy
grpc_server_credentials. */ grpc_server_credentials. */
extern VALUE grpc_cServerCredentials; extern VALUE grpc_rb_cServerCredentials;
/* Initializes the ruby ServerCredentials class. */ /* Initializes the ruby ServerCredentials class. */
void Init_grpc_server_credentials(); void Init_grpc_server_credentials();

Loading…
Cancel
Save