Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 3 | * Copyright 2015 gRPC authors. |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 4 | * |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [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 |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 8 | * |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 10 | * |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [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. |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H |
| 20 | #define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H |
| 21 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 22 | #include <memory> |
| 23 | #include <vector> |
| 24 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 25 | #include "src/compiler/config.h" |
| 26 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 27 | #ifndef GRPC_CUSTOM_STRING |
| 28 | # include <string> |
| 29 | # define GRPC_CUSTOM_STRING std::string |
| 30 | #endif |
| 31 | |
| 32 | namespace grpc { |
| 33 | |
| 34 | typedef GRPC_CUSTOM_STRING string; |
| 35 | |
| 36 | } // namespace grpc |
| 37 | |
| 38 | namespace grpc_generator { |
| 39 | |
| 40 | // A common interface for objects having comments in the source. |
| 41 | // Return formatted comments to be inserted in generated code. |
| 42 | struct CommentHolder { |
| 43 | virtual ~CommentHolder() {} |
| 44 | virtual grpc::string GetLeadingComments(const grpc::string prefix) const = 0; |
| 45 | virtual grpc::string GetTrailingComments(const grpc::string prefix) const = 0; |
| 46 | virtual std::vector<grpc::string> GetAllComments() const = 0; |
| 47 | }; |
| 48 | |
| 49 | // An abstract interface representing a method. |
| 50 | struct Method : public CommentHolder { |
| 51 | virtual ~Method() {} |
| 52 | |
| 53 | virtual grpc::string name() const = 0; |
| 54 | |
| 55 | virtual grpc::string input_type_name() const = 0; |
| 56 | virtual grpc::string output_type_name() const = 0; |
| 57 | |
| 58 | virtual bool get_module_and_message_path_input( |
| 59 | grpc::string *str, grpc::string generator_file_name, |
| 60 | bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0; |
| 61 | virtual bool get_module_and_message_path_output( |
| 62 | grpc::string *str, grpc::string generator_file_name, |
| 63 | bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0; |
| 64 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 65 | virtual std::vector<grpc::string> get_input_namespace_parts() const = 0; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 66 | virtual grpc::string get_input_type_name() const = 0; |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 67 | virtual std::vector<grpc::string> get_output_namespace_parts() const = 0; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 68 | virtual grpc::string get_output_type_name() const = 0; |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 69 | |
| 70 | virtual grpc::string get_fb_builder() const = 0; |
| 71 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 72 | virtual bool NoStreaming() const = 0; |
| 73 | virtual bool ClientStreaming() const = 0; |
| 74 | virtual bool ServerStreaming() const = 0; |
| 75 | virtual bool BidiStreaming() const = 0; |
| 76 | }; |
| 77 | |
| 78 | // An abstract interface representing a service. |
| 79 | struct Service : public CommentHolder { |
| 80 | virtual ~Service() {} |
| 81 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 82 | virtual std::vector<grpc::string> namespace_parts() const = 0; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 83 | virtual grpc::string name() const = 0; |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 84 | virtual bool is_internal() const = 0; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 85 | |
| 86 | virtual int method_count() const = 0; |
| 87 | virtual std::unique_ptr<const Method> method(int i) const = 0; |
| 88 | }; |
| 89 | |
| 90 | struct Printer { |
| 91 | virtual ~Printer() {} |
| 92 | |
| 93 | virtual void Print(const std::map<grpc::string, grpc::string> &vars, |
| 94 | const char *template_string) = 0; |
| 95 | virtual void Print(const char *string) = 0; |
| 96 | virtual void Indent() = 0; |
| 97 | virtual void Outdent() = 0; |
| 98 | }; |
| 99 | |
| 100 | // An interface that allows the source generated to be output using various |
| 101 | // libraries/idls/serializers. |
| 102 | struct File : public CommentHolder { |
| 103 | virtual ~File() {} |
| 104 | |
| 105 | virtual grpc::string filename() const = 0; |
| 106 | virtual grpc::string filename_without_ext() const = 0; |
| 107 | virtual grpc::string package() const = 0; |
| 108 | virtual std::vector<grpc::string> package_parts() const = 0; |
| 109 | virtual grpc::string additional_headers() const = 0; |
| 110 | |
| 111 | virtual int service_count() const = 0; |
| 112 | virtual std::unique_ptr<const Service> service(int i) const = 0; |
| 113 | |
| 114 | virtual std::unique_ptr<Printer> CreatePrinter(grpc::string *str) const = 0; |
| 115 | }; |
| 116 | } // namespace grpc_generator |
| 117 | |
| 118 | #endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H |