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* 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 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 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 62 void CoreCodegen::grpc_completion_queue_destroy(grpc_completion_queue* cq) { 63 ::grpc_completion_queue_destroy(cq); 64 } 65 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 } 72 73 void* CoreCodegen::gpr_malloc(size_t size) { return ::gpr_malloc(size); } 74 75 void CoreCodegen::gpr_free(void* p) { return ::gpr_free(p); } 76 77 void CoreCodegen::grpc_init() { ::grpc_init(); } 78 void CoreCodegen::grpc_shutdown() { ::grpc_shutdown(); } 79 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 93 grpc_byte_buffer* CoreCodegen::grpc_byte_buffer_copy(grpc_byte_buffer* bb) { 94 return ::grpc_byte_buffer_copy(bb); 95 } 96 97 void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { 98 ::grpc_byte_buffer_destroy(bb); 99 } 100 101 size_t CoreCodegen::grpc_byte_buffer_length(grpc_byte_buffer* bb) { 102 return ::grpc_byte_buffer_length(bb); 103 } 104 105 grpc_call_error CoreCodegen::grpc_call_cancel_with_status( 106 grpc_call* call, grpc_status_code status, const char* description, 107 void* reserved) { 108 return ::grpc_call_cancel_with_status(call, status, description, reserved); 109 } 110 void CoreCodegen::grpc_call_ref(grpc_call* call) { ::grpc_call_ref(call); } 111 void CoreCodegen::grpc_call_unref(grpc_call* call) { ::grpc_call_unref(call); } 112 void* CoreCodegen::grpc_call_arena_alloc(grpc_call* call, size_t length) { 113 return ::grpc_call_arena_alloc(call, length); 114 } 115 116 int CoreCodegen::grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, 117 grpc_byte_buffer* buffer) { 118 return ::grpc_byte_buffer_reader_init(reader, buffer); 119 } 120 121 void CoreCodegen::grpc_byte_buffer_reader_destroy( 122 grpc_byte_buffer_reader* reader) { 123 ::grpc_byte_buffer_reader_destroy(reader); 124 } 125 126 int CoreCodegen::grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader, 127 grpc_slice* slice) { 128 return ::grpc_byte_buffer_reader_next(reader, slice); 129 } 130 131 grpc_byte_buffer* CoreCodegen::grpc_raw_byte_buffer_create(grpc_slice* slice, 132 size_t nslices) { 133 return ::grpc_raw_byte_buffer_create(slice, nslices); 134 } 135 136 grpc_slice CoreCodegen::grpc_slice_new_with_user_data(void* p, size_t len, 137 void (*destroy)(void*), 138 void* user_data) { 139 return ::grpc_slice_new_with_user_data(p, len, destroy, user_data); 140 } 141 142 grpc_slice CoreCodegen::grpc_slice_new_with_len(void* p, size_t len, 143 void (*destroy)(void*, 144 size_t)) { 145 return ::grpc_slice_new_with_len(p, len, destroy); 146 } 147 148 grpc_slice CoreCodegen::grpc_empty_slice() { return ::grpc_empty_slice(); } 149 150 grpc_slice CoreCodegen::grpc_slice_malloc(size_t length) { 151 return ::grpc_slice_malloc(length); 152 } 153 154 void CoreCodegen::grpc_slice_unref(grpc_slice slice) { 155 ::grpc_slice_unref(slice); 156 } 157 158 grpc_slice CoreCodegen::grpc_slice_ref(grpc_slice slice) { 159 return ::grpc_slice_ref(slice); 160 } 161 162 grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) { 163 return ::grpc_slice_split_tail(s, split); 164 } 165 166 grpc_slice CoreCodegen::grpc_slice_split_head(grpc_slice* s, size_t split) { 167 return ::grpc_slice_split_head(s, split); 168 } 169 170 grpc_slice CoreCodegen::grpc_slice_sub(grpc_slice s, size_t begin, size_t end) { 171 return ::grpc_slice_sub(s, begin, end); 172 } 173 174 grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer, 175 size_t length) { 176 return ::grpc_slice_from_static_buffer(buffer, length); 177 } 178 179 grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer, 180 size_t length) { 181 return ::grpc_slice_from_copied_buffer(static_cast<const char*>(buffer), 182 length); 183 } 184 185 void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, 186 grpc_slice slice) { 187 ::grpc_slice_buffer_add(sb, slice); 188 } 189 190 void CoreCodegen::grpc_slice_buffer_pop(grpc_slice_buffer* sb) { 191 ::grpc_slice_buffer_pop(sb); 192 } 193 194 void CoreCodegen::grpc_metadata_array_init(grpc_metadata_array* array) { 195 ::grpc_metadata_array_init(array); 196 } 197 198 void CoreCodegen::grpc_metadata_array_destroy(grpc_metadata_array* array) { 199 ::grpc_metadata_array_destroy(array); 200 } 201 202 const Status& CoreCodegen::ok() { return grpc::Status::OK; } 203 204 const Status& CoreCodegen::cancelled() { return grpc::Status::CANCELLED; } 205 206 gpr_timespec CoreCodegen::gpr_inf_future(gpr_clock_type type) { 207 return ::gpr_inf_future(type); 208 } 209 210 gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) { 211 return ::gpr_time_0(type); 212 } 213 214 void CoreCodegen::assert_fail(const char* failed_assertion, const char* file, 215 int line) { 216 gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s", 217 failed_assertion); 218 abort(); 219 } 220 221 } // namespace grpc 222