diff options
author | Muxi Yan <mxyan@google.com> | 2016-09-28 11:25:57 -0700 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2016-09-28 12:07:47 -0700 |
commit | e97f7c0ba6c2f7c55e2ea650f52597a06bcfa6fd (patch) | |
tree | 4fe0fa50d1e8218dcb14becc42816cfcf19b4212 /src/objective-c | |
parent | fdea83d42afbebfecfea1edf9143619640115824 (diff) |
Allow more general flags to be passed to ObjC API
Diffstat (limited to 'src/objective-c')
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall.h | 2 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall.m | 12 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCWrappedCall.h | 2 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCWrappedCall.m | 10 | ||||
-rw-r--r-- | src/objective-c/ProtoRPC/ProtoRPC.h | 2 | ||||
-rw-r--r-- | src/objective-c/ProtoRPC/ProtoRPC.m | 6 | ||||
-rw-r--r-- | src/objective-c/ProtoRPC/ProtoService.h | 2 | ||||
-rw-r--r-- | src/objective-c/ProtoRPC/ProtoService.m | 4 |
8 files changed, 19 insertions, 21 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index fc59e5f5e9..9a58311fe1 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -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 diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 6bd80c8b3f..8a58db7051 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -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]]]; } diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h index 8b64b27e56..52233c8242 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h @@ -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 diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index 2836f99bf1..627b6aa86d 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -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; diff --git a/src/objective-c/ProtoRPC/ProtoRPC.h b/src/objective-c/ProtoRPC/ProtoRPC.h index 509a15abae..75c9b9bb3b 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.h +++ b/src/objective-c/ProtoRPC/ProtoRPC.h @@ -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 diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 67405d2a19..2514d616f1 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -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. diff --git a/src/objective-c/ProtoRPC/ProtoService.h b/src/objective-c/ProtoRPC/ProtoService.h index 80fab37fd5..9a49ebd257 100644 --- a/src/objective-c/ProtoRPC/ProtoService.h +++ b/src/objective-c/ProtoRPC/ProtoService.h @@ -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 diff --git a/src/objective-c/ProtoRPC/ProtoService.m b/src/objective-c/ProtoRPC/ProtoService.m index fc3e017072..b237164a00 100644 --- a/src/objective-c/ProtoRPC/ProtoService.m +++ b/src/objective-c/ProtoRPC/ProtoService.m @@ -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 |