|
|
|
@ -47,8 +47,8 @@ void PrintSimpleBlockSignature(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
(*vars)["request_type"] = PrefixedName(method->input_type()); |
|
|
|
|
(*vars)["response_type"] = PrefixedName(method->output_type()); |
|
|
|
|
(*vars)["request_type"] = PrefixedName(method->input_type()->name()); |
|
|
|
|
(*vars)["response_type"] = PrefixedName(method->output_type()->name()); |
|
|
|
|
|
|
|
|
|
if (method->server_streaming()) { |
|
|
|
|
printer->Print("// When the response stream finishes, the handler is " |
|
|
|
@ -56,7 +56,7 @@ void PrintSimpleBlockSignature(grpc::protobuf::io::Printer *printer, |
|
|
|
|
} else { |
|
|
|
|
printer->Print("// The handler is only called once.\n\n"); |
|
|
|
|
} |
|
|
|
|
printer->Print(vars, "- (id<GRXLiveSource>)$method_name$WithRequest:" |
|
|
|
|
printer->Print(*vars, "- (id<GRXLiveSource>)$method_name$WithRequest:" |
|
|
|
|
"($request_type$)request completionHandler:(void(^)" |
|
|
|
|
"($response_type$ *, NSError *))handler"); |
|
|
|
|
} |
|
|
|
@ -65,9 +65,9 @@ void PrintSimpleDelegateSignature(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
(*vars)["request_type"] = PrefixedName(method->input_type()); |
|
|
|
|
(*vars)["request_type"] = PrefixedName(method->input_type()->name()); |
|
|
|
|
|
|
|
|
|
printer->Print(vars, "- (id<GRXLiveSource>)$method_name$WithRequest:" |
|
|
|
|
printer->Print(*vars, "- (id<GRXLiveSource>)$method_name$WithRequest:" |
|
|
|
|
"($request_type$)request delegate:(id<GRXSink>)delegate"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -75,52 +75,10 @@ void PrintAdvancedSignature(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
printer->Print(vars, "- (GRXSource *)$method_name$WithRequest:" |
|
|
|
|
printer->Print(*vars, "- (GRXSource *)$method_name$WithRequest:" |
|
|
|
|
"(id<GRXSource>)request"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeader(const grpc::protobuf::ServiceDescriptor *service |
|
|
|
|
const grpc::string message_header) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
printer.Print("#import \"PBgRPCClient.h\"\n"); |
|
|
|
|
printer.Print("#import \"PBStub.h\"\n"); |
|
|
|
|
vars["message_header"] = message_header; |
|
|
|
|
printer.Print(&vars, "#import \"$message_header$\"\n\n"); |
|
|
|
|
printer.Print("@protocol GRXSource\n"); |
|
|
|
|
printer.Print("@class GRXSource\n\n"); |
|
|
|
|
vars["service_name"] = service->name(); |
|
|
|
|
printer.Print("@protocol $service_name$Stub <NSObject>\n\n"); |
|
|
|
|
printer.Print("#pragma mark Simple block handlers\n\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
PrintSimpleBlockSignature(&printer, service->method(i), &vars); |
|
|
|
|
printer.Print(";\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
printer.Print("#pragma mark Simple delegate handlers.\n\n"); |
|
|
|
|
printer.Print("# TODO(jcanizales): Use high-level snippets to remove this duplication."); |
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
PrintSimpleDelegateSignature(&printer, service->method(i), &vars); |
|
|
|
|
printer.Print(";\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
printer.Print("#pragma mark Advanced handlers.\n\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
PrintAdvancedSignature(&printer, service->method(i), &vars); |
|
|
|
|
printer.Print(";\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
printer.Print("@end\n\n"); |
|
|
|
|
printer.Print("// Basic stub that only does marshalling and parsing\n"); |
|
|
|
|
printer.Print(&vars, "@interface $service_name$Stub :" |
|
|
|
|
" PBStub<$service_name$Stub>\n"); |
|
|
|
|
printer.Print("- (instancetype)initWithHost:(NSString *)host;\n"); |
|
|
|
|
printer.Print("@end\n"); |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceMethodSimpleBlock(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
@ -129,7 +87,7 @@ void PrintSourceMethodSimpleBlock(grpc::protobuf::io::Printer *printer, |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
printer->Print(" {\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(vars, "return [[self $method_name$WithRequest:request] " |
|
|
|
|
printer->Print(*vars, "return [[self $method_name$WithRequest:request] " |
|
|
|
|
"connectHandler:^(id value, NSError *error) {\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print("handler(value, error);\n"); |
|
|
|
@ -147,7 +105,7 @@ void PrintSourceMethodSimpleDelegate(grpc::protobuf::io::Printer *printer, |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
printer->Print(" {\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(vars, "return [[self $method_name$WithRequest:request]" |
|
|
|
|
printer->Print(*vars, "return [[self $method_name$WithRequest:request]" |
|
|
|
|
"connectToSink:delegate];\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
@ -161,7 +119,7 @@ void PrintSourceMethodAdvanced(grpc::protobuf::io::Printer *printer, |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
printer->Print(" {\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(vars, "return [self $method_name$WithRequest:request " |
|
|
|
|
printer->Print(*vars, "return [self $method_name$WithRequest:request " |
|
|
|
|
"client:[self newClient]];\n"); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Print("}\n"); |
|
|
|
@ -171,15 +129,15 @@ void PrintSourceMethodHandler(grpc::protobuf::io::Printer *printer, |
|
|
|
|
const grpc::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<grpc::string, grpc::string> *vars) { |
|
|
|
|
(*vars)["method_name"] = method->name(); |
|
|
|
|
(*vars)["response_type"] = PrefixedName(method->output_type()); |
|
|
|
|
(*vars)["response_type"] = PrefixedName(method->output_type()->name()); |
|
|
|
|
(*vars)["caps_name"] = grpc_generator::CapitalizeFirstLetter(method->name()); |
|
|
|
|
|
|
|
|
|
printer->Print(vars, "- (GRXSource *)$method_name$WithRequest:" |
|
|
|
|
printer->Print(*vars, "- (GRXSource *)$method_name$WithRequest:" |
|
|
|
|
"(id<GRXSource>)request client:(PBgRPCClient *)client {\n"); |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print(vars, |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
"return [self responseWithMethod:$@\"$caps_name\"\n"); |
|
|
|
|
printer->Print(vars, |
|
|
|
|
printer->Print(*vars, |
|
|
|
|
" class:[$response_type$ class]\n"); |
|
|
|
|
printer->Print(" request:request\n"); |
|
|
|
|
printer->Print(" client:client];\n"); |
|
|
|
@ -187,16 +145,60 @@ void PrintSourceMethodHandler(grpc::protobuf::io::Printer *printer, |
|
|
|
|
printer->Print("}\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeader(const grpc::protobuf::ServiceDescriptor *service, |
|
|
|
|
const grpc::string message_header) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
printer.Print("#import \"PBgRPCClient.h\"\n"); |
|
|
|
|
printer.Print("#import \"PBStub.h\"\n"); |
|
|
|
|
vars["message_header"] = message_header; |
|
|
|
|
printer.Print(vars, "#import \"$message_header$\"\n\n"); |
|
|
|
|
printer.Print("@protocol GRXSource\n"); |
|
|
|
|
printer.Print("@class GRXSource\n\n"); |
|
|
|
|
vars["service_name"] = service->name(); |
|
|
|
|
printer.Print("@protocol $service_name$Stub <NSObject>\n\n"); |
|
|
|
|
printer.Print("#pragma mark Simple block handlers\n\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
PrintSimpleBlockSignature(&printer, service->method(i), &vars); |
|
|
|
|
printer.Print(";\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
printer.Print("#pragma mark Simple delegate handlers.\n\n"); |
|
|
|
|
printer.Print("# TODO(jcanizales): Use high-level snippets to remove this duplication."); |
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
PrintSimpleDelegateSignature(&printer, service->method(i), &vars); |
|
|
|
|
printer.Print(";\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
printer.Print("#pragma mark Advanced handlers.\n\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); i++) { |
|
|
|
|
PrintAdvancedSignature(&printer, service->method(i), &vars); |
|
|
|
|
printer.Print(";\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
printer.Print("@end\n\n"); |
|
|
|
|
printer.Print("// Basic stub that only does marshalling and parsing\n"); |
|
|
|
|
printer.Print(vars, "@interface $service_name$Stub :" |
|
|
|
|
" PBStub<$service_name$Stub>\n"); |
|
|
|
|
printer.Print("- (instancetype)initWithHost:(NSString *)host;\n"); |
|
|
|
|
printer.Print("@end\n"); |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSource(const grpc::protobuf::ServiceDescriptor *service) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
vars["service_name"] = service->name(); |
|
|
|
|
printer.Print(&vars, "#import \"$service_name$Stub.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "#import \"$service_name$Stub.pb.h\"\n"); |
|
|
|
|
printer.Print("#import \"PBGeneratedMessage+GRXSource.h\"\n\n"); |
|
|
|
|
vars["full_name"] = service->full_name(); |
|
|
|
|
printer.Print(&vars, |
|
|
|
|
printer.Print(vars, |
|
|
|
|
"static NSString *const kInterface = @\"$full_name$\";\n"); |
|
|
|
|
printer.Print("@implementation $service_name$Stub\n\n"); |
|
|
|
|
printer.Print("- (instancetype)initWithHost:(NSString *)host {\n"); |
|
|
|
|