Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:11:56

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // Author: kenton@google.com (Kenton Varda)
0009 //  Based on original Protocol Buffers design by
0010 //  Sanjay Ghemawat, Jeff Dean, and others.
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   // See generator.cc for the meaning of dllexport_decl.
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   // Generate the class definitions for the service's interface and the
0046   // stub implementation.
0047   void GenerateDeclarations(io::Printer* printer);
0048 
0049   // Generate implementations of everything declared by
0050   // GenerateDeclarations().
0051   void GenerateImplementation(io::Printer* printer);
0052 
0053  private:
0054   enum RequestOrResponse { kRequest, kResponse };
0055   enum VirtualOrNot { kVirtual, kNonVirtual };
0056 
0057   // Prints signatures for all methods in the
0058   void GenerateMethodSignatures(VirtualOrNot virtual_or_not,
0059                                 io::Printer* printer);
0060 
0061   // Generate the default implementations of the service methods, which
0062   // produce a "not implemented" error.
0063   void GenerateNotImplementedMethods(io::Printer* printer);
0064 
0065   // Generate the CallMethod() method of the service.
0066   void GenerateCallMethod(io::Printer* printer);
0067 
0068   // Generate the Get{Request,Response}Prototype() methods.
0069   void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer);
0070 
0071   // Generate the cases in CallMethod().
0072   void GenerateCallMethodCases(io::Printer* printer);
0073 
0074   // Generate the stub's implementations of the service methods.
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 }  // namespace cpp
0086 }  // namespace compiler
0087 }  // namespace protobuf
0088 }  // namespace google
0089 
0090 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__