File indexing completed on 2025-01-31 10:11:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__
0013 #define GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__
0014
0015 #include <string>
0016
0017 #include "absl/container/flat_hash_map.h"
0018 #include "google/protobuf/compiler/cpp/options.h"
0019 #include "google/protobuf/descriptor.h"
0020 #include "google/protobuf/io/printer.h"
0021
0022 namespace google {
0023 namespace protobuf {
0024 namespace compiler {
0025 namespace cpp {
0026 class ServiceGenerator {
0027 public:
0028
0029 ServiceGenerator(
0030 const ServiceDescriptor* descriptor,
0031 const absl::flat_hash_map<absl::string_view, std::string>& vars,
0032 const Options& options)
0033 : descriptor_(descriptor), options_(&options), vars_(vars) {
0034 vars_["classname"] = descriptor_->name();
0035 vars_["full_name"] = descriptor_->full_name();
0036 }
0037
0038 ServiceGenerator(const ServiceGenerator&) = delete;
0039 ServiceGenerator& operator=(const ServiceGenerator&) = delete;
0040 ServiceGenerator(ServiceGenerator&&) = delete;
0041 ServiceGenerator& operator=(ServiceGenerator&&) = delete;
0042
0043 ~ServiceGenerator() = default;
0044
0045
0046
0047 void GenerateDeclarations(io::Printer* printer);
0048
0049
0050
0051 void GenerateImplementation(io::Printer* printer);
0052
0053 private:
0054 enum RequestOrResponse { kRequest, kResponse };
0055 enum VirtualOrNot { kVirtual, kNonVirtual };
0056
0057
0058 void GenerateMethodSignatures(VirtualOrNot virtual_or_not,
0059 io::Printer* printer);
0060
0061
0062
0063 void GenerateNotImplementedMethods(io::Printer* printer);
0064
0065
0066 void GenerateCallMethod(io::Printer* printer);
0067
0068
0069 void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer);
0070
0071
0072 void GenerateCallMethodCases(io::Printer* printer);
0073
0074
0075 void GenerateStubMethods(io::Printer* printer);
0076
0077 const ServiceDescriptor* descriptor_;
0078 const Options* options_;
0079 absl::flat_hash_map<absl::string_view, std::string> vars_;
0080
0081 int index_in_metadata_;
0082
0083 friend class FileGenerator;
0084 };
0085 }
0086 }
0087 }
0088 }
0089
0090 #endif