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, std::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 std::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 std::string& package_qualified_service_name, 59 const grpc_generator::Service* service, 60 grpc_generator::Printer* out); 61 62 bool PrintServiceClass(const std::string& package_qualified_service_name, 63 const grpc_generator::Service* service, 64 grpc_generator::Printer* out); 65 bool PrintBetaServicer(const grpc_generator::Service* service, 66 grpc_generator::Printer* out); 67 bool PrintBetaServerFactory(const std::string& package_qualified_service_name, 68 const grpc_generator::Service* service, 69 grpc_generator::Printer* out); 70 bool PrintBetaStub(const grpc_generator::Service* service, 71 grpc_generator::Printer* out); 72 bool PrintBetaStubFactory(const std::string& package_qualified_service_name, 73 const grpc_generator::Service* service, 74 grpc_generator::Printer* out); 75 76 // Get all comments (leading, leading_detached, trailing) and print them as a 77 // docstring. Any leading space of a line will be removed, but the line 78 // wrapping will not be changed. 79 void PrintAllComments(std::vector<std::string> comments, 80 grpc_generator::Printer* out); 81 }; 82 83 } // namespace 84 85 } // namespace grpc_python_generator 86 87 #endif // GRPC_INTERNAL_COMPILER_PYTHON_PRIVATE_GENERATOR_H 88