Go to the documentation of this file.
35 #include <google/protobuf/compiler/cpp/cpp_service.h>
36 #include <google/protobuf/compiler/cpp/cpp_helpers.h>
37 #include <google/protobuf/io/printer.h>
38 #include <google/protobuf/stubs/strutil.h>
59 const std::map<std::string, std::string>& vars,
const Options&
options)
71 "class $classname$_Stub;\n"
81 "class $dllexport_decl $$classname$ : public ::$proto_ns$::Service {\n"
83 " // This class should be treated as an abstract interface.\n"
84 " inline $classname$() {};\n"
86 " virtual ~$classname$();\n");
91 "typedef $classname$_Stub Stub;\n"
93 "static const ::$proto_ns$::ServiceDescriptor* descriptor();\n"
100 "// implements Service ----------------------------------------------\n"
102 "const ::$proto_ns$::ServiceDescriptor* GetDescriptor();\n"
103 "void CallMethod(const ::$proto_ns$::MethodDescriptor* method,\n"
104 " ::$proto_ns$::RpcController* controller,\n"
105 " const ::$proto_ns$::Message* request,\n"
106 " ::$proto_ns$::Message* response,\n"
107 " ::google::protobuf::Closure* done);\n"
108 "const ::$proto_ns$::Message& GetRequestPrototype(\n"
109 " const ::$proto_ns$::MethodDescriptor* method) const;\n"
110 "const ::$proto_ns$::Message& GetResponsePrototype(\n"
111 " const ::$proto_ns$::MethodDescriptor* method) const;\n");
117 " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$);\n"
125 "class $dllexport_decl $$classname$_Stub : public $classname$ {\n"
131 "$classname$_Stub(::$proto_ns$::RpcChannel* channel);\n"
132 "$classname$_Stub(::$proto_ns$::RpcChannel* channel,\n"
133 " ::$proto_ns$::Service::ChannelOwnership ownership);\n"
134 "~$classname$_Stub();\n"
136 "inline ::$proto_ns$::RpcChannel* channel() { return channel_; }\n"
138 "// implements $classname$ ------------------------------------------\n"
146 " ::$proto_ns$::RpcChannel* channel_;\n"
147 " bool owns_channel_;\n"
148 " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$_Stub);\n"
159 format.Set(
"virtual", virtual_or_non ==
VIRTUAL ?
"virtual " :
"");
161 "$virtual$void $name$(::$proto_ns$::RpcController* controller,\n"
162 " const $input_type$* request,\n"
163 " $output_type$* response,\n"
164 " ::google::protobuf::Closure* done);\n");
173 "$classname$::~$classname$() {}\n"
175 "const ::$proto_ns$::ServiceDescriptor* $classname$::descriptor() {\n"
177 "::$proto_ns$::internal::AssignDescriptors(&$desc_table$);\n"
178 " return $file_level_service_descriptors$[$1$];\n"
181 "const ::$proto_ns$::ServiceDescriptor* $classname$::GetDescriptor() {\n"
182 " return descriptor();\n"
195 "$classname$_Stub::$classname$_Stub(::$proto_ns$::RpcChannel* channel)\n"
196 " : channel_(channel), owns_channel_(false) {}\n"
197 "$classname$_Stub::$classname$_Stub(\n"
198 " ::$proto_ns$::RpcChannel* channel,\n"
199 " ::$proto_ns$::Service::ChannelOwnership ownership)\n"
200 " : channel_(channel),\n"
201 " owns_channel_(ownership == "
202 "::$proto_ns$::Service::STUB_OWNS_CHANNEL) "
204 "$classname$_Stub::~$classname$_Stub() {\n"
205 " if (owns_channel_) delete channel_;\n"
218 "void $classname$::$name$(::$proto_ns$::RpcController* controller,\n"
219 " const $input_type$*,\n"
221 " ::google::protobuf::Closure* done) {\n"
222 " controller->SetFailed(\"Method $name$() not implemented.\");\n"
232 "void $classname$::CallMethod(const ::$proto_ns$::MethodDescriptor* "
234 " ::$proto_ns$::RpcController* controller,\n"
235 " const ::$proto_ns$::Message* request,\n"
236 " ::$proto_ns$::Message* response,\n"
237 " ::google::protobuf::Closure* done) {\n"
238 " GOOGLE_DCHECK_EQ(method->service(), $file_level_service_descriptors$[$1$]);\n"
239 " switch(method->index()) {\n",
251 " $name$(controller,\n"
252 " ::$proto_ns$::internal::DownCast<const $input_type$*>(\n"
254 " ::$proto_ns$::internal::DownCast<$output_type$*>(\n"
263 " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n"
274 format(
"const ::$proto_ns$::Message& $classname$::GetRequestPrototype(\n");
276 format(
"const ::$proto_ns$::Message& $classname$::GetResponsePrototype(\n");
280 " const ::$proto_ns$::MethodDescriptor* method) const {\n"
281 " GOOGLE_DCHECK_EQ(method->service(), descriptor());\n"
282 " switch(method->index()) {\n");
291 " return $2$::default_instance();\n",
297 " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n"
298 " return *::$proto_ns$::MessageFactory::generated_factory()\n"
299 " ->GetPrototype(method->$1$_type());\n"
312 "void $classname$_Stub::$name$(::$proto_ns$::RpcController* "
314 " const $input_type$* request,\n"
315 " $output_type$* response,\n"
316 " ::google::protobuf::Closure* done) {\n"
317 " channel_->CallMethod(descriptor()->method($1$),\n"
318 " controller, request, response, done);\n"
void GenerateGetPrototype(RequestOrResponse which, io::Printer *printer)
const std::string & full_name() const
GRPC_CUSTOM_PRINTER Printer
std::string QualifiedClassName(const Descriptor *d, const Options &options)
void GenerateDeclarations(io::Printer *printer)
const std::string & name() const
void GenerateInterface(io::Printer *printer)
ServiceGenerator(const ServiceDescriptor *descriptor, const std::map< std::string, std::string > &vars, const Options &options)
const std::string & name() const
GRPC_CUSTOM_METHODDESCRIPTOR MethodDescriptor
void GenerateCallMethod(io::Printer *printer)
void GenerateMethodSignatures(VirtualOrNon virtual_or_non, io::Printer *printer)
void GenerateStubDefinition(io::Printer *printer)
std::map< std::string, std::string > vars_
DebugStringOptions options_
void GenerateImplementation(io::Printer *printer)
void GenerateNotImplementedMethods(io::Printer *printer)
const MethodDescriptor * method(int index) const
const ServiceDescriptor * descriptor_
void GenerateStubMethods(io::Printer *printer)
static const char descriptor[1336]
GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor
const Descriptor::ReservedRange const EnumValueDescriptor method
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:06