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_PYTHON_PRIVATE_GENERATOR_H
20 #define GRPC_INTERNAL_COMPILER_PYTHON_PRIVATE_GENERATOR_H
25 #include "src/compiler/python_generator.h"
26 #include "src/compiler/schema_interface.h"
28 namespace grpc_python_generator {
32 // Tucks all generator state in an anonymous namespace away from
33 // PythonGrpcGenerator and the header file, mostly to encourage future changes
34 // to not require updates to the grpcio-tools C++ code part. Assumes that it is
35 // only ever used from a single thread.
36 struct PrivateGenerator {
37 const GeneratorConfiguration& config;
38 const grpc_generator::File* file;
40 bool generate_in_pb2_grpc;
42 PrivateGenerator(const GeneratorConfiguration& config,
43 const grpc_generator::File* file);
45 std::pair<bool, grpc::string> GetGrpcServices();
48 bool PrintPreamble(grpc_generator::Printer* out);
49 bool PrintBetaPreamble(grpc_generator::Printer* out);
50 bool PrintGAServices(grpc_generator::Printer* out);
51 bool PrintBetaServices(grpc_generator::Printer* out);
53 bool PrintAddServicerToServer(
54 const grpc::string& package_qualified_service_name,
55 const grpc_generator::Service* service, grpc_generator::Printer* out);
56 bool PrintServicer(const grpc_generator::Service* service,
57 grpc_generator::Printer* out);
58 bool PrintStub(const grpc::string& package_qualified_service_name,
59 const grpc_generator::Service* service,
60 grpc_generator::Printer* out);
62 bool PrintBetaServicer(const grpc_generator::Service* service,
63 grpc_generator::Printer* out);
64 bool PrintBetaServerFactory(
65 const grpc::string& package_qualified_service_name,
66 const grpc_generator::Service* service, grpc_generator::Printer* out);
67 bool PrintBetaStub(const grpc_generator::Service* service,
68 grpc_generator::Printer* out);
69 bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
70 const grpc_generator::Service* service,
71 grpc_generator::Printer* out);
73 // Get all comments (leading, leading_detached, trailing) and print them as a
74 // docstring. Any leading space of a line will be removed, but the line
75 // wrapping will not be changed.
76 void PrintAllComments(std::vector<grpc::string> comments,
77 grpc_generator::Printer* out);
82 } // namespace grpc_python_generator
84 #endif // GRPC_INTERNAL_COMPILER_PYTHON_PRIVATE_GENERATOR_H