1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_RB_H_
20 #define GRPC_RB_H_
21 
22 #include <ruby/ruby.h>
23 #include <sys/time.h>
24 
25 #include <grpc/support/time.h>
26 
27 /* grpc_rb_mGrpcCore is the module containing the ruby wrapper GRPC classes. */
28 extern VALUE grpc_rb_mGrpcCore;
29 
30 /* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
31 extern VALUE grpc_rb_sNewServerRpc;
32 
33 /* grpc_rb_sStruct is the struct that holds status details. */
34 extern VALUE grpc_rb_sStatus;
35 
36 /* sym_code is the symbol for the code attribute of grpc_rb_sStatus. */
37 extern VALUE sym_code;
38 
39 /* sym_details is the symbol for the details attribute of grpc_rb_sStatus. */
40 extern VALUE sym_details;
41 
42 /* sym_metadata is the symbol for the metadata attribute of grpc_rb_sStatus. */
43 extern VALUE sym_metadata;
44 
45 /* GC_NOT_MARKED is used in calls to Data_Wrap_Struct to indicate that the
46    wrapped struct does not need to participate in ruby gc. */
47 #define GRPC_RB_GC_NOT_MARKED (RUBY_DATA_FUNC)(NULL)
48 
49 /* GC_DONT_FREED is used in calls to Data_Wrap_Struct to indicate that the
50    wrapped struct should not be freed the wrapped ruby object is released by
51    the garbage collector. */
52 #define GRPC_RB_GC_DONT_FREE (RUBY_DATA_FUNC)(NULL)
53 
54 /* GRPC_RB_MEMSIZE_UNAVAILABLE is used in rb_data_type_t to indicate that the
55  * number of bytes used by the wrapped struct is not available. */
56 #define GRPC_RB_MEMSIZE_UNAVAILABLE (size_t(*)(const void*))(NULL)
57 
58 /* A ruby object alloc func that fails by raising an exception. */
59 VALUE grpc_rb_cannot_alloc(VALUE cls);
60 
61 /* A ruby object init func that fails by raising an exception. */
62 VALUE grpc_rb_cannot_init(VALUE self);
63 
64 /* A ruby object clone init func that fails by raising an exception. */
65 VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self);
66 
67 /* grpc_rb_time_timeval creates a gpr_timespec from a ruby time object. */
68 gpr_timespec grpc_rb_time_timeval(VALUE time, int interval);
69 
70 void grpc_ruby_once_init();
71 
72 void grpc_ruby_fork_guard();
73 
74 #endif /* GRPC_RB_H_ */
75