• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2016 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 #include <grpcpp/impl/codegen/core_codegen.h>
20 
21 #include <stdlib.h>
22 
23 #include <grpc/byte_buffer.h>
24 #include <grpc/byte_buffer_reader.h>
25 #include <grpc/grpc.h>
26 #include <grpc/slice.h>
27 #include <grpc/slice_buffer.h>
28 #include <grpc/support/alloc.h>
29 #include <grpc/support/log.h>
30 #include <grpc/support/port_platform.h>
31 #include <grpc/support/sync.h>
32 #include <grpcpp/support/config.h>
33 
34 #include "src/core/lib/profiling/timers.h"
35 
36 struct grpc_byte_buffer;
37 
38 namespace grpc {
39 
40 const grpc_completion_queue_factory*
grpc_completion_queue_factory_lookup(const grpc_completion_queue_attributes * attributes)41 CoreCodegen::grpc_completion_queue_factory_lookup(
42     const grpc_completion_queue_attributes* attributes) {
43   return ::grpc_completion_queue_factory_lookup(attributes);
44 }
45 
grpc_completion_queue_create(const grpc_completion_queue_factory * factory,const grpc_completion_queue_attributes * attributes,void * reserved)46 grpc_completion_queue* CoreCodegen::grpc_completion_queue_create(
47     const grpc_completion_queue_factory* factory,
48     const grpc_completion_queue_attributes* attributes, void* reserved) {
49   return ::grpc_completion_queue_create(factory, attributes, reserved);
50 }
51 
grpc_completion_queue_create_for_next(void * reserved)52 grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_next(
53     void* reserved) {
54   return ::grpc_completion_queue_create_for_next(reserved);
55 }
56 
grpc_completion_queue_create_for_pluck(void * reserved)57 grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_pluck(
58     void* reserved) {
59   return ::grpc_completion_queue_create_for_pluck(reserved);
60 }
61 
grpc_completion_queue_shutdown(grpc_completion_queue * cq)62 void CoreCodegen::grpc_completion_queue_shutdown(grpc_completion_queue* cq) {
63   ::grpc_completion_queue_shutdown(cq);
64 }
65 
grpc_completion_queue_destroy(grpc_completion_queue * cq)66 void CoreCodegen::grpc_completion_queue_destroy(grpc_completion_queue* cq) {
67   ::grpc_completion_queue_destroy(cq);
68 }
69 
grpc_completion_queue_pluck(grpc_completion_queue * cq,void * tag,gpr_timespec deadline,void * reserved)70 grpc_event CoreCodegen::grpc_completion_queue_pluck(grpc_completion_queue* cq,
71                                                     void* tag,
72                                                     gpr_timespec deadline,
73                                                     void* reserved) {
74   return ::grpc_completion_queue_pluck(cq, tag, deadline, reserved);
75 }
76 
gpr_malloc(size_t size)77 void* CoreCodegen::gpr_malloc(size_t size) { return ::gpr_malloc(size); }
78 
gpr_free(void * p)79 void CoreCodegen::gpr_free(void* p) { return ::gpr_free(p); }
80 
grpc_init()81 void CoreCodegen::grpc_init() { ::grpc_init(); }
grpc_shutdown()82 void CoreCodegen::grpc_shutdown() { ::grpc_shutdown(); }
83 
gpr_mu_init(gpr_mu * mu)84 void CoreCodegen::gpr_mu_init(gpr_mu* mu) { ::gpr_mu_init(mu); }
gpr_mu_destroy(gpr_mu * mu)85 void CoreCodegen::gpr_mu_destroy(gpr_mu* mu) { ::gpr_mu_destroy(mu); }
gpr_mu_lock(gpr_mu * mu)86 void CoreCodegen::gpr_mu_lock(gpr_mu* mu) { ::gpr_mu_lock(mu); }
gpr_mu_unlock(gpr_mu * mu)87 void CoreCodegen::gpr_mu_unlock(gpr_mu* mu) { ::gpr_mu_unlock(mu); }
gpr_cv_init(gpr_cv * cv)88 void CoreCodegen::gpr_cv_init(gpr_cv* cv) { ::gpr_cv_init(cv); }
gpr_cv_destroy(gpr_cv * cv)89 void CoreCodegen::gpr_cv_destroy(gpr_cv* cv) { ::gpr_cv_destroy(cv); }
gpr_cv_wait(gpr_cv * cv,gpr_mu * mu,gpr_timespec abs_deadline)90 int CoreCodegen::gpr_cv_wait(gpr_cv* cv, gpr_mu* mu,
91                              gpr_timespec abs_deadline) {
92   return ::gpr_cv_wait(cv, mu, abs_deadline);
93 }
gpr_cv_signal(gpr_cv * cv)94 void CoreCodegen::gpr_cv_signal(gpr_cv* cv) { ::gpr_cv_signal(cv); }
gpr_cv_broadcast(gpr_cv * cv)95 void CoreCodegen::gpr_cv_broadcast(gpr_cv* cv) { ::gpr_cv_broadcast(cv); }
96 
grpc_byte_buffer_copy(grpc_byte_buffer * bb)97 grpc_byte_buffer* CoreCodegen::grpc_byte_buffer_copy(grpc_byte_buffer* bb) {
98   return ::grpc_byte_buffer_copy(bb);
99 }
100 
grpc_byte_buffer_destroy(grpc_byte_buffer * bb)101 void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) {
102   ::grpc_byte_buffer_destroy(bb);
103 }
104 
grpc_byte_buffer_length(grpc_byte_buffer * bb)105 size_t CoreCodegen::grpc_byte_buffer_length(grpc_byte_buffer* bb) {
106   return ::grpc_byte_buffer_length(bb);
107 }
108 
grpc_call_start_batch(grpc_call * call,const grpc_op * ops,size_t nops,void * tag,void * reserved)109 grpc_call_error CoreCodegen::grpc_call_start_batch(grpc_call* call,
110                                                    const grpc_op* ops,
111                                                    size_t nops, void* tag,
112                                                    void* reserved) {
113   return ::grpc_call_start_batch(call, ops, nops, tag, reserved);
114 }
115 
grpc_call_cancel_with_status(grpc_call * call,grpc_status_code status,const char * description,void * reserved)116 grpc_call_error CoreCodegen::grpc_call_cancel_with_status(
117     grpc_call* call, grpc_status_code status, const char* description,
118     void* reserved) {
119   return ::grpc_call_cancel_with_status(call, status, description, reserved);
120 }
grpc_call_ref(grpc_call * call)121 void CoreCodegen::grpc_call_ref(grpc_call* call) { ::grpc_call_ref(call); }
grpc_call_unref(grpc_call * call)122 void CoreCodegen::grpc_call_unref(grpc_call* call) { ::grpc_call_unref(call); }
grpc_call_arena_alloc(grpc_call * call,size_t length)123 void* CoreCodegen::grpc_call_arena_alloc(grpc_call* call, size_t length) {
124   return ::grpc_call_arena_alloc(call, length);
125 }
grpc_call_error_to_string(grpc_call_error error)126 const char* CoreCodegen::grpc_call_error_to_string(grpc_call_error error) {
127   return ::grpc_call_error_to_string(error);
128 }
129 
grpc_byte_buffer_reader_init(grpc_byte_buffer_reader * reader,grpc_byte_buffer * buffer)130 int CoreCodegen::grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
131                                               grpc_byte_buffer* buffer) {
132   return ::grpc_byte_buffer_reader_init(reader, buffer);
133 }
134 
grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader * reader)135 void CoreCodegen::grpc_byte_buffer_reader_destroy(
136     grpc_byte_buffer_reader* reader) {
137   ::grpc_byte_buffer_reader_destroy(reader);
138 }
139 
grpc_byte_buffer_reader_next(grpc_byte_buffer_reader * reader,grpc_slice * slice)140 int CoreCodegen::grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
141                                               grpc_slice* slice) {
142   return ::grpc_byte_buffer_reader_next(reader, slice);
143 }
144 
grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader * reader,grpc_slice ** slice)145 int CoreCodegen::grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader* reader,
146                                               grpc_slice** slice) {
147   return ::grpc_byte_buffer_reader_peek(reader, slice);
148 }
149 
grpc_raw_byte_buffer_create(grpc_slice * slice,size_t nslices)150 grpc_byte_buffer* CoreCodegen::grpc_raw_byte_buffer_create(grpc_slice* slice,
151                                                            size_t nslices) {
152   return ::grpc_raw_byte_buffer_create(slice, nslices);
153 }
154 
grpc_slice_new_with_user_data(void * p,size_t len,void (* destroy)(void *),void * user_data)155 grpc_slice CoreCodegen::grpc_slice_new_with_user_data(void* p, size_t len,
156                                                       void (*destroy)(void*),
157                                                       void* user_data) {
158   return ::grpc_slice_new_with_user_data(p, len, destroy, user_data);
159 }
160 
grpc_slice_new_with_len(void * p,size_t len,void (* destroy)(void *,size_t))161 grpc_slice CoreCodegen::grpc_slice_new_with_len(void* p, size_t len,
162                                                 void (*destroy)(void*,
163                                                                 size_t)) {
164   return ::grpc_slice_new_with_len(p, len, destroy);
165 }
166 
grpc_empty_slice()167 grpc_slice CoreCodegen::grpc_empty_slice() { return ::grpc_empty_slice(); }
168 
grpc_slice_malloc(size_t length)169 grpc_slice CoreCodegen::grpc_slice_malloc(size_t length) {
170   return ::grpc_slice_malloc(length);
171 }
172 
grpc_slice_unref(grpc_slice slice)173 void CoreCodegen::grpc_slice_unref(grpc_slice slice) {
174   ::grpc_slice_unref(slice);
175 }
176 
grpc_slice_ref(grpc_slice slice)177 grpc_slice CoreCodegen::grpc_slice_ref(grpc_slice slice) {
178   return ::grpc_slice_ref(slice);
179 }
180 
grpc_slice_split_tail(grpc_slice * s,size_t split)181 grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) {
182   return ::grpc_slice_split_tail(s, split);
183 }
184 
grpc_slice_split_head(grpc_slice * s,size_t split)185 grpc_slice CoreCodegen::grpc_slice_split_head(grpc_slice* s, size_t split) {
186   return ::grpc_slice_split_head(s, split);
187 }
188 
grpc_slice_sub(grpc_slice s,size_t begin,size_t end)189 grpc_slice CoreCodegen::grpc_slice_sub(grpc_slice s, size_t begin, size_t end) {
190   return ::grpc_slice_sub(s, begin, end);
191 }
192 
grpc_slice_from_static_buffer(const void * buffer,size_t length)193 grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer,
194                                                       size_t length) {
195   return ::grpc_slice_from_static_buffer(buffer, length);
196 }
197 
grpc_slice_from_copied_buffer(const void * buffer,size_t length)198 grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer,
199                                                       size_t length) {
200   return ::grpc_slice_from_copied_buffer(static_cast<const char*>(buffer),
201                                          length);
202 }
203 
grpc_slice_buffer_add(grpc_slice_buffer * sb,grpc_slice slice)204 void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb,
205                                         grpc_slice slice) {
206   ::grpc_slice_buffer_add(sb, slice);
207 }
208 
grpc_slice_buffer_pop(grpc_slice_buffer * sb)209 void CoreCodegen::grpc_slice_buffer_pop(grpc_slice_buffer* sb) {
210   ::grpc_slice_buffer_pop(sb);
211 }
212 
grpc_metadata_array_init(grpc_metadata_array * array)213 void CoreCodegen::grpc_metadata_array_init(grpc_metadata_array* array) {
214   ::grpc_metadata_array_init(array);
215 }
216 
grpc_metadata_array_destroy(grpc_metadata_array * array)217 void CoreCodegen::grpc_metadata_array_destroy(grpc_metadata_array* array) {
218   ::grpc_metadata_array_destroy(array);
219 }
220 
ok()221 const Status& CoreCodegen::ok() { return grpc::Status::OK; }
222 
cancelled()223 const Status& CoreCodegen::cancelled() { return grpc::Status::CANCELLED; }
224 
gpr_inf_future(gpr_clock_type type)225 gpr_timespec CoreCodegen::gpr_inf_future(gpr_clock_type type) {
226   return ::gpr_inf_future(type);
227 }
228 
gpr_time_0(gpr_clock_type type)229 gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) {
230   return ::gpr_time_0(type);
231 }
232 
assert_fail(const char * failed_assertion,const char * file,int line)233 void CoreCodegen::assert_fail(const char* failed_assertion, const char* file,
234                               int line) {
235   gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s",
236           failed_assertion);
237   abort();
238 }
239 
240 }  // namespace grpc
241