Skip to content
Snippets Groups Projects
Commit 56369ea4 authored by Muxi Yan's avatar Muxi Yan
Browse files

Support in ProtoRPC

parent 895f3d83
No related branches found
No related tags found
No related merge requests found
......@@ -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,23 +169,25 @@ 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:");
printer->Print(" requestsWriter:");
if (method->client_streaming()) {
printer->Print("requestWriter\n");
} else {
printer->Print("[GRXWriter writerWithValue:request]\n");
}
printer->Print(vars, " responseClass:[$response_class$ class]\n");
printer->Print(vars, " responseClass:[$response_class$ class]\n");
printer->Print(" responsesWriteable:[GRXWriteable ");
printer->Print(" responsesWriteable:[GRXWriteable ");
if (method->server_streaming()) {
printer->Print("writeableWithEventHandler:eventHandler]];\n");
} 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";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment