1 /* 2 * 3 * Copyright 2015 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 GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H 20 #define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H 21 22 #include "src/compiler/config.h" 23 24 #include <memory> 25 #include <string> 26 #include <vector> 27 28 #ifdef GRPC_CUSTOM_STRING 29 #warning GRPC_CUSTOM_STRING is no longer supported. Please use std::string. 30 #endif 31 32 namespace grpc { 33 34 // Using grpc::string and grpc::to_string is discouraged in favor of 35 // std::string and std::to_string. This is only for legacy code using 36 // them explictly. 37 using std::string; // deprecated 38 using std::to_string; // deprecated 39 40 } // namespace grpc 41 42 namespace grpc_generator { 43 44 // A common interface for objects having comments in the source. 45 // Return formatted comments to be inserted in generated code. 46 struct CommentHolder { ~CommentHolderCommentHolder47 virtual ~CommentHolder() {} 48 virtual std::string GetLeadingComments(const std::string prefix) const = 0; 49 virtual std::string GetTrailingComments(const std::string prefix) const = 0; 50 virtual std::vector<std::string> GetAllComments() const = 0; 51 }; 52 53 // An abstract interface representing a method. 54 struct Method : public CommentHolder { ~MethodMethod55 virtual ~Method() {} 56 57 virtual std::string name() const = 0; 58 59 virtual std::string input_type_name() const = 0; 60 virtual std::string output_type_name() const = 0; 61 62 virtual bool get_module_and_message_path_input( 63 std::string* str, std::string generator_file_name, 64 bool generate_in_pb2_grpc, std::string import_prefix, 65 const std::vector<std::string>& prefixes_to_filter) const = 0; 66 virtual bool get_module_and_message_path_output( 67 std::string* str, std::string generator_file_name, 68 bool generate_in_pb2_grpc, std::string import_prefix, 69 const std::vector<std::string>& prefixes_to_filter) const = 0; 70 71 virtual std::string get_input_type_name() const = 0; 72 virtual std::string get_output_type_name() const = 0; 73 virtual bool NoStreaming() const = 0; 74 virtual bool ClientStreaming() const = 0; 75 virtual bool ServerStreaming() const = 0; 76 virtual bool BidiStreaming() const = 0; 77 }; 78 79 // An abstract interface representing a service. 80 struct Service : public CommentHolder { ~ServiceService81 virtual ~Service() {} 82 83 virtual std::string name() const = 0; 84 85 virtual int method_count() const = 0; 86 virtual std::unique_ptr<const Method> method(int i) const = 0; 87 }; 88 89 struct Printer { ~PrinterPrinter90 virtual ~Printer() {} 91 92 virtual void Print(const std::map<std::string, std::string>& vars, 93 const char* template_string) = 0; 94 virtual void Print(const char* string) = 0; 95 virtual void PrintRaw(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 { ~FileFile103 virtual ~File() {} 104 105 virtual std::string filename() const = 0; 106 virtual std::string filename_without_ext() const = 0; 107 virtual std::string package() const = 0; 108 virtual std::vector<std::string> package_parts() const = 0; 109 virtual std::string additional_headers() const = 0; GetImportNamesFile110 virtual std::vector<std::string> GetImportNames() const { return {}; } 111 112 virtual int service_count() const = 0; 113 virtual std::unique_ptr<const Service> service(int i) const = 0; 114 115 virtual std::unique_ptr<Printer> CreatePrinter(std::string* str) const = 0; 116 }; 117 } // namespace grpc_generator 118 119 #endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H 120