xref: /aosp_15_r20/external/grpc-grpc/src/ruby/ext/grpc/rb_grpc.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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 
24 #include <grpc/support/time.h>
25 
26 /* grpc_rb_mGrpcCore is the module containing the ruby wrapper GRPC classes. */
27 extern VALUE grpc_rb_mGrpcCore;
28 
29 /* grpc_rb_sNewServerRpc is the struct that holds new server rpc details. */
30 extern VALUE grpc_rb_sNewServerRpc;
31 
32 /* grpc_rb_sStruct is the struct that holds status details. */
33 extern VALUE grpc_rb_sStatus;
34 
35 /* sym_code is the symbol for the code attribute of grpc_rb_sStatus. */
36 extern VALUE sym_code;
37 
38 /* sym_details is the symbol for the details attribute of grpc_rb_sStatus. */
39 extern VALUE sym_details;
40 
41 /* sym_metadata is the symbol for the metadata attribute of grpc_rb_sStatus. */
42 extern VALUE sym_metadata;
43 
44 /* GC_NOT_MARKED is used in calls to Data_Wrap_Struct to indicate that the
45    wrapped struct does not need to participate in ruby gc. */
46 #define GRPC_RB_GC_NOT_MARKED (RUBY_DATA_FUNC)(NULL)
47 
48 /* GC_DONT_FREED is used in calls to Data_Wrap_Struct to indicate that the
49    wrapped struct should not be freed the wrapped ruby object is released by
50    the garbage collector. */
51 #define GRPC_RB_GC_DONT_FREE (RUBY_DATA_FUNC)(NULL)
52 
53 /* GRPC_RB_MEMSIZE_UNAVAILABLE is used in rb_data_type_t to indicate that the
54  * number of bytes used by the wrapped struct is not available. */
55 #define GRPC_RB_MEMSIZE_UNAVAILABLE (size_t(*)(const void*))(NULL)
56 
57 /* A ruby object alloc func that fails by raising an exception. */
58 VALUE grpc_rb_cannot_alloc(VALUE cls);
59 
60 /* A ruby object init func that fails by raising an exception. */
61 VALUE grpc_rb_cannot_init(VALUE self);
62 
63 /* A ruby object clone init func that fails by raising an exception. */
64 VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self);
65 
66 /* grpc_rb_time_timeval creates a gpr_timespec from a ruby time object. */
67 gpr_timespec grpc_rb_time_timeval(VALUE time, int interval);
68 
69 void grpc_ruby_fork_guard();
70 
71 /* To be called once and only once before entering code section that is
72  * definitely not fork-safe. Used in conjunction with GRPC.prefork
73  * to catch for-unsafe processes and raise errors. */
74 void grpc_rb_fork_unsafe_begin();
75 
76 /* To be called once and only once after each grpc_rb_fork_unsafe_begin*/
77 void grpc_rb_fork_unsafe_end();
78 
79 void grpc_ruby_init();
80 
81 #endif /* GRPC_RB_H_ */
82