blob: 936d6996b267e00bd079f0536ed7eafebda61091 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2016 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
David Garcia Quintasa20a2ad2016-05-19 10:53:44 -070019#include <grpc++/impl/codegen/core_codegen.h>
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080020
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080021#include <stdlib.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080022
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080023#include <grpc++/support/config.h>
Chilledheartbf5ec2f2015-03-10 01:20:18 +080024#include <grpc/byte_buffer.h>
David Garcia Quintas30bd4eb2015-06-01 21:08:59 -070025#include <grpc/byte_buffer_reader.h>
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080026#include <grpc/grpc.h>
Craig Tiller28b72422016-10-26 21:15:29 -070027#include <grpc/slice.h>
28#include <grpc/slice_buffer.h>
David Garcia Quintas6b114622016-07-27 14:49:53 -070029#include <grpc/support/alloc.h>
David Garcia Quintasc79b0652016-07-27 21:11:58 -070030#include <grpc/support/log.h>
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080031#include <grpc/support/port_platform.h>
David Garcia Quintas61887dc2016-07-27 23:17:34 -070032#include <grpc/support/sync.h>
Chilledheartbf5ec2f2015-03-10 01:20:18 +080033
Craig Tiller9533d042016-03-25 17:11:06 -070034#include "src/core/lib/profiling/timers.h"
Craig Tiller1f41b6b2015-10-09 15:07:02 -070035
David Garcia Quintas3b31fdf2016-07-27 18:17:12 -070036struct grpc_byte_buffer;
David Garcia Quintas3b31fdf2016-07-27 18:17:12 -070037
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038namespace grpc {
39
Craig Tiller75bfb972017-04-11 17:55:12 -070040const grpc_completion_queue_factory*
41CoreCodegen::grpc_completion_queue_factory_lookup(
42 const grpc_completion_queue_attributes* attributes) {
43 return ::grpc_completion_queue_factory_lookup(attributes);
44}
45
46grpc_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
Sree Kuchibhotlaf2c32152017-03-22 03:01:24 -070052grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_next(
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080053 void* reserved) {
Sree Kuchibhotlaf2c32152017-03-22 03:01:24 -070054 return ::grpc_completion_queue_create_for_next(reserved);
55}
56
57grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_pluck(
58 void* reserved) {
59 return ::grpc_completion_queue_create_for_pluck(reserved);
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080060}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080061
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080062void CoreCodegen::grpc_completion_queue_destroy(grpc_completion_queue* cq) {
63 ::grpc_completion_queue_destroy(cq);
64}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080065
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080066grpc_event CoreCodegen::grpc_completion_queue_pluck(grpc_completion_queue* cq,
67 void* tag,
68 gpr_timespec deadline,
69 void* reserved) {
70 return ::grpc_completion_queue_pluck(cq, tag, deadline, reserved);
71}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080072
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080073void* CoreCodegen::gpr_malloc(size_t size) { return ::gpr_malloc(size); }
David Garcia Quintase1ce31e2016-03-07 18:19:12 -080074
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080075void CoreCodegen::gpr_free(void* p) { return ::gpr_free(p); }
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080076
ncteisenf97d2f52017-11-06 17:49:57 -080077void CoreCodegen::grpc_init() { ::grpc_init(); }
78void CoreCodegen::grpc_shutdown() { ::grpc_shutdown(); }
79
David Garcia Quintas61887dc2016-07-27 23:17:34 -070080void CoreCodegen::gpr_mu_init(gpr_mu* mu) { ::gpr_mu_init(mu); };
81void CoreCodegen::gpr_mu_destroy(gpr_mu* mu) { ::gpr_mu_destroy(mu); }
82void CoreCodegen::gpr_mu_lock(gpr_mu* mu) { ::gpr_mu_lock(mu); }
83void CoreCodegen::gpr_mu_unlock(gpr_mu* mu) { ::gpr_mu_unlock(mu); }
84void CoreCodegen::gpr_cv_init(gpr_cv* cv) { ::gpr_cv_init(cv); }
85void CoreCodegen::gpr_cv_destroy(gpr_cv* cv) { ::gpr_cv_destroy(cv); }
86int CoreCodegen::gpr_cv_wait(gpr_cv* cv, gpr_mu* mu,
87 gpr_timespec abs_deadline) {
88 return ::gpr_cv_wait(cv, mu, abs_deadline);
89}
90void CoreCodegen::gpr_cv_signal(gpr_cv* cv) { ::gpr_cv_signal(cv); }
91void CoreCodegen::gpr_cv_broadcast(gpr_cv* cv) { ::gpr_cv_broadcast(cv); }
92
Ken Payson47543982017-08-30 08:31:38 -070093grpc_byte_buffer* CoreCodegen::grpc_byte_buffer_copy(grpc_byte_buffer* bb) {
Ken Payson567e0f12017-08-29 09:21:22 -070094 return ::grpc_byte_buffer_copy(bb);
95}
96
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080097void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) {
98 ::grpc_byte_buffer_destroy(bb);
99}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800100
Mark D. Roth06966112017-07-14 07:18:39 -0700101grpc_call_error CoreCodegen::grpc_call_cancel_with_status(
102 grpc_call* call, grpc_status_code status, const char* description,
103 void* reserved) {
104 return ::grpc_call_cancel_with_status(call, status, description, reserved);
105}
Craig Tiller66051c62017-03-31 09:16:35 -0700106void CoreCodegen::grpc_call_ref(grpc_call* call) { ::grpc_call_ref(call); }
107void CoreCodegen::grpc_call_unref(grpc_call* call) { ::grpc_call_unref(call); }
Craig Tillerfa416cb2017-04-05 15:14:30 -0700108void* CoreCodegen::grpc_call_arena_alloc(grpc_call* call, size_t length) {
109 return ::grpc_call_arena_alloc(call, length);
110}
Craig Tiller66051c62017-03-31 09:16:35 -0700111
David Garcia Quintas6721d4f2016-06-30 17:17:23 -0700112int CoreCodegen::grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
113 grpc_byte_buffer* buffer) {
114 return ::grpc_byte_buffer_reader_init(reader, buffer);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700115}
116
117void CoreCodegen::grpc_byte_buffer_reader_destroy(
118 grpc_byte_buffer_reader* reader) {
119 ::grpc_byte_buffer_reader_destroy(reader);
120}
121
122int CoreCodegen::grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
Craig Tillerd41a4a72016-10-26 16:16:06 -0700123 grpc_slice* slice) {
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700124 return ::grpc_byte_buffer_reader_next(reader, slice);
125}
126
Craig Tillerd41a4a72016-10-26 16:16:06 -0700127grpc_byte_buffer* CoreCodegen::grpc_raw_byte_buffer_create(grpc_slice* slice,
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700128 size_t nslices) {
129 return ::grpc_raw_byte_buffer_create(slice, nslices);
130}
131
ncteisene107b0d2017-04-19 14:01:13 -0700132grpc_slice CoreCodegen::grpc_slice_new_with_user_data(void* p, size_t len,
133 void (*destroy)(void*),
134 void* user_data) {
135 return ::grpc_slice_new_with_user_data(p, len, destroy, user_data);
136}
137
Craig Tillerbe094fc2017-04-04 09:31:28 -0700138grpc_slice CoreCodegen::grpc_empty_slice() { return ::grpc_empty_slice(); }
139
Craig Tillerd41a4a72016-10-26 16:16:06 -0700140grpc_slice CoreCodegen::grpc_slice_malloc(size_t length) {
141 return ::grpc_slice_malloc(length);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700142}
143
Craig Tiller28b72422016-10-26 21:15:29 -0700144void CoreCodegen::grpc_slice_unref(grpc_slice slice) {
145 ::grpc_slice_unref(slice);
146}
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700147
ncteisene107b0d2017-04-19 14:01:13 -0700148grpc_slice CoreCodegen::grpc_slice_ref(grpc_slice slice) {
149 return ::grpc_slice_ref(slice);
150}
151
Craig Tillerd41a4a72016-10-26 16:16:06 -0700152grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) {
153 return ::grpc_slice_split_tail(s, split);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700154}
155
ncteisene107b0d2017-04-19 14:01:13 -0700156grpc_slice CoreCodegen::grpc_slice_split_head(grpc_slice* s, size_t split) {
157 return ::grpc_slice_split_head(s, split);
158}
159
ncteisen02372622017-10-31 13:13:03 -0700160grpc_slice CoreCodegen::grpc_slice_sub(grpc_slice s, size_t begin, size_t end) {
161 return ::grpc_slice_sub(s, begin, end);
162}
163
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800164grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer,
165 size_t length) {
166 return ::grpc_slice_from_static_buffer(buffer, length);
167}
168
169grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer,
170 size_t length) {
171 return ::grpc_slice_from_copied_buffer(static_cast<const char*>(buffer),
172 length);
173}
174
Craig Tiller28b72422016-10-26 21:15:29 -0700175void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb,
176 grpc_slice slice) {
Craig Tillerd41a4a72016-10-26 16:16:06 -0700177 ::grpc_slice_buffer_add(sb, slice);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700178}
179
Craig Tillerd41a4a72016-10-26 16:16:06 -0700180void CoreCodegen::grpc_slice_buffer_pop(grpc_slice_buffer* sb) {
181 ::grpc_slice_buffer_pop(sb);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700182}
183
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800184void CoreCodegen::grpc_metadata_array_init(grpc_metadata_array* array) {
185 ::grpc_metadata_array_init(array);
186}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800187
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800188void CoreCodegen::grpc_metadata_array_destroy(grpc_metadata_array* array) {
189 ::grpc_metadata_array_destroy(array);
190}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800191
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700192const Status& CoreCodegen::ok() { return grpc::Status::OK; }
193
194const Status& CoreCodegen::cancelled() { return grpc::Status::CANCELLED; }
195
David Garcia Quintasef6848f2016-03-08 16:05:30 -0800196gpr_timespec CoreCodegen::gpr_inf_future(gpr_clock_type type) {
197 return ::gpr_inf_future(type);
198}
199
David Garcia Quintas1399e462016-07-27 20:31:55 -0700200gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) {
201 return ::gpr_time_0(type);
202}
203
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800204void CoreCodegen::assert_fail(const char* failed_assertion, const char* file,
205 int line) {
206 gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s",
207 failed_assertion);
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800208 abort();
209}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800210
Craig Tiller190d3602015-02-18 09:23:38 -0800211} // namespace grpc