python_private_generator.h 3.1 KB

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