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 // Tucks all generator state in an anonymous namespace away from
31 // PythonGrpcGenerator and the header file, mostly to encourage future changes
32 // to not require updates to the grpcio-tools C++ code part. Assumes that it is
33 // only ever used from a single thread.
34 struct PrivateGenerator {
35   const GeneratorConfiguration& config;
36   const grpc_generator::File* file;
37 
38   PrivateGenerator(const GeneratorConfiguration& config,
39                    const grpc_generator::File* file);
40 
41   grpc::string GetGrpcServices();
42 
43  private:
44   void PrintPreamble(grpc_generator::Printer* out);
45   void PrintBetaPreamble(grpc_generator::Printer* out);
46   void PrintGAServices(grpc_generator::Printer* out);
47   void PrintBetaServices(grpc_generator::Printer* out);
48 
49   void PrintAddServicerToServer(
50       const grpc::string& package_qualified_service_name,
51       const grpc_generator::Service* service, grpc_generator::Printer* out);
52   void PrintServicer(const grpc_generator::Service* service,
53                      grpc_generator::Printer* out);
54   void PrintStub(const grpc::string& package_qualified_service_name,
55                  const grpc_generator::Service* service,
56                  grpc_generator::Printer* out);
57 
58   void PrintBetaServicer(const grpc_generator::Service* service,
59                          grpc_generator::Printer* out);
60   void PrintBetaServerFactory(
61       const grpc::string& package_qualified_service_name,
62       const grpc_generator::Service* service, grpc_generator::Printer* out);
63   void PrintBetaStub(const grpc_generator::Service* service,
64                      grpc_generator::Printer* out);
65   void PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
66                             const grpc_generator::Service* service,
67                             grpc_generator::Printer* out);
68 };
69 
70 }  // namespace grpc_python_generator
71 
72 #endif  // GRPC_INTERNAL_COMPILER_PYTHON_PRIVATE_GENERATOR_H
73