blob: 2b484c0a08ef07b59e23be3bcc4656306a90db02 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
David Garcia Quintas6848c4e2016-03-07 17:10:57 -08003 * Copyright 2016, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
David Garcia Quintasa20a2ad2016-05-19 10:53:44 -070034#include <grpc++/impl/codegen/core_codegen.h>
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080035
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080036#include <stdlib.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080037
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080038#include <grpc++/support/config.h>
Chilledheartbf5ec2f2015-03-10 01:20:18 +080039#include <grpc/byte_buffer.h>
David Garcia Quintas30bd4eb2015-06-01 21:08:59 -070040#include <grpc/byte_buffer_reader.h>
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080041#include <grpc/grpc.h>
Craig Tiller28b72422016-10-26 21:15:29 -070042#include <grpc/slice.h>
43#include <grpc/slice_buffer.h>
David Garcia Quintas6b114622016-07-27 14:49:53 -070044#include <grpc/support/alloc.h>
David Garcia Quintasc79b0652016-07-27 21:11:58 -070045#include <grpc/support/log.h>
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080046#include <grpc/support/port_platform.h>
David Garcia Quintas61887dc2016-07-27 23:17:34 -070047#include <grpc/support/sync.h>
Chilledheartbf5ec2f2015-03-10 01:20:18 +080048
Craig Tiller9533d042016-03-25 17:11:06 -070049#include "src/core/lib/profiling/timers.h"
Craig Tiller1f41b6b2015-10-09 15:07:02 -070050
David Garcia Quintas3b31fdf2016-07-27 18:17:12 -070051extern "C" {
52struct grpc_byte_buffer;
53}
54
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080055namespace grpc {
56
Craig Tiller75bfb972017-04-11 17:55:12 -070057const grpc_completion_queue_factory*
58CoreCodegen::grpc_completion_queue_factory_lookup(
59 const grpc_completion_queue_attributes* attributes) {
60 return ::grpc_completion_queue_factory_lookup(attributes);
61}
62
63grpc_completion_queue* CoreCodegen::grpc_completion_queue_create(
64 const grpc_completion_queue_factory* factory,
65 const grpc_completion_queue_attributes* attributes, void* reserved) {
66 return ::grpc_completion_queue_create(factory, attributes, reserved);
67}
68
Sree Kuchibhotlaf2c32152017-03-22 03:01:24 -070069grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_next(
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080070 void* reserved) {
Sree Kuchibhotlaf2c32152017-03-22 03:01:24 -070071 return ::grpc_completion_queue_create_for_next(reserved);
72}
73
74grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_pluck(
75 void* reserved) {
76 return ::grpc_completion_queue_create_for_pluck(reserved);
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080077}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080078
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080079void CoreCodegen::grpc_completion_queue_destroy(grpc_completion_queue* cq) {
80 ::grpc_completion_queue_destroy(cq);
81}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080082
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080083grpc_event CoreCodegen::grpc_completion_queue_pluck(grpc_completion_queue* cq,
84 void* tag,
85 gpr_timespec deadline,
86 void* reserved) {
87 return ::grpc_completion_queue_pluck(cq, tag, deadline, reserved);
88}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080089
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080090void* CoreCodegen::gpr_malloc(size_t size) { return ::gpr_malloc(size); }
David Garcia Quintase1ce31e2016-03-07 18:19:12 -080091
David Garcia Quintas8c3d9942016-03-08 00:07:14 -080092void CoreCodegen::gpr_free(void* p) { return ::gpr_free(p); }
David Garcia Quintas6848c4e2016-03-07 17:10:57 -080093
David Garcia Quintas61887dc2016-07-27 23:17:34 -070094void CoreCodegen::gpr_mu_init(gpr_mu* mu) { ::gpr_mu_init(mu); };
95void CoreCodegen::gpr_mu_destroy(gpr_mu* mu) { ::gpr_mu_destroy(mu); }
96void CoreCodegen::gpr_mu_lock(gpr_mu* mu) { ::gpr_mu_lock(mu); }
97void CoreCodegen::gpr_mu_unlock(gpr_mu* mu) { ::gpr_mu_unlock(mu); }
98void CoreCodegen::gpr_cv_init(gpr_cv* cv) { ::gpr_cv_init(cv); }
99void CoreCodegen::gpr_cv_destroy(gpr_cv* cv) { ::gpr_cv_destroy(cv); }
100int CoreCodegen::gpr_cv_wait(gpr_cv* cv, gpr_mu* mu,
101 gpr_timespec abs_deadline) {
102 return ::gpr_cv_wait(cv, mu, abs_deadline);
103}
104void CoreCodegen::gpr_cv_signal(gpr_cv* cv) { ::gpr_cv_signal(cv); }
105void CoreCodegen::gpr_cv_broadcast(gpr_cv* cv) { ::gpr_cv_broadcast(cv); }
106
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800107void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) {
108 ::grpc_byte_buffer_destroy(bb);
109}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800110
Craig Tiller66051c62017-03-31 09:16:35 -0700111void CoreCodegen::grpc_call_ref(grpc_call* call) { ::grpc_call_ref(call); }
112void CoreCodegen::grpc_call_unref(grpc_call* call) { ::grpc_call_unref(call); }
Craig Tillerfa416cb2017-04-05 15:14:30 -0700113void* CoreCodegen::grpc_call_arena_alloc(grpc_call* call, size_t length) {
114 return ::grpc_call_arena_alloc(call, length);
115}
Craig Tiller66051c62017-03-31 09:16:35 -0700116
David Garcia Quintas6721d4f2016-06-30 17:17:23 -0700117int CoreCodegen::grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
118 grpc_byte_buffer* buffer) {
119 return ::grpc_byte_buffer_reader_init(reader, buffer);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700120}
121
122void CoreCodegen::grpc_byte_buffer_reader_destroy(
123 grpc_byte_buffer_reader* reader) {
124 ::grpc_byte_buffer_reader_destroy(reader);
125}
126
127int CoreCodegen::grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
Craig Tillerd41a4a72016-10-26 16:16:06 -0700128 grpc_slice* slice) {
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700129 return ::grpc_byte_buffer_reader_next(reader, slice);
130}
131
Craig Tillerd41a4a72016-10-26 16:16:06 -0700132grpc_byte_buffer* CoreCodegen::grpc_raw_byte_buffer_create(grpc_slice* slice,
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700133 size_t nslices) {
134 return ::grpc_raw_byte_buffer_create(slice, nslices);
135}
136
ncteisene107b0d2017-04-19 14:01:13 -0700137grpc_slice CoreCodegen::grpc_slice_new_with_user_data(void* p, size_t len,
138 void (*destroy)(void*),
139 void* user_data) {
140 return ::grpc_slice_new_with_user_data(p, len, destroy, user_data);
141}
142
Craig Tillerbe094fc2017-04-04 09:31:28 -0700143grpc_slice CoreCodegen::grpc_empty_slice() { return ::grpc_empty_slice(); }
144
Craig Tillerd41a4a72016-10-26 16:16:06 -0700145grpc_slice CoreCodegen::grpc_slice_malloc(size_t length) {
146 return ::grpc_slice_malloc(length);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700147}
148
Craig Tiller28b72422016-10-26 21:15:29 -0700149void CoreCodegen::grpc_slice_unref(grpc_slice slice) {
150 ::grpc_slice_unref(slice);
151}
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700152
ncteisene107b0d2017-04-19 14:01:13 -0700153grpc_slice CoreCodegen::grpc_slice_ref(grpc_slice slice) {
154 return ::grpc_slice_ref(slice);
155}
156
Craig Tillerd41a4a72016-10-26 16:16:06 -0700157grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) {
158 return ::grpc_slice_split_tail(s, split);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700159}
160
ncteisene107b0d2017-04-19 14:01:13 -0700161grpc_slice CoreCodegen::grpc_slice_split_head(grpc_slice* s, size_t split) {
162 return ::grpc_slice_split_head(s, split);
163}
164
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800165grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer,
166 size_t length) {
167 return ::grpc_slice_from_static_buffer(buffer, length);
168}
169
170grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer,
171 size_t length) {
172 return ::grpc_slice_from_copied_buffer(static_cast<const char*>(buffer),
173 length);
174}
175
Craig Tiller28b72422016-10-26 21:15:29 -0700176void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb,
177 grpc_slice slice) {
Craig Tillerd41a4a72016-10-26 16:16:06 -0700178 ::grpc_slice_buffer_add(sb, slice);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700179}
180
Craig Tillerd41a4a72016-10-26 16:16:06 -0700181void CoreCodegen::grpc_slice_buffer_pop(grpc_slice_buffer* sb) {
182 ::grpc_slice_buffer_pop(sb);
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700183}
184
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800185void CoreCodegen::grpc_metadata_array_init(grpc_metadata_array* array) {
186 ::grpc_metadata_array_init(array);
187}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800188
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800189void CoreCodegen::grpc_metadata_array_destroy(grpc_metadata_array* array) {
190 ::grpc_metadata_array_destroy(array);
191}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800192
David Garcia Quintas1b2db632016-04-27 15:06:54 -0700193const Status& CoreCodegen::ok() { return grpc::Status::OK; }
194
195const Status& CoreCodegen::cancelled() { return grpc::Status::CANCELLED; }
196
David Garcia Quintasef6848f2016-03-08 16:05:30 -0800197gpr_timespec CoreCodegen::gpr_inf_future(gpr_clock_type type) {
198 return ::gpr_inf_future(type);
199}
200
David Garcia Quintas1399e462016-07-27 20:31:55 -0700201gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) {
202 return ::gpr_time_0(type);
203}
204
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800205void CoreCodegen::assert_fail(const char* failed_assertion, const char* file,
206 int line) {
207 gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s",
208 failed_assertion);
David Garcia Quintas8c3d9942016-03-08 00:07:14 -0800209 abort();
210}
David Garcia Quintas6848c4e2016-03-07 17:10:57 -0800211
Craig Tiller190d3602015-02-18 09:23:38 -0800212} // namespace grpc