Allow more general flags to be passed to ObjC API

pull/8223/head
Muxi Yan 8 years ago
parent fdea83d42a
commit e97f7c0ba6
  1. 2
      src/objective-c/GRPCClient/GRPCCall.h
  2. 12
      src/objective-c/GRPCClient/GRPCCall.m
  3. 2
      src/objective-c/GRPCClient/private/GRPCWrappedCall.h
  4. 10
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  5. 2
      src/objective-c/ProtoRPC/ProtoRPC.h
  6. 6
      src/objective-c/ProtoRPC/ProtoRPC.m
  7. 2
      src/objective-c/ProtoRPC/ProtoService.h
  8. 4
      src/objective-c/ProtoRPC/ProtoService.m

@ -230,7 +230,7 @@ extern id const kGRPCTrailersKey;
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestsWriter
http2Method:(NSString *)http2Method NS_DESIGNATED_INITIALIZER;
flags:(uint32_t)flags NS_DESIGNATED_INITIALIZER;
/**
* Finishes the request side of this call, notifies the server that the RPC should be cancelled, and

@ -75,7 +75,7 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
NSString *_host;
NSString *_path;
NSString *_http2Method;
uint32_t _flags;
GRPCWrappedCall *_wrappedCall;
GRPCConnectivityMonitor *_connectivityMonitor;
@ -110,20 +110,20 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
}
- (instancetype)init {
return [self initWithHost:nil path:nil requestsWriter:nil http2Method:nil];
return [self initWithHost:nil path:nil requestsWriter:nil flags:0];
}
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestWriter{
return [self initWithHost:host path:path requestsWriter:requestWriter http2Method:@"POST"];
return [self initWithHost:host path:path requestsWriter:requestWriter flags:0];
}
// Designated initializer
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestWriter
http2Method:(NSString *)http2Method {
flags:(uint32_t)flags {
if (!host || !path) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."];
}
@ -134,7 +134,7 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
if ((self = [super init])) {
_host = [host copy];
_path = [path copy];
_http2Method = http2Method;
_flags = flags;
// Serial queue to invoke the non-reentrant methods of the grpc_call object.
_callQueue = dispatch_queue_create("io.grpc.call", NULL);
@ -240,7 +240,7 @@ NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey";
- (void)sendHeaders:(NSDictionary *)headers {
// TODO(jcanizales): Add error handlers for async failures
[_wrappedCall startBatchWithOperations:@[[[GRPCOpSendMetadata alloc] initWithMetadata:headers
http2Method:_http2Method
flags:_flags
handler:nil]]];
}

@ -48,7 +48,7 @@
handler:(void(^)())handler;
- (instancetype)initWithMetadata:(NSDictionary *)metadata
http2Method:(NSString *)http2Method
flags:(uint32_t)flags
handler:(void(^)())handler NS_DESIGNATED_INITIALIZER;
@end

@ -64,16 +64,16 @@
@implementation GRPCOpSendMetadata
- (instancetype)init {
return [self initWithMetadata:nil http2Method:nil handler:nil];
return [self initWithMetadata:nil flags:0 handler:nil];
}
- (instancetype)initWithMetadata:(NSDictionary *)metadata
handler:(void (^)())handler {
return [self initWithMetadata:metadata http2Method:@"POST" handler:handler];
return [self initWithMetadata:metadata flags:0 handler:handler];
}
- (instancetype)initWithMetadata:(NSDictionary *)metadata
http2Method:(NSString *)http2Method
flags:(uint32_t)flags
handler:(void (^)())handler {
if (self = [super init]) {
_op.op = GRPC_OP_SEND_INITIAL_METADATA;
@ -81,9 +81,7 @@
_op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray;
_op.data.send_initial_metadata.maybe_compression_level.is_set = false;
_op.data.send_initial_metadata.maybe_compression_level.level = 0;
if ([http2Method isEqualToString:@"PUT"]) {
_op.flags = GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST;
}
_op.flags = flags;
_handler = handler;
}
return self;

@ -48,7 +48,7 @@ __attribute__((deprecated("Please use GRPCProtoCall.")))
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method NS_DESIGNATED_INITIALIZER;
flags:(uint32_t)flags NS_DESIGNATED_INITIALIZER;
- (void)start;
@end

@ -66,7 +66,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
requestsWriter:(GRXWriter *)requestsWriter
http2Method:(NSString *)http2Method {
flags:(uint32_t)flags {
[NSException raise:NSInvalidArgumentException
format:@"Please use ProtoRPC's designated initializer instead."];
return nil;
@ -79,7 +79,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method {
flags:(uint32_t)flags {
// Because we can't tell the type system to constrain the class, we need to check at runtime:
if (![responseClass respondsToSelector:@selector(parseFromData:error:)]) {
[NSException raise:NSInvalidArgumentException
@ -94,7 +94,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
return [proto data];
}];
if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter
http2Method:http2Method])) {
flags:flags])) {
__weak ProtoRPC *weakSelf = self;
// A writeable that parses the proto messages received.

@ -48,7 +48,7 @@ __attribute__((deprecated("Please use GRPCProtoService.")))
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method;
flags:(uint32_t)flags;
@end

@ -69,7 +69,7 @@
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable
http2Method:(NSString *)http2Method {
flags:(uint32_t)flags {
GRPCProtoMethod *methodName = [[GRPCProtoMethod alloc] initWithPackage:_packageName
service:_serviceName
method:method];
@ -78,7 +78,7 @@
requestsWriter:requestsWriter
responseClass:responseClass
responsesWriteable:responsesWriteable
http2Method:http2Method];
flags:flags];
}
@end

Loading…
Cancel
Save