blob: e42e3e349e0ffe7d8650aa7c6a0d4fa4b047a52d [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001/*
2 *
Austin Schuh272c6132020-11-14 16:37:52 -08003 * Copyright 2015 gRPC authors.
Austin Schuhe89fa2d2019-08-14 20:24:23 -07004 *
Austin Schuh272c6132020-11-14 16:37:52 -08005 * 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 Schuhe89fa2d2019-08-14 20:24:23 -07008 *
Austin Schuh272c6132020-11-14 16:37:52 -08009 * http://www.apache.org/licenses/LICENSE-2.0
Austin Schuhe89fa2d2019-08-14 20:24:23 -070010 *
Austin Schuh272c6132020-11-14 16:37:52 -080011 * 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 Schuhe89fa2d2019-08-14 20:24:23 -070016 *
17 */
18
19#ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
20#define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
21
James Kuszmaul8e62b022022-03-22 09:33:25 -070022#include <map>
Austin Schuhe89fa2d2019-08-14 20:24:23 -070023#include <memory>
24#include <vector>
25
26#ifndef GRPC_CUSTOM_STRING
27# include <string>
28# define GRPC_CUSTOM_STRING std::string
29#endif
30
31namespace grpc {
32
33typedef GRPC_CUSTOM_STRING string;
34
35} // namespace grpc
36
37namespace grpc_generator {
38
39// A common interface for objects having comments in the source.
40// Return formatted comments to be inserted in generated code.
41struct CommentHolder {
42 virtual ~CommentHolder() {}
43 virtual grpc::string GetLeadingComments(const grpc::string prefix) const = 0;
44 virtual grpc::string GetTrailingComments(const grpc::string prefix) const = 0;
45 virtual std::vector<grpc::string> GetAllComments() const = 0;
46};
47
48// An abstract interface representing a method.
49struct Method : public CommentHolder {
50 virtual ~Method() {}
51
52 virtual grpc::string name() const = 0;
53
54 virtual grpc::string input_type_name() const = 0;
55 virtual grpc::string output_type_name() const = 0;
56
57 virtual bool get_module_and_message_path_input(
58 grpc::string *str, grpc::string generator_file_name,
59 bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
60 virtual bool get_module_and_message_path_output(
61 grpc::string *str, grpc::string generator_file_name,
62 bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
63
Austin Schuh272c6132020-11-14 16:37:52 -080064 virtual std::vector<grpc::string> get_input_namespace_parts() const = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070065 virtual grpc::string get_input_type_name() const = 0;
Austin Schuh272c6132020-11-14 16:37:52 -080066 virtual std::vector<grpc::string> get_output_namespace_parts() const = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070067 virtual grpc::string get_output_type_name() const = 0;
Austin Schuh272c6132020-11-14 16:37:52 -080068
69 virtual grpc::string get_fb_builder() const = 0;
70
Austin Schuhe89fa2d2019-08-14 20:24:23 -070071 virtual bool NoStreaming() const = 0;
72 virtual bool ClientStreaming() const = 0;
73 virtual bool ServerStreaming() const = 0;
74 virtual bool BidiStreaming() const = 0;
75};
76
77// An abstract interface representing a service.
78struct Service : public CommentHolder {
79 virtual ~Service() {}
80
Austin Schuh272c6132020-11-14 16:37:52 -080081 virtual std::vector<grpc::string> namespace_parts() const = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070082 virtual grpc::string name() const = 0;
Austin Schuh272c6132020-11-14 16:37:52 -080083 virtual bool is_internal() const = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070084
85 virtual int method_count() const = 0;
86 virtual std::unique_ptr<const Method> method(int i) const = 0;
87};
88
89struct Printer {
90 virtual ~Printer() {}
91
92 virtual void Print(const std::map<grpc::string, grpc::string> &vars,
93 const char *template_string) = 0;
94 virtual void Print(const char *string) = 0;
James Kuszmaul8e62b022022-03-22 09:33:25 -070095 virtual void SetIndentationSize(const size_t size) = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070096 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.
102struct 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;
James Kuszmaul8e62b022022-03-22 09:33:25 -0700110 virtual std::string message_header_ext() const = 0;
111 virtual std::string service_header_ext() const = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700112
113 virtual int service_count() const = 0;
114 virtual std::unique_ptr<const Service> service(int i) const = 0;
115
James Kuszmaul8e62b022022-03-22 09:33:25 -0700116 virtual std::unique_ptr<Printer> CreatePrinter(
117 grpc::string *str, const char indentation_type = ' ') const = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700118};
119} // namespace grpc_generator
120
121#endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H