Merge pull request #1245 from yugui/fix/prefix

Avoid identifiers reserved by Ruby
pull/1232/head
Tim Emiola 10 years ago
commit 9a70c1aaf3
  1. 128
      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_grpc.h"
/* rb_sBatchResult is struct class used to hold the results of a batch call */
static VALUE rb_sBatchResult;
/* grpc_rb_sBatchResult is struct class used to hold the results of a batch
* call. */
static VALUE grpc_rb_sBatchResult;
/* rb_cMdAry is the MetadataArray class whose instances proxy
/* grpc_rb_cMdAry is the MetadataArray class whose instances proxy
* grpc_metadata_array. */
static VALUE rb_cMdAry;
static VALUE grpc_rb_cMdAry;
/* id_cq is the name of the hidden ivar that preserves a reference to a
* completion queue */
@ -70,7 +71,7 @@ static ID id_metadata;
* received by the call and subsequently saved on it. */
static ID id_status;
/* sym_* are the symbol for attributes of rb_sBatchResult. */
/* sym_* are the symbol for attributes of grpc_rb_sBatchResult. */
static VALUE sym_send_message;
static VALUE sym_send_metadata;
static VALUE sym_send_close;
@ -126,7 +127,7 @@ static VALUE grpc_rb_call_cancel(VALUE self) {
Data_Get_Struct(self, grpc_call, call);
err = grpc_call_cancel(call);
if (err != GRPC_CALL_OK) {
rb_raise(rb_eCallError, "cancel failed: %s (code=%d)",
rb_raise(grpc_rb_eCallError, "cancel failed: %s (code=%d)",
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. */
static VALUE grpc_rb_call_set_status(VALUE self, VALUE status) {
if (!NIL_P(status) && rb_obj_class(status) != rb_sStatus) {
if (!NIL_P(status) && rb_obj_class(status) != grpc_rb_sStatus) {
rb_raise(rb_eTypeError, "bad status: got:<%s> want: <Struct::Status>",
rb_obj_classname(status));
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. */
grpc_metadata_array_init(md_ary);
md_ary_obj = Data_Wrap_Struct(rb_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);
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);
@ -470,8 +472,8 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack* st, VALUE ops_hash) {
after the results have run */
static VALUE grpc_run_batch_stack_build_result(run_batch_stack* st) {
size_t i = 0;
VALUE result = rb_struct_new(rb_sBatchResult, Qnil, Qnil, Qnil, Qnil, Qnil,
Qnil, Qnil, Qnil, NULL);
VALUE result = rb_struct_new(grpc_rb_sBatchResult, Qnil, Qnil, Qnil, Qnil,
Qnil, Qnil, Qnil, Qnil, NULL);
for (i = 0; i < st->op_num; i++) {
switch(st->ops[i].op) {
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(
result,
sym_status,
rb_struct_new(rb_sStatus,
rb_struct_new(grpc_rb_sStatus,
UINT2NUM(st->recv_status),
(st->recv_status_details == NULL
? 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));
if (err != GRPC_CALL_OK) {
grpc_run_batch_stack_cleanup(&st);
rb_raise(rb_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);
return;
}
ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout);
if (ev == NULL) {
grpc_run_batch_stack_cleanup(&st);
rb_raise(rb_eOutOfTime, "grpc_call_start_batch timed out");
rb_raise(grpc_rb_eOutOfTime, "grpc_call_start_batch timed out");
return;
}
if (ev->data.op_complete != GRPC_OP_OK) {
grpc_run_batch_stack_cleanup(&st);
rb_raise(rb_eCallError, "start_batch completion failed, (code=%d)",
rb_raise(grpc_rb_eCallError, "start_batch completion failed, (code=%d)",
ev->data.op_complete);
return;
}
@ -579,37 +582,38 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
return result;
}
/* rb_cCall is the ruby class that proxies grpc_call. */
VALUE rb_cCall = Qnil;
/* grpc_rb_cCall is the ruby class that proxies grpc_call. */
VALUE grpc_rb_cCall = Qnil;
/* rb_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; */
VALUE rb_eCallError = Qnil;
VALUE grpc_rb_eCallError = Qnil;
/* rb_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. */
VALUE rb_eOutOfTime = Qnil;
VALUE grpc_rb_eOutOfTime = Qnil;
void Init_grpc_error_codes() {
/* Constants representing the error codes of grpc_call_error in grpc.h */
VALUE rb_RpcErrors = rb_define_module_under(rb_mGrpcCore, "RpcErrors");
rb_define_const(rb_RpcErrors, "OK", UINT2NUM(GRPC_CALL_OK));
rb_define_const(rb_RpcErrors, "ERROR", UINT2NUM(GRPC_CALL_ERROR));
rb_define_const(rb_RpcErrors, "NOT_ON_SERVER",
VALUE grpc_rb_mRpcErrors =
rb_define_module_under(grpc_rb_mGrpcCore, "RpcErrors");
rb_define_const(grpc_rb_mRpcErrors, "OK", UINT2NUM(GRPC_CALL_OK));
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));
rb_define_const(rb_RpcErrors, "NOT_ON_CLIENT",
rb_define_const(grpc_rb_mRpcErrors, "NOT_ON_CLIENT",
UINT2NUM(GRPC_CALL_ERROR_NOT_ON_CLIENT));
rb_define_const(rb_RpcErrors, "ALREADY_ACCEPTED",
rb_define_const(grpc_rb_mRpcErrors, "ALREADY_ACCEPTED",
UINT2NUM(GRPC_CALL_ERROR_ALREADY_ACCEPTED));
rb_define_const(rb_RpcErrors, "ALREADY_INVOKED",
rb_define_const(grpc_rb_mRpcErrors, "ALREADY_INVOKED",
UINT2NUM(GRPC_CALL_ERROR_ALREADY_INVOKED));
rb_define_const(rb_RpcErrors, "NOT_INVOKED",
rb_define_const(grpc_rb_mRpcErrors, "NOT_INVOKED",
UINT2NUM(GRPC_CALL_ERROR_NOT_INVOKED));
rb_define_const(rb_RpcErrors, "ALREADY_FINISHED",
rb_define_const(grpc_rb_mRpcErrors, "ALREADY_FINISHED",
UINT2NUM(GRPC_CALL_ERROR_ALREADY_FINISHED));
rb_define_const(rb_RpcErrors, "TOO_MANY_OPERATIONS",
rb_define_const(grpc_rb_mRpcErrors, "TOO_MANY_OPERATIONS",
UINT2NUM(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
rb_define_const(rb_RpcErrors, "INVALID_FLAGS",
rb_define_const(grpc_rb_mRpcErrors, "INVALID_FLAGS",
UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS));
/* Add the detail strings to a Hash */
@ -637,52 +641,55 @@ void Init_grpc_error_codes() {
rb_str_new2("outstanding read or write present"));
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS),
rb_str_new2("a bad flag was given"));
rb_define_const(rb_RpcErrors, "ErrorMessages", rb_error_code_details);
rb_define_const(grpc_rb_mRpcErrors, "ErrorMessages", rb_error_code_details);
rb_obj_freeze(rb_error_code_details);
}
void Init_grpc_op_codes() {
/* Constants representing operation type codes in grpc.h */
VALUE rb_CallOps = rb_define_module_under(rb_mGrpcCore, "CallOps");
rb_define_const(rb_CallOps, "SEND_INITIAL_METADATA",
VALUE grpc_rb_mCallOps =
rb_define_module_under(grpc_rb_mGrpcCore, "CallOps");
rb_define_const(grpc_rb_mCallOps, "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_CLOSE_FROM_CLIENT",
rb_define_const(grpc_rb_mCallOps, "SEND_MESSAGE",
UINT2NUM(GRPC_OP_SEND_MESSAGE));
rb_define_const(grpc_rb_mCallOps, "SEND_CLOSE_FROM_CLIENT",
UINT2NUM(GRPC_OP_SEND_CLOSE_FROM_CLIENT));
rb_define_const(rb_CallOps, "SEND_STATUS_FROM_SERVER",
rb_define_const(grpc_rb_mCallOps, "SEND_STATUS_FROM_SERVER",
UINT2NUM(GRPC_OP_SEND_STATUS_FROM_SERVER));
rb_define_const(rb_CallOps, "RECV_INITIAL_METADATA",
rb_define_const(grpc_rb_mCallOps, "RECV_INITIAL_METADATA",
UINT2NUM(GRPC_OP_RECV_INITIAL_METADATA));
rb_define_const(rb_CallOps, "RECV_MESSAGE",
rb_define_const(grpc_rb_mCallOps, "RECV_MESSAGE",
UINT2NUM(GRPC_OP_RECV_MESSAGE));
rb_define_const(rb_CallOps, "RECV_STATUS_ON_CLIENT",
rb_define_const(grpc_rb_mCallOps, "RECV_STATUS_ON_CLIENT",
UINT2NUM(GRPC_OP_RECV_STATUS_ON_CLIENT));
rb_define_const(rb_CallOps, "RECV_CLOSE_ON_SERVER",
rb_define_const(grpc_rb_mCallOps, "RECV_CLOSE_ON_SERVER",
UINT2NUM(GRPC_OP_RECV_CLOSE_ON_SERVER));
}
void Init_grpc_call() {
/* CallError inherits from Exception to signal that it is non-recoverable */
rb_eCallError =
rb_define_class_under(rb_mGrpcCore, "CallError", rb_eException);
rb_eOutOfTime =
rb_define_class_under(rb_mGrpcCore, "OutOfTime", rb_eException);
rb_cCall = rb_define_class_under(rb_mGrpcCore, "Call", rb_cObject);
rb_cMdAry = rb_define_class_under(rb_mGrpcCore, "MetadataArray",
rb_cObject);
grpc_rb_eCallError =
rb_define_class_under(grpc_rb_mGrpcCore, "CallError", rb_eException);
grpc_rb_eOutOfTime =
rb_define_class_under(grpc_rb_mGrpcCore, "OutOfTime", rb_eException);
grpc_rb_cCall = rb_define_class_under(grpc_rb_mGrpcCore, "Call", rb_cObject);
grpc_rb_cMdAry = rb_define_class_under(grpc_rb_mGrpcCore, "MetadataArray",
rb_cObject);
/* Prevent allocation or inialization of the Call class */
rb_define_alloc_func(rb_cCall, grpc_rb_cannot_alloc);
rb_define_method(rb_cCall, "initialize", grpc_rb_cannot_init, 0);
rb_define_method(rb_cCall, "initialize_copy", grpc_rb_cannot_init_copy, 1);
rb_define_alloc_func(grpc_rb_cCall, grpc_rb_cannot_alloc);
rb_define_method(grpc_rb_cCall, "initialize", grpc_rb_cannot_init, 0);
rb_define_method(grpc_rb_cCall, "initialize_copy",
grpc_rb_cannot_init_copy, 1);
/* Add ruby analogues of the Call methods. */
rb_define_method(rb_cCall, "run_batch", grpc_rb_call_run_batch, 4);
rb_define_method(rb_cCall, "cancel", grpc_rb_call_cancel, 0);
rb_define_method(rb_cCall, "status", grpc_rb_call_get_status, 0);
rb_define_method(rb_cCall, "status=", grpc_rb_call_set_status, 1);
rb_define_method(rb_cCall, "metadata", grpc_rb_call_get_metadata, 0);
rb_define_method(rb_cCall, "metadata=", grpc_rb_call_set_metadata, 1);
rb_define_method(grpc_rb_cCall, "run_batch", grpc_rb_call_run_batch, 4);
rb_define_method(grpc_rb_cCall, "cancel", grpc_rb_call_cancel, 0);
rb_define_method(grpc_rb_cCall, "status", grpc_rb_call_get_status, 0);
rb_define_method(grpc_rb_cCall, "status=", grpc_rb_call_set_status, 1);
rb_define_method(grpc_rb_cCall, "metadata", grpc_rb_call_get_metadata, 0);
rb_define_method(grpc_rb_cCall, "metadata=", grpc_rb_call_set_metadata, 1);
/* Ids used to support call attributes */
id_metadata = rb_intern("metadata");
@ -703,7 +710,7 @@ void Init_grpc_call() {
sym_cancelled = ID2SYM(rb_intern("cancelled"));
/* The Struct used to return the run_batch result. */
rb_sBatchResult = rb_struct_define(
grpc_rb_sBatchResult = rb_struct_define(
"BatchResult",
"send_message",
"send_metadata",
@ -718,7 +725,7 @@ void Init_grpc_call() {
/* The hash for reference counting calls, to ensure they can't be destroyed
* more than once */
hash_all_calls = rb_hash_new();
rb_define_const(rb_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_op_codes();
@ -744,5 +751,6 @@ VALUE grpc_rb_wrap_call(grpc_call *c) {
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c),
UINT2NUM(NUM2UINT(obj) + 1));
}
return Data_Wrap_Struct(rb_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. */
VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary);
/* rb_cCall is the Call class whose instances proxy grpc_call. */
extern VALUE rb_cCall;
/* grpc_rb_cCall is the Call class whose instances proxy grpc_call. */
extern VALUE grpc_rb_cCall;
/* rb_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. */
extern VALUE rb_eCallError;
extern VALUE grpc_rb_eCallError;
/* rb_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. */
extern VALUE rb_eOutOfTime;
extern VALUE grpc_rb_eOutOfTime;
/* Initializes the Call class. */
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 */
static VALUE rb_cChannelArgs;
static VALUE grpc_rb_cChannelArgs;
/* grpc_rb_channel wraps a grpc_channel. It provides a peer ruby object,
* '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. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_channel_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(rb_cChannel));
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cChannel));
return Qnil;
}
@ -240,36 +240,38 @@ static VALUE grpc_rb_channel_destroy(VALUE self) {
return Qnil;
}
/* rb_cChannel is the ruby class that proxies grpc_channel. */
VALUE rb_cChannel = Qnil;
/* grpc_rb_cChannel is the ruby class that proxies grpc_channel. */
VALUE grpc_rb_cChannel = Qnil;
void Init_grpc_channel() {
rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
rb_cChannel = rb_define_class_under(rb_mGrpcCore, "Channel", rb_cObject);
grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
grpc_rb_cChannel =
rb_define_class_under(grpc_rb_mGrpcCore, "Channel", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_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. */
rb_define_method(rb_cChannel, "initialize", grpc_rb_channel_init, -1);
rb_define_method(rb_cChannel, "initialize_copy", grpc_rb_channel_init_copy,
1);
rb_define_method(grpc_rb_cChannel, "initialize", grpc_rb_channel_init, -1);
rb_define_method(grpc_rb_cChannel, "initialize_copy",
grpc_rb_channel_init_copy, 1);
/* Add ruby analogues of the Channel methods. */
rb_define_method(rb_cChannel, "create_call", grpc_rb_channel_create_call, 4);
rb_define_method(rb_cChannel, "destroy", grpc_rb_channel_destroy, 0);
rb_define_alias(rb_cChannel, "close", "destroy");
rb_define_method(grpc_rb_cChannel, "create_call",
grpc_rb_channel_create_call, 4);
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_cqueue = rb_intern("__cqueue");
id_target = rb_intern("__target");
rb_define_const(rb_cChannel, "SSL_TARGET",
rb_define_const(grpc_rb_cChannel, "SSL_TARGET",
ID2SYM(rb_intern(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)));
rb_define_const(rb_cChannel, "ENABLE_CENSUS",
rb_define_const(grpc_rb_cChannel, "ENABLE_CENSUS",
ID2SYM(rb_intern(GRPC_ARG_ENABLE_CENSUS)));
rb_define_const(rb_cChannel, "MAX_CONCURRENT_STREAMS",
rb_define_const(grpc_rb_cChannel, "MAX_CONCURRENT_STREAMS",
ID2SYM(rb_intern(GRPC_ARG_MAX_CONCURRENT_STREAMS)));
rb_define_const(rb_cChannel, "MAX_MESSAGE_LENGTH",
rb_define_const(grpc_rb_cChannel, "MAX_MESSAGE_LENGTH",
ID2SYM(rb_intern(GRPC_ARG_MAX_MESSAGE_LENGTH)));
}

@ -37,8 +37,8 @@
#include <ruby.h>
#include <grpc/grpc.h>
/* rb_cChannel is the Channel class whose instances proxy grpc_channel. */
extern VALUE rb_cChannel;
/* grpc_rb_cChannel is the Channel class whose instances proxy grpc_channel. */
extern VALUE grpc_rb_cChannel;
/* Initializes the Channel class. */
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) {
ID id_size = rb_intern("size");
VALUE rb_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;
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);
rb_hash_foreach(params->src_hash,
grpc_rb_channel_create_in_process_add_args_hash_cb,
Data_Wrap_Struct(rb_cChannelArgs, GC_NOT_MARKED,
Data_Wrap_Struct(grpc_rb_cChannelArgs, GC_NOT_MARKED,
GC_DONT_FREE, params->dst));
/* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
* 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;
}
/* rb_cCompletionQueue is the ruby class that proxies grpc_completion_queue. */
VALUE rb_cCompletionQueue = Qnil;
/* grpc_rb_cCompletionQueue is the ruby class that proxies
* grpc_completion_queue. */
VALUE grpc_rb_cCompletionQueue = Qnil;
void Init_grpc_completion_queue() {
rb_cCompletionQueue =
rb_define_class_under(rb_mGrpcCore, "CompletionQueue", rb_cObject);
grpc_rb_cCompletionQueue =
rb_define_class_under(grpc_rb_mGrpcCore, "CompletionQueue", rb_cObject);
/* 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
this func, so no separate initialization step is necessary. */
rb_define_alloc_func(rb_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. */
rb_define_method(rb_cCompletionQueue, "next", grpc_rb_completion_queue_next,
1);
rb_define_method(grpc_rb_cCompletionQueue, "next",
grpc_rb_completion_queue_next, 1);
/* Add the pluck method that waits for the next event of given tag */
rb_define_method(rb_cCompletionQueue, "pluck", grpc_rb_completion_queue_pluck,
2);
rb_define_method(grpc_rb_cCompletionQueue, "pluck",
grpc_rb_completion_queue_pluck, 2);
}
/* 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,
VALUE timeout);
/* rb_cCompletionQueue is the CompletionQueue class whose instances proxy
/* grpc_rb_cCompletionQueue is the CompletionQueue class whose instances proxy
grpc_completion_queue. */
extern VALUE rb_cCompletionQueue;
extern VALUE grpc_rb_cCompletionQueue;
/* Initializes the CompletionQueue class. */
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. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_credentials_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(rb_cCredentials));
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cCredentials));
}
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;
return Data_Wrap_Struct(rb_cCredentials, grpc_rb_credentials_mark,
return Data_Wrap_Struct(grpc_rb_cCredentials, grpc_rb_credentials_mark,
grpc_rb_credentials_free, wrapper);
}
@ -242,30 +242,31 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
return self;
}
/* rb_cCredentials is the ruby class that proxies grpc_credentials. */
VALUE rb_cCredentials = Qnil;
/* grpc_rb_cCredentials is the ruby class that proxies grpc_credentials. */
VALUE grpc_rb_cCredentials = Qnil;
void Init_grpc_credentials() {
rb_cCredentials =
rb_define_class_under(rb_mGrpcCore, "Credentials", rb_cObject);
grpc_rb_cCredentials =
rb_define_class_under(grpc_rb_mGrpcCore, "Credentials", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_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. */
rb_define_method(rb_cCredentials, "initialize", grpc_rb_credentials_init, -1);
rb_define_method(rb_cCredentials, "initialize_copy",
rb_define_method(grpc_rb_cCredentials, "initialize",
grpc_rb_credentials_init, -1);
rb_define_method(grpc_rb_cCredentials, "initialize_copy",
grpc_rb_credentials_init_copy, 1);
/* Provide static funcs that create new special instances. */
rb_define_singleton_method(rb_cCredentials, "default",
rb_define_singleton_method(grpc_rb_cCredentials, "default",
grpc_rb_default_credentials_create, 0);
rb_define_singleton_method(rb_cCredentials, "compute_engine",
rb_define_singleton_method(grpc_rb_cCredentials, "compute_engine",
grpc_rb_compute_engine_credentials_create, 0);
/* Provide other methods. */
rb_define_method(rb_cCredentials, "compose",
rb_define_method(grpc_rb_cCredentials, "compose",
grpc_rb_composite_credentials_create, 1);
id_pem_cert_chain = rb_intern("__pem_cert_chain");

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

@ -50,7 +50,7 @@
const RUBY_DATA_FUNC GC_NOT_MARKED = NULL;
const RUBY_DATA_FUNC GC_DONT_FREE = NULL;
VALUE rb_cTimeVal = Qnil;
VALUE grpc_rb_cTimeVal = Qnil;
/* Alloc func that blocks allocation of a given object by raising an
* exception. */
@ -96,7 +96,7 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
switch (TYPE(time)) {
case T_DATA:
if (CLASS_OF(time) == rb_cTimeVal) {
if (CLASS_OF(time) == grpc_rb_cTimeVal) {
Data_Get_Struct(time, gpr_timespec, time_const);
t = *time_const;
} 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() {
/* Constants representing the status codes or grpc_status_code in status.h */
VALUE rb_mStatusCodes =
rb_define_module_under(rb_mGrpcCore, "StatusCodes");
rb_define_const(rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK));
rb_define_const(rb_mStatusCodes, "CANCELLED", INT2NUM(GRPC_STATUS_CANCELLED));
rb_define_const(rb_mStatusCodes, "UNKNOWN", INT2NUM(GRPC_STATUS_UNKNOWN));
rb_define_const(rb_mStatusCodes, "INVALID_ARGUMENT",
VALUE grpc_rb_mStatusCodes =
rb_define_module_under(grpc_rb_mGrpcCore, "StatusCodes");
rb_define_const(grpc_rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK));
rb_define_const(grpc_rb_mStatusCodes, "CANCELLED",
INT2NUM(GRPC_STATUS_CANCELLED));
rb_define_const(grpc_rb_mStatusCodes, "UNKNOWN",
INT2NUM(GRPC_STATUS_UNKNOWN));
rb_define_const(grpc_rb_mStatusCodes, "INVALID_ARGUMENT",
INT2NUM(GRPC_STATUS_INVALID_ARGUMENT));
rb_define_const(rb_mStatusCodes, "DEADLINE_EXCEEDED",
rb_define_const(grpc_rb_mStatusCodes, "DEADLINE_EXCEEDED",
INT2NUM(GRPC_STATUS_DEADLINE_EXCEEDED));
rb_define_const(rb_mStatusCodes, "NOT_FOUND", INT2NUM(GRPC_STATUS_NOT_FOUND));
rb_define_const(rb_mStatusCodes, "ALREADY_EXISTS",
rb_define_const(grpc_rb_mStatusCodes, "NOT_FOUND",
INT2NUM(GRPC_STATUS_NOT_FOUND));
rb_define_const(grpc_rb_mStatusCodes, "ALREADY_EXISTS",
INT2NUM(GRPC_STATUS_ALREADY_EXISTS));
rb_define_const(rb_mStatusCodes, "PERMISSION_DENIED",
rb_define_const(grpc_rb_mStatusCodes, "PERMISSION_DENIED",
INT2NUM(GRPC_STATUS_PERMISSION_DENIED));
rb_define_const(rb_mStatusCodes, "UNAUTHENTICATED",
rb_define_const(grpc_rb_mStatusCodes, "UNAUTHENTICATED",
INT2NUM(GRPC_STATUS_UNAUTHENTICATED));
rb_define_const(rb_mStatusCodes, "RESOURCE_EXHAUSTED",
rb_define_const(grpc_rb_mStatusCodes, "RESOURCE_EXHAUSTED",
INT2NUM(GRPC_STATUS_RESOURCE_EXHAUSTED));
rb_define_const(rb_mStatusCodes, "FAILED_PRECONDITION",
rb_define_const(grpc_rb_mStatusCodes, "FAILED_PRECONDITION",
INT2NUM(GRPC_STATUS_FAILED_PRECONDITION));
rb_define_const(rb_mStatusCodes, "ABORTED", INT2NUM(GRPC_STATUS_ABORTED));
rb_define_const(rb_mStatusCodes, "OUT_OF_RANGE",
rb_define_const(grpc_rb_mStatusCodes, "ABORTED",
INT2NUM(GRPC_STATUS_ABORTED));
rb_define_const(grpc_rb_mStatusCodes, "OUT_OF_RANGE",
INT2NUM(GRPC_STATUS_OUT_OF_RANGE));
rb_define_const(rb_mStatusCodes, "UNIMPLEMENTED",
rb_define_const(grpc_rb_mStatusCodes, "UNIMPLEMENTED",
INT2NUM(GRPC_STATUS_UNIMPLEMENTED));
rb_define_const(rb_mStatusCodes, "INTERNAL", INT2NUM(GRPC_STATUS_INTERNAL));
rb_define_const(rb_mStatusCodes, "UNAVAILABLE",
rb_define_const(grpc_rb_mStatusCodes, "INTERNAL",
INT2NUM(GRPC_STATUS_INTERNAL));
rb_define_const(grpc_rb_mStatusCodes, "UNAVAILABLE",
INT2NUM(GRPC_STATUS_UNAVAILABLE));
rb_define_const(rb_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. */
@ -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. */
void Init_grpc_time_consts() {
VALUE rb_mTimeConsts =
rb_define_module_under(rb_mGrpcCore, "TimeConsts");
rb_cTimeVal =
rb_define_class_under(rb_mGrpcCore, "TimeSpec", rb_cObject);
rb_define_const(rb_mTimeConsts, "ZERO",
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
VALUE grpc_rb_mTimeConsts =
rb_define_module_under(grpc_rb_mGrpcCore, "TimeConsts");
grpc_rb_cTimeVal =
rb_define_class_under(grpc_rb_mGrpcCore, "TimeSpec", rb_cObject);
rb_define_const(grpc_rb_mTimeConsts, "ZERO",
Data_Wrap_Struct(grpc_rb_cTimeVal,
GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_time_0));
rb_define_const(rb_mTimeConsts, "INFINITE_FUTURE",
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
rb_define_const(grpc_rb_mTimeConsts, "INFINITE_FUTURE",
Data_Wrap_Struct(grpc_rb_cTimeVal,
GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_inf_future));
rb_define_const(rb_mTimeConsts, "INFINITE_PAST",
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
rb_define_const(grpc_rb_mTimeConsts, "INFINITE_PAST",
Data_Wrap_Struct(grpc_rb_cTimeVal,
GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_inf_past));
rb_define_method(rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0);
rb_define_method(rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0);
rb_define_method(rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0);
rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0);
rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0);
rb_define_method(grpc_rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0);
id_at = rb_intern("at");
id_inspect = rb_intern("inspect");
id_to_s = rb_intern("to_s");
@ -239,23 +248,25 @@ void grpc_rb_shutdown(void *vm) { grpc_shutdown(); }
/* Initialize the GRPC module structs */
/* rb_sNewServerRpc is the struct that holds new server rpc details. */
VALUE rb_sNewServerRpc = Qnil;
/* rb_sStatus is the struct that holds status details. */
VALUE rb_sStatus = Qnil;
/* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
VALUE grpc_rb_sNewServerRpc = Qnil;
/* grpc_rb_sStatus is the struct that holds status details. */
VALUE grpc_rb_sStatus = Qnil;
/* Initialize the GRPC module. */
VALUE rb_mGRPC = Qnil;
VALUE rb_mGrpcCore = Qnil;
VALUE grpc_rb_mGRPC = Qnil;
VALUE grpc_rb_mGrpcCore = Qnil;
void Init_grpc() {
grpc_init();
ruby_vm_at_exit(grpc_rb_shutdown);
rb_mGRPC = rb_define_module("GRPC");
rb_mGrpcCore = rb_define_module_under(rb_mGRPC, "Core");
rb_sNewServerRpc = rb_struct_define("NewServerRpc", "method", "host",
"deadline", "metadata", "call", NULL);
rb_sStatus = rb_struct_define("Status", "code", "details", "metadata", NULL);
grpc_rb_mGRPC = rb_define_module("GRPC");
grpc_rb_mGrpcCore = rb_define_module_under(grpc_rb_mGRPC, "Core");
grpc_rb_sNewServerRpc =
rb_struct_define("NewServerRpc", "method", "host",
"deadline", "metadata", "call", NULL);
grpc_rb_sStatus =
rb_struct_define("Status", "code", "details", "metadata", NULL);
sym_code = ID2SYM(rb_intern("code"));
sym_details = ID2SYM(rb_intern("details"));
sym_metadata = ID2SYM(rb_intern("metadata"));

@ -38,25 +38,25 @@
#include <ruby.h>
#include <grpc/support/time.h>
/* rb_mGrpcCore is the module containing the ruby wrapper GRPC classes. */
extern VALUE rb_mGrpcCore;
/* grpc_rb_mGrpcCore is the module containing the ruby wrapper GRPC classes. */
extern VALUE grpc_rb_mGrpcCore;
/* Class used to wrap timeval structs. */
extern VALUE rb_cTimeVal;
extern VALUE grpc_rb_cTimeVal;
/* rb_sNewServerRpc is the struct that holds new server rpc details. */
extern VALUE rb_sNewServerRpc;
/* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
extern VALUE grpc_rb_sNewServerRpc;
/* rb_sStruct is the struct that holds status details. */
extern VALUE rb_sStatus;
/* grpc_rb_sStruct is the struct that holds status details. */
extern VALUE grpc_rb_sStatus;
/* sym_code is the symbol for the code attribute of rb_sStatus. */
/* sym_code is the symbol for the code attribute of grpc_rb_sStatus. */
VALUE sym_code;
/* sym_details is the symbol for the details attribute of rb_sStatus. */
/* sym_details is the symbol for the details attribute of grpc_rb_sStatus. */
VALUE sym_details;
/* sym_metadata is the symbol for the metadata attribute of rb_sStatus. */
/* sym_metadata is the symbol for the metadata attribute of grpc_rb_sStatus. */
VALUE sym_metadata;
/* 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_grpc.h"
/* rb_cServer is the ruby class that proxies grpc_server. */
VALUE rb_cServer = Qnil;
/* grpc_rb_cServer is the ruby class that proxies grpc_server. */
VALUE grpc_rb_cServer = Qnil;
/* id_at is the constructor method of the ruby standard Time class. */
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. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(rb_cServer));
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cServer));
}
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));
if (err != GRPC_CALL_OK) {
grpc_request_call_stack_cleanup(&st);
rb_raise(rb_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);
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) {
grpc_request_call_stack_cleanup(&st);
grpc_event_finish(ev);
rb_raise(rb_eCallError, "request_call completion failed: (code=%d)",
rb_raise(grpc_rb_eCallError, "request_call completion failed: (code=%d)",
ev->data.op_complete);
return Qnil;
}
/* build the NewServerRpc struct result */
result = rb_struct_new(
rb_sNewServerRpc,
grpc_rb_sNewServerRpc,
rb_str_new2(st.details.method),
rb_str_new2(st.details.host),
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() {
rb_cServer = rb_define_class_under(rb_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 */
rb_define_alloc_func(rb_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. */
rb_define_method(rb_cServer, "initialize", grpc_rb_server_init, 2);
rb_define_method(rb_cServer, "initialize_copy", grpc_rb_server_init_copy, 1);
rb_define_method(grpc_rb_cServer, "initialize", grpc_rb_server_init, 2);
rb_define_method(grpc_rb_cServer, "initialize_copy",
grpc_rb_server_init_copy, 1);
/* Add the server methods. */
rb_define_method(rb_cServer, "request_call", grpc_rb_server_request_call, 3);
rb_define_method(rb_cServer, "start", grpc_rb_server_start, 0);
rb_define_method(rb_cServer, "destroy", grpc_rb_server_destroy, 0);
rb_define_alias(rb_cServer, "close", "destroy");
rb_define_method(rb_cServer, "add_http2_port", grpc_rb_server_add_http2_port,
rb_define_method(grpc_rb_cServer, "request_call",
grpc_rb_server_request_call, 3);
rb_define_method(grpc_rb_cServer, "start", grpc_rb_server_start, 0);
rb_define_method(grpc_rb_cServer, "destroy", grpc_rb_server_destroy, 0);
rb_define_alias(grpc_rb_cServer, "close", "destroy");
rb_define_method(grpc_rb_cServer, "add_http2_port",
grpc_rb_server_add_http2_port,
-1);
id_at = rb_intern("at");
}

@ -37,9 +37,9 @@
#include <ruby.h>
#include <grpc/grpc.h>
/* rb_cServer is the Server class whose instances proxy
/* grpc_rb_cServer is the Server class whose instances proxy
grpc_byte_buffer. */
extern VALUE rb_cServer;
extern VALUE grpc_rb_cServer;
/* Initializes the Server class. */
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 ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_credentials_free) {
rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(rb_cServerCredentials));
rb_obj_classname(grpc_rb_cServerCredentials));
}
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;
}
/* rb_cServerCredentials is the ruby class that proxies
/* grpc_rb_cServerCredentials is the ruby class that proxies
grpc_server_credentials. */
VALUE rb_cServerCredentials = Qnil;
VALUE grpc_rb_cServerCredentials = Qnil;
void Init_grpc_server_credentials() {
rb_cServerCredentials =
rb_define_class_under(rb_mGrpcCore, "ServerCredentials", rb_cObject);
grpc_rb_cServerCredentials =
rb_define_class_under(grpc_rb_mGrpcCore, "ServerCredentials", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_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. */
rb_define_method(rb_cServerCredentials, "initialize",
rb_define_method(grpc_rb_cServerCredentials, "initialize",
grpc_rb_server_credentials_init, 3);
rb_define_method(rb_cServerCredentials, "initialize_copy",
rb_define_method(grpc_rb_cServerCredentials, "initialize_copy",
grpc_rb_server_credentials_init_copy, 1);
id_pem_cert_chain = rb_intern("__pem_cert_chain");

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

Loading…
Cancel
Save