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