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 #ifndef GRPCPP_IMPL_CODEGEN_CORE_CODEGEN_H
20 #define GRPCPP_IMPL_CODEGEN_CORE_CODEGEN_H
21 
22 // This file should be compiled as part of grpcpp.
23 
24 #include <grpc/byte_buffer.h>
25 #include <grpc/grpc.h>
26 #include <grpc/impl/codegen/grpc_types.h>
27 #include <grpcpp/impl/codegen/core_codegen_interface.h>
28 
29 namespace grpc {
30 
31 /// Implementation of the core codegen interface.
32 class CoreCodegen final : public CoreCodegenInterface {
33  private:
34   virtual const grpc_completion_queue_factory*
35   grpc_completion_queue_factory_lookup(
36       const grpc_completion_queue_attributes* attributes) override;
37   virtual grpc_completion_queue* grpc_completion_queue_create(
38       const grpc_completion_queue_factory* factory,
39       const grpc_completion_queue_attributes* attributes,
40       void* reserved) override;
41   grpc_completion_queue* grpc_completion_queue_create_for_next(
42       void* reserved) override;
43   grpc_completion_queue* grpc_completion_queue_create_for_pluck(
44       void* reserved) override;
45   void grpc_completion_queue_destroy(grpc_completion_queue* cq) override;
46   grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag,
47                                          gpr_timespec deadline,
48                                          void* reserved) override;
49 
50   void* gpr_malloc(size_t size) override;
51   void gpr_free(void* p) override;
52 
53   void grpc_init() override;
54   void grpc_shutdown() override;
55 
56   void gpr_mu_init(gpr_mu* mu) override;
57   void gpr_mu_destroy(gpr_mu* mu) override;
58   void gpr_mu_lock(gpr_mu* mu) override;
59   void gpr_mu_unlock(gpr_mu* mu) override;
60   void gpr_cv_init(gpr_cv* cv) override;
61   void gpr_cv_destroy(gpr_cv* cv) override;
62   int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) override;
63   void gpr_cv_signal(gpr_cv* cv) override;
64   void gpr_cv_broadcast(gpr_cv* cv) override;
65 
66   grpc_call_error grpc_call_cancel_with_status(grpc_call* call,
67                                                grpc_status_code status,
68                                                const char* description,
69                                                void* reserved) override;
70   void grpc_call_ref(grpc_call* call) override;
71   void grpc_call_unref(grpc_call* call) override;
72   virtual void* grpc_call_arena_alloc(grpc_call* call, size_t length) override;
73 
74   grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) override;
75   void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override;
76   size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) override;
77 
78   int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
79                                    grpc_byte_buffer* buffer) override;
80   void grpc_byte_buffer_reader_destroy(
81       grpc_byte_buffer_reader* reader) override;
82   int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
83                                    grpc_slice* slice) override;
84 
85   grpc_byte_buffer* grpc_raw_byte_buffer_create(grpc_slice* slice,
86                                                 size_t nslices) override;
87   grpc_slice grpc_slice_new_with_user_data(void* p, size_t len,
88                                            void (*destroy)(void*),
89                                            void* user_data) override;
90   grpc_slice grpc_slice_new_with_len(void* p, size_t len,
91                                      void (*destroy)(void*, size_t)) override;
92   grpc_slice grpc_empty_slice() override;
93   grpc_slice grpc_slice_malloc(size_t length) override;
94   void grpc_slice_unref(grpc_slice slice) override;
95   grpc_slice grpc_slice_ref(grpc_slice slice) override;
96   grpc_slice grpc_slice_split_tail(grpc_slice* s, size_t split) override;
97   grpc_slice grpc_slice_split_head(grpc_slice* s, size_t split) override;
98   grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end) override;
99   void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) override;
100   void grpc_slice_buffer_pop(grpc_slice_buffer* sb) override;
101   grpc_slice grpc_slice_from_static_buffer(const void* buffer,
102                                            size_t length) override;
103   grpc_slice grpc_slice_from_copied_buffer(const void* buffer,
104                                            size_t length) override;
105   void grpc_metadata_array_init(grpc_metadata_array* array) override;
106   void grpc_metadata_array_destroy(grpc_metadata_array* array) override;
107 
108   gpr_timespec gpr_inf_future(gpr_clock_type type) override;
109   gpr_timespec gpr_time_0(gpr_clock_type type) override;
110 
111   virtual const Status& ok() override;
112   virtual const Status& cancelled() override;
113 
114   void assert_fail(const char* failed_assertion, const char* file,
115                    int line) override;
116 };
117 
118 }  // namespace grpc
119 
120 #endif  // GRPCPP_IMPL_CODEGEN_CORE_CODEGEN_H
121