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_PYTHON_PRIVATE_GENERATOR_H |
20 | #define GRPC_INTERNAL_COMPILER_PYTHON_PRIVATE_GENERATOR_H |
21 | |
22 | #include <iostream> |
23 | #include <vector> |
24 | |
25 | #include "src/compiler/python_generator.h" |
26 | #include "src/compiler/schema_interface.h" |
27 | |
28 | namespace grpc_python_generator { |
29 | |
30 | namespace { |
31 | |
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; |
39 | |
40 | bool generate_in_pb2_grpc; |
41 | |
42 | PrivateGenerator(const GeneratorConfiguration& config, |
43 | const grpc_generator::File* file); |
44 | |
45 | std::pair<bool, grpc::string> GetGrpcServices(); |
46 | |
47 | private: |
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); |
52 | |
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); |
61 | |
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); |
72 | |
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 (std::vector<grpc::string> , |
77 | grpc_generator::Printer* out); |
78 | }; |
79 | |
80 | } // namespace |
81 | |
82 | } // namespace grpc_python_generator |
83 | |
84 | #endif // GRPC_INTERNAL_COMPILER_PYTHON_PRIVATE_GENERATOR_H |
85 | |