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