aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/cpp/cpp_service.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_service.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_service.cc66
1 files changed, 36 insertions, 30 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_service.cc b/src/google/protobuf/compiler/cpp/cpp_service.cc
index 226c2aa0..95357d9f 100644
--- a/src/google/protobuf/compiler/cpp/cpp_service.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_service.cc
@@ -46,6 +46,7 @@ ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor,
const Options& options)
: descriptor_(descriptor) {
vars_["classname"] = descriptor_->name();
+ vars_["file_namespace"] = FileLevelNamespace(descriptor_->file()->name());
vars_["full_name"] = descriptor_->full_name();
if (options.dllexport_decl.empty()) {
vars_["dllexport"] = "";
@@ -143,7 +144,7 @@ void ServiceGenerator::GenerateMethodSignatures(
VirtualOrNon virtual_or_non, io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["name"] = method->name();
sub_vars["input_type"] = ClassName(method->input_type(), true);
sub_vars["output_type"] = ClassName(method->output_type(), true);
@@ -161,7 +162,7 @@ void ServiceGenerator::GenerateMethodSignatures(
void ServiceGenerator::GenerateDescriptorInitializer(
io::Printer* printer, int index) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = descriptor_->name();
vars["index"] = SimpleItoa(index);
@@ -172,19 +173,20 @@ void ServiceGenerator::GenerateDescriptorInitializer(
// ===================================================================
void ServiceGenerator::GenerateImplementation(io::Printer* printer) {
- printer->Print(vars_,
- "$classname$::~$classname$() {}\n"
- "\n"
- "const ::google::protobuf::ServiceDescriptor* $classname$::descriptor() {\n"
- " protobuf_AssignDescriptorsOnce();\n"
- " return $classname$_descriptor_;\n"
- "}\n"
- "\n"
- "const ::google::protobuf::ServiceDescriptor* $classname$::GetDescriptor() {\n"
- " protobuf_AssignDescriptorsOnce();\n"
- " return $classname$_descriptor_;\n"
- "}\n"
- "\n");
+ vars_["index"] = SimpleItoa(index_in_metadata_);
+ printer->Print(
+ vars_,
+ "$classname$::~$classname$() {}\n"
+ "\n"
+ "const ::google::protobuf::ServiceDescriptor* $classname$::descriptor() {\n"
+ " $file_namespace$::protobuf_AssignDescriptorsOnce();\n"
+ " return $file_namespace$::file_level_service_descriptors[$index$];\n"
+ "}\n"
+ "\n"
+ "const ::google::protobuf::ServiceDescriptor* $classname$::GetDescriptor() {\n"
+ " return descriptor();\n"
+ "}\n"
+ "\n");
// Generate methods of the interface.
GenerateNotImplementedMethods(printer);
@@ -212,7 +214,7 @@ void ServiceGenerator::GenerateImplementation(io::Printer* printer) {
void ServiceGenerator::GenerateNotImplementedMethods(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["classname"] = descriptor_->name();
sub_vars["name"] = method->name();
sub_vars["index"] = SimpleItoa(i);
@@ -232,18 +234,20 @@ void ServiceGenerator::GenerateNotImplementedMethods(io::Printer* printer) {
}
void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
- printer->Print(vars_,
- "void $classname$::CallMethod(const ::google::protobuf::MethodDescriptor* method,\n"
- " ::google::protobuf::RpcController* controller,\n"
- " const ::google::protobuf::Message* request,\n"
- " ::google::protobuf::Message* response,\n"
- " ::google::protobuf::Closure* done) {\n"
- " GOOGLE_DCHECK_EQ(method->service(), $classname$_descriptor_);\n"
- " switch(method->index()) {\n");
+ printer->Print(
+ vars_,
+ "void $classname$::CallMethod(const ::google::protobuf::MethodDescriptor* method,\n"
+ " ::google::protobuf::RpcController* controller,\n"
+ " const ::google::protobuf::Message* request,\n"
+ " ::google::protobuf::Message* response,\n"
+ " ::google::protobuf::Closure* done) {\n"
+ " GOOGLE_DCHECK_EQ(method->service(), "
+ "$file_namespace$::file_level_service_descriptors[$index$]);\n"
+ " switch(method->index()) {\n");
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["name"] = method->name();
sub_vars["index"] = SimpleItoa(i);
sub_vars["input_type"] = ClassName(method->input_type(), true);
@@ -289,7 +293,7 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
const Descriptor* type =
(which == REQUEST) ? method->input_type() : method->output_type();
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["index"] = SimpleItoa(i);
sub_vars["type"] = ClassName(type, true);
@@ -298,19 +302,21 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
" return $type$::default_instance();\n");
}
- printer->Print(vars_,
+ printer->Print(
" default:\n"
" GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n"
- " return *static_cast< ::google::protobuf::Message*>(NULL);\n"
+ " return *::google::protobuf::MessageFactory::generated_factory()\n"
+ " ->GetPrototype(method->$input_or_output$_type());\n"
" }\n"
"}\n"
- "\n");
+ "\n",
+ "input_or_output", which == REQUEST ? "input" : "output");
}
void ServiceGenerator::GenerateStubMethods(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["classname"] = descriptor_->name();
sub_vars["name"] = method->name();
sub_vars["index"] = SimpleItoa(i);