3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
20 #define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
22 #include "src/compiler/config.h"
27 #ifndef GRPC_CUSTOM_STRING
29 #define GRPC_CUSTOM_STRING std::string
34 typedef GRPC_CUSTOM_STRING string;
38 namespace grpc_generator {
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;
49 // An abstract interface representing a method.
50 struct Method : public CommentHolder {
53 virtual grpc::string name() const = 0;
55 virtual grpc::string input_type_name() const = 0;
56 virtual grpc::string output_type_name() const = 0;
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,
61 const std::vector<grpc::string>& prefixes_to_filter) const = 0;
62 virtual bool get_module_and_message_path_output(
63 grpc::string* str, grpc::string generator_file_name,
64 bool generate_in_pb2_grpc, grpc::string import_prefix,
65 const std::vector<grpc::string>& prefixes_to_filter) const = 0;
67 virtual grpc::string get_input_type_name() const = 0;
68 virtual grpc::string get_output_type_name() const = 0;
69 virtual bool NoStreaming() const = 0;
70 virtual bool ClientStreaming() const = 0;
71 virtual bool ServerStreaming() const = 0;
72 virtual bool BidiStreaming() const = 0;
75 // An abstract interface representing a service.
76 struct Service : public CommentHolder {
79 virtual grpc::string name() const = 0;
81 virtual int method_count() const = 0;
82 virtual std::unique_ptr<const Method> method(int i) const = 0;
88 virtual void Print(const std::map<grpc::string, grpc::string>& vars,
89 const char* template_string) = 0;
90 virtual void Print(const char* string) = 0;
91 virtual void PrintRaw(const char* string) = 0;
92 virtual void Indent() = 0;
93 virtual void Outdent() = 0;
96 // An interface that allows the source generated to be output using various
97 // libraries/idls/serializers.
98 struct File : public CommentHolder {
101 virtual grpc::string filename() const = 0;
102 virtual grpc::string filename_without_ext() const = 0;
103 virtual grpc::string package() const = 0;
104 virtual std::vector<grpc::string> package_parts() const = 0;
105 virtual grpc::string additional_headers() const = 0;
106 virtual std::vector<grpc::string> GetImportNames() const { return {}; }
108 virtual int service_count() const = 0;
109 virtual std::unique_ptr<const Service> service(int i) const = 0;
111 virtual std::unique_ptr<Printer> CreatePrinter(grpc::string* str) const = 0;
113 } // namespace grpc_generator
115 #endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H