Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 3 | * Copyright 2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * 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 Quintas | a20a2ad | 2016-05-19 10:53:44 -0700 | [diff] [blame] | 34 | #include <grpc++/impl/codegen/core_codegen.h> |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 35 | |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 36 | #include <stdlib.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 37 | |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 38 | #include <grpc++/support/config.h> |
Chilledheart | bf5ec2f | 2015-03-10 01:20:18 +0800 | [diff] [blame] | 39 | #include <grpc/byte_buffer.h> |
David Garcia Quintas | 30bd4eb | 2015-06-01 21:08:59 -0700 | [diff] [blame] | 40 | #include <grpc/byte_buffer_reader.h> |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 41 | #include <grpc/grpc.h> |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 42 | #include <grpc/slice.h> |
| 43 | #include <grpc/slice_buffer.h> |
David Garcia Quintas | 6b11462 | 2016-07-27 14:49:53 -0700 | [diff] [blame] | 44 | #include <grpc/support/alloc.h> |
David Garcia Quintas | c79b065 | 2016-07-27 21:11:58 -0700 | [diff] [blame] | 45 | #include <grpc/support/log.h> |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 46 | #include <grpc/support/port_platform.h> |
David Garcia Quintas | 61887dc | 2016-07-27 23:17:34 -0700 | [diff] [blame] | 47 | #include <grpc/support/sync.h> |
Chilledheart | bf5ec2f | 2015-03-10 01:20:18 +0800 | [diff] [blame] | 48 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 49 | #include "src/core/lib/profiling/timers.h" |
Craig Tiller | 1f41b6b | 2015-10-09 15:07:02 -0700 | [diff] [blame] | 50 | |
David Garcia Quintas | 3b31fdf | 2016-07-27 18:17:12 -0700 | [diff] [blame] | 51 | extern "C" { |
| 52 | struct grpc_byte_buffer; |
| 53 | } |
| 54 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 55 | namespace grpc { |
| 56 | |
Craig Tiller | 75bfb97 | 2017-04-11 17:55:12 -0700 | [diff] [blame] | 57 | const grpc_completion_queue_factory* |
| 58 | CoreCodegen::grpc_completion_queue_factory_lookup( |
| 59 | const grpc_completion_queue_attributes* attributes) { |
| 60 | return ::grpc_completion_queue_factory_lookup(attributes); |
| 61 | } |
| 62 | |
| 63 | grpc_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 Kuchibhotla | f2c3215 | 2017-03-22 03:01:24 -0700 | [diff] [blame] | 69 | grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_next( |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 70 | void* reserved) { |
Sree Kuchibhotla | f2c3215 | 2017-03-22 03:01:24 -0700 | [diff] [blame] | 71 | return ::grpc_completion_queue_create_for_next(reserved); |
| 72 | } |
| 73 | |
| 74 | grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_pluck( |
| 75 | void* reserved) { |
| 76 | return ::grpc_completion_queue_create_for_pluck(reserved); |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 77 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 78 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 79 | void CoreCodegen::grpc_completion_queue_destroy(grpc_completion_queue* cq) { |
| 80 | ::grpc_completion_queue_destroy(cq); |
| 81 | } |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 82 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 83 | grpc_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 Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 89 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 90 | void* CoreCodegen::gpr_malloc(size_t size) { return ::gpr_malloc(size); } |
David Garcia Quintas | e1ce31e | 2016-03-07 18:19:12 -0800 | [diff] [blame] | 91 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 92 | void CoreCodegen::gpr_free(void* p) { return ::gpr_free(p); } |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 93 | |
David Garcia Quintas | 61887dc | 2016-07-27 23:17:34 -0700 | [diff] [blame] | 94 | void CoreCodegen::gpr_mu_init(gpr_mu* mu) { ::gpr_mu_init(mu); }; |
| 95 | void CoreCodegen::gpr_mu_destroy(gpr_mu* mu) { ::gpr_mu_destroy(mu); } |
| 96 | void CoreCodegen::gpr_mu_lock(gpr_mu* mu) { ::gpr_mu_lock(mu); } |
| 97 | void CoreCodegen::gpr_mu_unlock(gpr_mu* mu) { ::gpr_mu_unlock(mu); } |
| 98 | void CoreCodegen::gpr_cv_init(gpr_cv* cv) { ::gpr_cv_init(cv); } |
| 99 | void CoreCodegen::gpr_cv_destroy(gpr_cv* cv) { ::gpr_cv_destroy(cv); } |
| 100 | int 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 | } |
| 104 | void CoreCodegen::gpr_cv_signal(gpr_cv* cv) { ::gpr_cv_signal(cv); } |
| 105 | void CoreCodegen::gpr_cv_broadcast(gpr_cv* cv) { ::gpr_cv_broadcast(cv); } |
| 106 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 107 | void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { |
| 108 | ::grpc_byte_buffer_destroy(bb); |
| 109 | } |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 110 | |
Craig Tiller | 66051c6 | 2017-03-31 09:16:35 -0700 | [diff] [blame] | 111 | void CoreCodegen::grpc_call_ref(grpc_call* call) { ::grpc_call_ref(call); } |
| 112 | void CoreCodegen::grpc_call_unref(grpc_call* call) { ::grpc_call_unref(call); } |
Craig Tiller | fa416cb | 2017-04-05 15:14:30 -0700 | [diff] [blame] | 113 | void* CoreCodegen::grpc_call_arena_alloc(grpc_call* call, size_t length) { |
| 114 | return ::grpc_call_arena_alloc(call, length); |
| 115 | } |
Craig Tiller | 66051c6 | 2017-03-31 09:16:35 -0700 | [diff] [blame] | 116 | |
David Garcia Quintas | 6721d4f | 2016-06-30 17:17:23 -0700 | [diff] [blame] | 117 | int 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 Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void CoreCodegen::grpc_byte_buffer_reader_destroy( |
| 123 | grpc_byte_buffer_reader* reader) { |
| 124 | ::grpc_byte_buffer_reader_destroy(reader); |
| 125 | } |
| 126 | |
| 127 | int CoreCodegen::grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader, |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 128 | grpc_slice* slice) { |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 129 | return ::grpc_byte_buffer_reader_next(reader, slice); |
| 130 | } |
| 131 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 132 | grpc_byte_buffer* CoreCodegen::grpc_raw_byte_buffer_create(grpc_slice* slice, |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 133 | size_t nslices) { |
| 134 | return ::grpc_raw_byte_buffer_create(slice, nslices); |
| 135 | } |
| 136 | |
ncteisen | e107b0d | 2017-04-19 14:01:13 -0700 | [diff] [blame] | 137 | grpc_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 Tiller | be094fc | 2017-04-04 09:31:28 -0700 | [diff] [blame] | 143 | grpc_slice CoreCodegen::grpc_empty_slice() { return ::grpc_empty_slice(); } |
| 144 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 145 | grpc_slice CoreCodegen::grpc_slice_malloc(size_t length) { |
| 146 | return ::grpc_slice_malloc(length); |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Craig Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 149 | void CoreCodegen::grpc_slice_unref(grpc_slice slice) { |
| 150 | ::grpc_slice_unref(slice); |
| 151 | } |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 152 | |
ncteisen | e107b0d | 2017-04-19 14:01:13 -0700 | [diff] [blame] | 153 | grpc_slice CoreCodegen::grpc_slice_ref(grpc_slice slice) { |
| 154 | return ::grpc_slice_ref(slice); |
| 155 | } |
| 156 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 157 | grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) { |
| 158 | return ::grpc_slice_split_tail(s, split); |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 159 | } |
| 160 | |
ncteisen | e107b0d | 2017-04-19 14:01:13 -0700 | [diff] [blame] | 161 | grpc_slice CoreCodegen::grpc_slice_split_head(grpc_slice* s, size_t split) { |
| 162 | return ::grpc_slice_split_head(s, split); |
| 163 | } |
| 164 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 165 | grpc_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 | |
| 170 | grpc_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 Tiller | 28b7242 | 2016-10-26 21:15:29 -0700 | [diff] [blame] | 176 | void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, |
| 177 | grpc_slice slice) { |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 178 | ::grpc_slice_buffer_add(sb, slice); |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 181 | void CoreCodegen::grpc_slice_buffer_pop(grpc_slice_buffer* sb) { |
| 182 | ::grpc_slice_buffer_pop(sb); |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 183 | } |
| 184 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 185 | void CoreCodegen::grpc_metadata_array_init(grpc_metadata_array* array) { |
| 186 | ::grpc_metadata_array_init(array); |
| 187 | } |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 188 | |
David Garcia Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 189 | void CoreCodegen::grpc_metadata_array_destroy(grpc_metadata_array* array) { |
| 190 | ::grpc_metadata_array_destroy(array); |
| 191 | } |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 192 | |
David Garcia Quintas | 1b2db63 | 2016-04-27 15:06:54 -0700 | [diff] [blame] | 193 | const Status& CoreCodegen::ok() { return grpc::Status::OK; } |
| 194 | |
| 195 | const Status& CoreCodegen::cancelled() { return grpc::Status::CANCELLED; } |
| 196 | |
David Garcia Quintas | ef6848f | 2016-03-08 16:05:30 -0800 | [diff] [blame] | 197 | gpr_timespec CoreCodegen::gpr_inf_future(gpr_clock_type type) { |
| 198 | return ::gpr_inf_future(type); |
| 199 | } |
| 200 | |
David Garcia Quintas | 1399e46 | 2016-07-27 20:31:55 -0700 | [diff] [blame] | 201 | gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) { |
| 202 | return ::gpr_time_0(type); |
| 203 | } |
| 204 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 205 | void 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 Quintas | 8c3d994 | 2016-03-08 00:07:14 -0800 | [diff] [blame] | 209 | abort(); |
| 210 | } |
David Garcia Quintas | 6848c4e | 2016-03-07 17:10:57 -0800 | [diff] [blame] | 211 | |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 212 | } // namespace grpc |