Support in ProtoRPC

pull/10505/head
Muxi Yan 8 years ago
parent 895f3d83da
commit 56369ea4a2
  1. 21
      src/compiler/objective_c_generator.cc
  2. 1
      src/compiler/objective_c_plugin.cc

@ -149,17 +149,19 @@ void PrintMethodDeclarations(Printer *printer, const MethodDescriptor *method) {
void PrintSimpleImplementation(Printer *printer, const MethodDescriptor *method,
map< ::grpc::string, ::grpc::string> vars) {
printer->Print("{\n");
printer->Print(vars, " [[self RPCTo$method_name$With");
printer->Print(vars, " GRPCProtoCall *rpc = [self RPCTo$method_name$With");
if (method->client_streaming()) {
printer->Print("RequestsWriter:requestWriter");
} else {
printer->Print("Request:request");
}
if (method->server_streaming()) {
printer->Print(" eventHandler:eventHandler] start];\n");
printer->Print(" eventHandler:eventHandler];\n");
} else {
printer->Print(" handler:handler] start];\n");
printer->Print(" handler:handler];\n");
}
printer->Print(" [rpc setResponseDispatchQueue:_defaultResponseDispatchQueue];\n");
printer->Print(" [rpc start];\n");
printer->Print("}\n");
}
@ -167,7 +169,7 @@ void PrintAdvancedImplementation(Printer *printer,
const MethodDescriptor *method,
map< ::grpc::string, ::grpc::string> vars) {
printer->Print("{\n");
printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n");
printer->Print(vars, " GRPCProtoCall *rpc = [self RPCToMethod:@\"$method_name$\"\n");
printer->Print(" requestsWriter:");
if (method->client_streaming()) {
@ -184,6 +186,8 @@ void PrintAdvancedImplementation(Printer *printer,
} else {
printer->Print("writeableWithSingleHandler:handler]];\n");
}
printer->Print(" [rpc setResponseDispatchQueue:_defaultResponseDispatchQueue];\n");
printer->Print(" return rpc;\n");
printer->Print("}\n");
}
@ -234,6 +238,7 @@ void PrintMethodImplementations(Printer *printer,
"- (instancetype)initWithHost:(NSString *)host"
" NS_DESIGNATED_INITIALIZER;\n");
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n");
printer.Print("- (void)setDefaultResponseDispatchQueue:(dispatch_queue_t)queue;\n");
printer.Print("@end\n");
}
return output;
@ -251,12 +256,15 @@ void PrintMethodImplementations(Printer *printer,
{"service_class", ServiceClassName(service)},
{"package", service->file()->package()}};
printer.Print(vars, "@implementation $service_class$\n\n");
printer.Print(vars, "@implementation $service_class$ {\n");
printer.Print(vars, " dispatch_queue_t _defaultResponseDispatchQueue;\n");
printer.Print(vars, "}\n\n");
printer.Print("// Designated initializer\n");
printer.Print("- (instancetype)initWithHost:(NSString *)host {\n");
printer.Print(
vars,
" _defaultResponseDispatchQueue = dispatch_get_main_queue();\n"
" return (self = [super initWithHost:host"
" packageName:@\"$package$\" serviceName:@\"$service_name$\"]);\n");
printer.Print("}\n\n");
@ -270,6 +278,9 @@ void PrintMethodImplementations(Printer *printer,
printer.Print("}\n\n");
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host {\n");
printer.Print(" return [[self alloc] initWithHost:host];\n");
printer.Print("}\n\n");
printer.Print("- (void)setDefaultResponseDispatchQueue:(dispatch_queue_t)queue {\n");
printer.Print(" _defaultResponseDispatchQueue = queue;\n");
printer.Print("}\n\n\n");
for (int i = 0; i < service->method_count(); i++) {

@ -68,6 +68,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
::grpc::string imports = ::grpc::string("#import \"") + file_name +
".pbobjc.h\"\n\n"
"#import <ProtoRPC/ProtoService.h>\n"
"#import <ProtoRPC/ProtoRPC.h>\n"
"#import <RxLibrary/GRXWriteable.h>\n"
"#import <RxLibrary/GRXWriter.h>\n";

Loading…
Cancel
Save