From c92d90aba2bd1bd710830c781d1e1e4c8adea0ba Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 11 Apr 2018 18:10:02 -0700 Subject: clang-format objective-c files --- src/objective-c/GRPCClient/GRPCCall+ChannelArg.h | 10 +- src/objective-c/GRPCClient/GRPCCall+ChannelArg.m | 3 +- .../GRPCClient/GRPCCall+ChannelCredentials.h | 4 +- .../GRPCClient/GRPCCall+ChannelCredentials.m | 17 ++- src/objective-c/GRPCClient/GRPCCall+Cronet.h | 6 +- src/objective-c/GRPCClient/GRPCCall+GID.h | 4 +- src/objective-c/GRPCClient/GRPCCall+OAuth2.m | 6 +- src/objective-c/GRPCClient/GRPCCall+Tests.m | 7 +- src/objective-c/GRPCClient/GRPCCall.h | 9 +- src/objective-c/GRPCClient/GRPCCall.m | 140 +++++++++++---------- src/objective-c/GRPCClient/private/GRPCChannel.h | 6 +- src/objective-c/GRPCClient/private/GRPCChannel.m | 50 +++----- .../GRPCClient/private/GRPCCompletionQueue.h | 2 +- .../GRPCClient/private/GRPCCompletionQueue.m | 5 +- .../GRPCClient/private/GRPCConnectivityMonitor.h | 5 +- .../GRPCClient/private/GRPCConnectivityMonitor.m | 11 +- src/objective-c/GRPCClient/private/GRPCHost.h | 1 - src/objective-c/GRPCClient/private/GRPCHost.m | 56 ++++----- .../GRPCClient/private/GRPCOpBatchLog.h | 1 - .../GRPCClient/private/GRPCOpBatchLog.m | 6 +- .../private/GRPCReachabilityFlagNames.xmacro.h | 6 +- .../GRPCClient/private/GRPCRequestHeaders.m | 20 +-- .../GRPCClient/private/GRPCWrappedCall.h | 17 ++- .../GRPCClient/private/GRPCWrappedCall.m | 77 ++++++------ src/objective-c/GRPCClient/private/NSData+GRPC.m | 10 +- .../GRPCClient/private/NSDictionary+GRPC.m | 5 +- src/objective-c/GRPCClient/private/NSError+GRPC.m | 4 +- src/objective-c/GRPCClient/private/version.h | 1 - 28 files changed, 236 insertions(+), 253 deletions(-) (limited to 'src/objective-c/GRPCClient') diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h index b6d3938af0..c05ba54c99 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -39,12 +39,12 @@ typedef NS_ENUM(NSInteger, GRPCCompressAlgorithm) { /** The default response size limit is 4MB. Set this to override that default. */ + (void)setResponseSizeLimit:(NSUInteger)limit forHost:(nonnull NSString *)host; -+ (void)closeOpenConnections DEPRECATED_MSG_ATTRIBUTE("The API for this feature is experimental, " - "and might be removed or modified at any " - "time."); ++ (void)closeOpenConnections DEPRECATED_MSG_ATTRIBUTE( + "The API for this feature is experimental, " + "and might be removed or modified at any " + "time."); -+ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm - forhost:(nonnull NSString *)host; ++ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm forhost:(nonnull NSString *)host; /** Enable keepalive and configure keepalive parameters. A user should call this function once to * enable keepalive for a particular host. gRPC client sends a ping after every \a interval ms to diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index 217d0e9220..8f9c1b90ce 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -38,8 +38,7 @@ [GRPCHost flushChannelCache]; } -+ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm - forhost:(nonnull NSString *)host { ++ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm forhost:(nonnull NSString *)host { GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; switch (algorithm) { case GRPCCompressNone: diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h index c0d36b5231..d7d15c4ee3 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h @@ -26,7 +26,7 @@ */ + (BOOL)setTLSPEMRootCerts:(nullable NSString *)pemRootCert forHost:(nonnull NSString *)host - error:(NSError * _Nullable * _Nullable)errorPtr; + error:(NSError *_Nullable *_Nullable)errorPtr; /** * Configures @c host with TLS/SSL Client Credentials and optionally trusted root Certificate * Authorities. If @c pemRootCerts is nil, the default CA Certificates bundled with gRPC will be @@ -36,6 +36,6 @@ withPrivateKey:(nullable NSString *)pemPrivateKey withCertChain:(nullable NSString *)pemCertChain forHost:(nonnull NSString *)host - error:(NSError * _Nullable * _Nullable)errorPtr; + error:(NSError *_Nullable *_Nullable)errorPtr; @end diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m index 00f3e4e510..2689ec2eff 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m @@ -28,24 +28,23 @@ forHost:(nonnull NSString *)host error:(NSError **)errorPtr { if (!host) { - [NSException raise:NSInvalidArgumentException - format:@"host must be provided."]; + [NSException raise:NSInvalidArgumentException format:@"host must be provided."]; } GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; return [hostConfig setTLSPEMRootCerts:pemRootCerts - withPrivateKey:pemPrivateKey - withCertChain:pemCertChain - error:errorPtr]; + withPrivateKey:pemPrivateKey + withCertChain:pemCertChain + error:errorPtr]; } + (BOOL)setTLSPEMRootCerts:(nullable NSString *)pemRootCerts forHost:(nonnull NSString *)host error:(NSError **)errorPtr { return [GRPCCall setTLSPEMRootCerts:pemRootCerts - withPrivateKey:nil - withCertChain:nil - forHost:host - error:errorPtr]; + withPrivateKey:nil + withCertChain:nil + forHost:host + error:errorPtr]; } @end diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.h b/src/objective-c/GRPCClient/GRPCCall+Cronet.h index e084bf1169..2a5f6e9cf0 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.h +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.h @@ -32,11 +32,11 @@ * all subsequent RPCs will use Cronet transport. The method is not thread * safe. */ -+(void)useCronetWithEngine:(stream_engine *)engine; ++ (void)useCronetWithEngine:(stream_engine*)engine; -+(stream_engine *)cronetEngine; ++ (stream_engine*)cronetEngine; -+(BOOL)isUsingCronet; ++ (BOOL)isUsingCronet; @end #endif diff --git a/src/objective-c/GRPCClient/GRPCCall+GID.h b/src/objective-c/GRPCClient/GRPCCall+GID.h index 3ee732e79e..8293e92ebe 100644 --- a/src/objective-c/GRPCClient/GRPCCall+GID.h +++ b/src/objective-c/GRPCClient/GRPCCall+GID.h @@ -16,14 +16,14 @@ * */ -#import "GRPCCall.h" #import "GRPCCall+OAuth2.h" +#import "GRPCCall.h" #import /** * Extend GIDSignIn class to comply GRPCAuthorizationProtocol */ -@interface GIDSignIn (GRPC) +@interface GIDSignIn (GRPC) - (void)getTokenWithHandler:(void (^)(NSString *token))hander; @end diff --git a/src/objective-c/GRPCClient/GRPCCall+OAuth2.m b/src/objective-c/GRPCClient/GRPCCall+OAuth2.m index 8451ebe870..3292b6c241 100644 --- a/src/objective-c/GRPCClient/GRPCCall+OAuth2.m +++ b/src/objective-c/GRPCClient/GRPCCall+OAuth2.m @@ -20,9 +20,9 @@ #import "GRPCCall+OAuth2.h" -static NSString * const kAuthorizationHeader = @"authorization"; -static NSString * const kBearerPrefix = @"Bearer "; -static NSString * const kChallengeHeader = @"www-authenticate"; +static NSString *const kAuthorizationHeader = @"authorization"; +static NSString *const kBearerPrefix = @"Bearer "; +static NSString *const kChallengeHeader = @"www-authenticate"; @implementation GRPCCall (OAuth2) @dynamic tokenProvider; diff --git a/src/objective-c/GRPCClient/GRPCCall+Tests.m b/src/objective-c/GRPCClient/GRPCCall+Tests.m index aa9af9fe54..0db3ad6b39 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Tests.m +++ b/src/objective-c/GRPCClient/GRPCCall+Tests.m @@ -29,11 +29,10 @@ [NSException raise:NSInvalidArgumentException format:@"host, path and name must be provided."]; } NSError *error = nil; - NSString *certs = [NSString stringWithContentsOfFile:certsPath - encoding:NSUTF8StringEncoding - error:&error]; + NSString *certs = + [NSString stringWithContentsOfFile:certsPath encoding:NSUTF8StringEncoding error:&error]; if (error != nil) { - [NSException raise:[error localizedDescription] format:@"failed to load certs"]; + [NSException raise:[error localizedDescription] format:@"failed to load certs"]; } GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index df563ca36c..e0ef8b1391 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -147,7 +147,8 @@ typedef NS_ENUM(NSUInteger, GRPCCallSafety) { GRPCCallSafetyDefault = 0, /** Signal that the call is idempotent. gRPC is free to use PUT verb. */ GRPCCallSafetyIdempotentRequest = 1, - /** Signal that the call is cacheable and will not affect server state. gRPC is free to use GET verb. */ + /** Signal that the call is cacheable and will not affect server state. gRPC is free to use GET + verb. */ GRPCCallSafetyCacheableRequest = 2, }; @@ -167,7 +168,7 @@ extern id const kGRPCTrailersKey; * The authority for the RPC. If nil, the default authority will be used. This property must be nil * when Cronet transport is enabled. */ -@property (atomic, copy, readwrite) NSString *serverName; +@property(atomic, copy, readwrite) NSString *serverName; /** * The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to @@ -265,7 +266,7 @@ extern id const kGRPCTrailersKey; /** This protocol is kept for backwards compatibility with existing code. */ DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.") -@protocol GRPCRequestHeaders +@protocol GRPCRequestHeaders @property(nonatomic, readonly) NSUInteger count; - (id)objectForKeyedSubscript:(id)key; @@ -278,6 +279,6 @@ DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.") #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated" /** This is only needed for backwards-compatibility. */ -@interface NSMutableDictionary (GRPCRequestHeaders) +@interface NSMutableDictionary (GRPCRequestHeaders) @end #pragma clang diagnostic pop diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 501114dea0..75dda9df85 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -20,10 +20,10 @@ #import "GRPCCall+OAuth2.h" -#include -#include #import #import +#include +#include #import "private/GRPCConnectivityMonitor.h" #import "private/GRPCHost.h" @@ -38,14 +38,14 @@ // and RECV_STATUS_ON_CLIENT. NSInteger kMaxClientBatch = 6; -NSString * const kGRPCHeadersKey = @"io.grpc.HeadersKey"; -NSString * const kGRPCTrailersKey = @"io.grpc.TrailersKey"; +NSString *const kGRPCHeadersKey = @"io.grpc.HeadersKey"; +NSString *const kGRPCTrailersKey = @"io.grpc.TrailersKey"; static NSMutableDictionary *callFlags; -static NSString * const kAuthorizationHeader = @"authorization"; -static NSString * const kBearerPrefix = @"Bearer "; +static NSString *const kAuthorizationHeader = @"authorization"; +static NSString *const kBearerPrefix = @"Bearer "; -@interface GRPCCall () +@interface GRPCCall () // Make them read-write. @property(atomic, strong) NSDictionary *responseHeaders; @property(atomic, strong) NSDictionary *responseTrailers; @@ -219,9 +219,11 @@ static NSString * const kBearerPrefix = @"Bearer "; } - (void)cancel { - [self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeCancelled - userInfo:@{NSLocalizedDescriptionKey: @"Canceled by app"}]]; + [self + maybeFinishWithError:[NSError + errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeCancelled + userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]]; if (!self.isWaitingForToken) { [self cancelCall]; @@ -254,9 +256,9 @@ static NSString * const kBearerPrefix = @"Bearer "; // Only called from the call queue. // The handler will be called from the network queue. -- (void)startReadWithHandler:(void(^)(grpc_byte_buffer *))handler { +- (void)startReadWithHandler:(void (^)(grpc_byte_buffer *))handler { // TODO(jcanizales): Add error handlers for async failures - [_wrappedCall startBatchWithOperations:@[[[GRPCOpRecvMessage alloc] initWithHandler:handler]]]; + [_wrappedCall startBatchWithOperations:@[ [[GRPCOpRecvMessage alloc] initWithHandler:handler] ]]; } // Called initially from the network queue once response headers are received, @@ -287,15 +289,21 @@ static NSString * const kBearerPrefix = @"Bearer "; // don't want to throw, because the app shouldn't crash for a behavior // that's on the hands of any server to have. Instead we finish and ask // the server to cancel. - [strongSelf maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeResourceExhausted - userInfo:@{NSLocalizedDescriptionKey: @"Client does not have enough memory to hold the server response."}]]; + [strongSelf + maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeResourceExhausted + userInfo:@{ + NSLocalizedDescriptionKey : + @"Client does not have enough memory to " + @"hold the server response." + }]]; [strongSelf cancelCall]; return; } - [strongWriteable enqueueValue:data completionHandler:^{ - [strongSelf startNextRead]; - }]; + [strongWriteable enqueueValue:data + completionHandler:^{ + [strongSelf startNextRead]; + }]; }]; }); } @@ -304,11 +312,12 @@ static NSString * const kBearerPrefix = @"Bearer "; - (void)sendHeaders:(NSDictionary *)headers { // TODO(jcanizales): Add error handlers for async failures - GRPCOpSendMetadata *op = [[GRPCOpSendMetadata alloc] initWithMetadata:headers - flags:[GRPCCall callFlagsForHost:_host path:_path] - handler:nil]; // No clean-up needed after SEND_INITIAL_METADATA + GRPCOpSendMetadata *op = [[GRPCOpSendMetadata alloc] + initWithMetadata:headers + flags:[GRPCCall callFlagsForHost:_host path:_path] + handler:nil]; // No clean-up needed after SEND_INITIAL_METADATA if (!_unaryCall) { - [_wrappedCall startBatchWithOperations:@[op]]; + [_wrappedCall startBatchWithOperations:@[ op ]]; } else { [_unaryOpBatch addObject:op]; } @@ -321,9 +330,8 @@ static NSString * const kBearerPrefix = @"Bearer "; // If the call is a unary call, parameter \a errorHandler will be ignored and // the error handler of GRPCOpSendClose will be executed in case of error. - (void)writeMessage:(NSData *)message withErrorHandler:(void (^)(void))errorHandler { - __weak GRPCCall *weakSelf = self; - void(^resumingHandler)(void) = ^{ + void (^resumingHandler)(void) = ^{ // Resume the request writer. GRPCCall *strongSelf = weakSelf; if (strongSelf) { @@ -333,11 +341,10 @@ static NSString * const kBearerPrefix = @"Bearer "; } }; - GRPCOpSendMessage *op = [[GRPCOpSendMessage alloc] initWithMessage:message - handler:resumingHandler]; + GRPCOpSendMessage *op = + [[GRPCOpSendMessage alloc] initWithMessage:message handler:resumingHandler]; if (!_unaryCall) { - [_wrappedCall startBatchWithOperations:@[op] - errorHandler:errorHandler]; + [_wrappedCall startBatchWithOperations:@[ op ] errorHandler:errorHandler]; } else { // Ignored errorHandler since it is the same as the one for GRPCOpSendClose. // TODO (mxyan): unify the error handlers of all Ops into a single closure. @@ -364,12 +371,11 @@ static NSString * const kBearerPrefix = @"Bearer "; // network queue if the requests stream couldn't be closed successfully. - (void)finishRequestWithErrorHandler:(void (^)(void))errorHandler { if (!_unaryCall) { - [_wrappedCall startBatchWithOperations:@[[[GRPCOpSendClose alloc] init]] + [_wrappedCall startBatchWithOperations:@[ [[GRPCOpSendClose alloc] init] ] errorHandler:errorHandler]; } else { [_unaryOpBatch addObject:[[GRPCOpSendClose alloc] init]]; - [_wrappedCall startBatchWithOperations:_unaryOpBatch - errorHandler:errorHandler]; + [_wrappedCall startBatchWithOperations:_unaryOpBatch errorHandler:errorHandler]; } } @@ -390,13 +396,13 @@ static NSString * const kBearerPrefix = @"Bearer "; // after this. // The first one (headersHandler), when the response headers are received. // The second one (completionHandler), whenever the RPC finishes for any reason. -- (void)invokeCallWithHeadersHandler:(void(^)(NSDictionary *))headersHandler - completionHandler:(void(^)(NSError *, NSDictionary *))completionHandler { +- (void)invokeCallWithHeadersHandler:(void (^)(NSDictionary *))headersHandler + completionHandler:(void (^)(NSError *, NSDictionary *))completionHandler { // TODO(jcanizales): Add error handlers for async failures - [_wrappedCall startBatchWithOperations:@[[[GRPCOpRecvMetadata alloc] - initWithHandler:headersHandler]]]; - [_wrappedCall startBatchWithOperations:@[[[GRPCOpRecvStatus alloc] - initWithHandler:completionHandler]]]; + [_wrappedCall + startBatchWithOperations:@[ [[GRPCOpRecvMetadata alloc] initWithHandler:headersHandler] ]]; + [_wrappedCall + startBatchWithOperations:@[ [[GRPCOpRecvStatus alloc] initWithHandler:completionHandler] ]]; } - (void)invokeCall { @@ -408,30 +414,31 @@ static NSString * const kBearerPrefix = @"Bearer "; strongSelf.responseHeaders = headers; [strongSelf startNextRead]; } - } completionHandler:^(NSError *error, NSDictionary *trailers) { - __strong GRPCCall *strongSelf = weakSelf; - if (strongSelf) { - strongSelf.responseTrailers = trailers; - - if (error) { - NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; - if (error.userInfo) { - [userInfo addEntriesFromDictionary:error.userInfo]; - } - userInfo[kGRPCTrailersKey] = strongSelf.responseTrailers; - // TODO(jcanizales): The C gRPC library doesn't guarantee that the headers block will be - // called before this one, so an error might end up with trailers but no headers. We - // shouldn't call finishWithError until ater both blocks are called. It is also when this is - // done that we can provide a merged view of response headers and trailers in a thread-safe - // way. - if (strongSelf.responseHeaders) { - userInfo[kGRPCHeadersKey] = strongSelf.responseHeaders; + } + completionHandler:^(NSError *error, NSDictionary *trailers) { + __strong GRPCCall *strongSelf = weakSelf; + if (strongSelf) { + strongSelf.responseTrailers = trailers; + + if (error) { + NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; + if (error.userInfo) { + [userInfo addEntriesFromDictionary:error.userInfo]; + } + userInfo[kGRPCTrailersKey] = strongSelf.responseTrailers; + // TODO(jcanizales): The C gRPC library doesn't guarantee that the headers block will be + // called before this one, so an error might end up with trailers but no headers. We + // shouldn't call finishWithError until ater both blocks are called. It is also when + // this is done that we can provide a merged view of response headers and trailers in a + // thread-safe way. + if (strongSelf.responseHeaders) { + userInfo[kGRPCHeadersKey] = strongSelf.responseHeaders; + } + error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; + } + [strongSelf maybeFinishWithError:error]; } - error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; - } - [strongSelf maybeFinishWithError:error]; - } - }]; + }]; // Now that the RPC has been initiated, request writes can start. @synchronized(_requestWriter) { [_requestWriter startWithWriteable:self]; @@ -441,8 +448,8 @@ static NSString * const kBearerPrefix = @"Bearer "; #pragma mark GRXWriter implementation - (void)startCallWithWriteable:(id)writeable { - _responseWriteable = [[GRXConcurrentWriteable alloc] initWithWriteable:writeable - dispatchQueue:_responseQueue]; + _responseWriteable = + [[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue]; _wrappedCall = [[GRPCWrappedCall alloc] initWithHost:_host serverName:_serverName @@ -453,8 +460,7 @@ static NSString * const kBearerPrefix = @"Bearer "; [self sendHeaders:_requestHeaders]; [self invokeCall]; - [GRPCConnectivityMonitor registerObserver:self - selector:@selector(connectivityChanged:)]; + [GRPCConnectivityMonitor registerObserver:self selector:@selector(connectivityChanged:)]; } - (void)startWithWriteable:(id)writeable { @@ -472,7 +478,7 @@ static NSString * const kBearerPrefix = @"Bearer "; if (self.tokenProvider != nil) { self.isWaitingForToken = YES; __weak typeof(self) weakSelf = self; - [self.tokenProvider getTokenWithHandler:^(NSString *token){ + [self.tokenProvider getTokenWithHandler:^(NSString *token) { typeof(self) strongSelf = weakSelf; if (strongSelf && strongSelf.isWaitingForToken) { if (token) { @@ -521,7 +527,9 @@ static NSString * const kBearerPrefix = @"Bearer "; - (void)connectivityChanged:(NSNotification *)note { [self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain code:GRPCErrorCodeUnavailable - userInfo:@{ NSLocalizedDescriptionKey : @"Connectivity lost." }]]; + userInfo:@{ + NSLocalizedDescriptionKey : @"Connectivity lost." + }]]; // Cancel underlying call upon this notification [self cancelCall]; } diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h index d37182f754..6499d4398c 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCChannel.h @@ -23,7 +23,6 @@ @class GRPCCompletionQueue; struct grpc_channel_credentials; - /** * Each separate instance of this class represents at least one TCP connection to the provided host. */ @@ -52,8 +51,9 @@ struct grpc_channel_credentials; * @c channelArgs. Only in tests should @c GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg be set. */ + (nonnull GRPCChannel *)secureChannelWithHost:(nonnull NSString *)host - credentials:(nonnull struct grpc_channel_credentials *)credentials - channelArgs:(nullable NSDictionary *)channelArgs; + credentials: + (nonnull struct grpc_channel_credentials *)credentials + channelArgs:(nullable NSDictionary *)channelArgs; /** * Creates an insecure channel to the specified @c host using the specified @c channelArgs. diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index b53d84159d..a49a489ea8 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -32,7 +32,7 @@ #endif #import "GRPCCompletionQueue.h" -static void* copy_pointer_arg(void *p) { +static void *copy_pointer_arg(void *p) { // Add ref count to the object when making copy id obj = (__bridge id)p; return (__bridge_retained void *)obj; @@ -43,12 +43,10 @@ static void destroy_pointer_arg(void *p) { CFRelease((CFTreeRef)p); } -static int cmp_pointer_arg(void *p, void *q) { - return p == q; -} +static int cmp_pointer_arg(void *p, void *q) { return p == q; } -static const grpc_arg_pointer_vtable objc_arg_vtable = { - copy_pointer_arg, destroy_pointer_arg, cmp_pointer_arg}; +static const grpc_arg_pointer_vtable objc_arg_vtable = {copy_pointer_arg, destroy_pointer_arg, + cmp_pointer_arg}; static void FreeChannelArgs(grpc_channel_args *channel_args) { for (size_t i = 0; i < channel_args->num_args; ++i) { @@ -124,10 +122,8 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { if (self = [super init]) { _channelArgs = BuildChannelArgs(channelArgs); _host = [host copy]; - _unmanagedChannel = grpc_cronet_secure_channel_create(cronetEngine, - _host.UTF8String, - _channelArgs, - NULL); + _unmanagedChannel = + grpc_cronet_secure_channel_create(cronetEngine, _host.UTF8String, _channelArgs, NULL); } return self; @@ -150,8 +146,8 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { _channelArgs = BuildChannelArgs(channelArgs); _host = [host copy]; if (secure) { - _unmanagedChannel = grpc_secure_channel_create(credentials, _host.UTF8String, _channelArgs, - NULL); + _unmanagedChannel = + grpc_secure_channel_create(credentials, _host.UTF8String, _channelArgs, NULL); } else { _unmanagedChannel = grpc_insecure_channel_create(_host.UTF8String, _channelArgs, NULL); } @@ -172,8 +168,7 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { channelArgs:(NSDictionary *)channelArgs { stream_engine *engine = [GRPCCall cronetEngine]; if (!engine) { - [NSException raise:NSInvalidArgumentException - format:@"cronet_engine is NULL. Set it first."]; + [NSException raise:NSInvalidArgumentException format:@"cronet_engine is NULL. Set it first."]; return nil; } return [[GRPCChannel alloc] initWithHost:host cronetEngine:engine channelArgs:channelArgs]; @@ -191,15 +186,10 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { secure:YES credentials:credentials channelArgs:channelArgs]; - } -+ (GRPCChannel *)insecureChannelWithHost:(NSString *)host - channelArgs:(NSDictionary *)channelArgs { - return [[GRPCChannel alloc] initWithHost:host - secure:NO - credentials:NULL - channelArgs:channelArgs]; ++ (GRPCChannel *)insecureChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)channelArgs { + return [[GRPCChannel alloc] initWithHost:host secure:NO credentials:NULL channelArgs:channelArgs]; } - (grpc_call *)unmanagedCallWithPath:(NSString *)path @@ -215,17 +205,13 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { host_slice = grpc_slice_from_copied_string(serverName.UTF8String); } grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String); - gpr_timespec deadline_ms = timeout == 0 ? - gpr_inf_future(GPR_CLOCK_REALTIME) : - gpr_time_add( - gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_millis((int64_t)(timeout * 1000), GPR_TIMESPAN)); - grpc_call *call = grpc_channel_create_call(_unmanagedChannel, - NULL, GRPC_PROPAGATE_DEFAULTS, - queue.unmanagedQueue, - path_slice, - serverName ? &host_slice : NULL, - deadline_ms, NULL); + gpr_timespec deadline_ms = + timeout == 0 ? gpr_inf_future(GPR_CLOCK_REALTIME) + : gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_millis((int64_t)(timeout * 1000), GPR_TIMESPAN)); + grpc_call *call = grpc_channel_create_call(_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS, + queue.unmanagedQueue, path_slice, + serverName ? &host_slice : NULL, deadline_ms, NULL); if (serverName) { grpc_slice_unref(host_slice); } diff --git a/src/objective-c/GRPCClient/private/GRPCCompletionQueue.h b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.h index 41f5da3dfc..5b017b45e6 100644 --- a/src/objective-c/GRPCClient/private/GRPCCompletionQueue.h +++ b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.h @@ -19,7 +19,7 @@ #import #include -typedef void(^GRPCQueueCompletionHandler)(bool success); +typedef void (^GRPCQueueCompletionHandler)(bool success); /** * This class lets one more easily use |grpc_completion_queue|. To use it, pass the value of the diff --git a/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m index 7ba197810e..57dbde8d04 100644 --- a/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m +++ b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m @@ -53,9 +53,8 @@ dispatch_async(gDefaultConcurrentQueue, ^{ while (YES) { // The following call blocks until an event is available. - grpc_event event = grpc_completion_queue_next(unmanagedQueue, - gpr_inf_future(GPR_CLOCK_REALTIME), - NULL); + grpc_event event = + grpc_completion_queue_next(unmanagedQueue, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GRPCQueueCompletionHandler handler; switch (event.type) { case GRPC_OP_COMPLETE: diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h index 394d21792d..d4b49b1b28 100644 --- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h +++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h @@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, GRPCConnectivityStatus) { GRPCConnectivityWiFi = 3, }; -extern NSString * _Nonnull kGRPCConnectivityNotification; +extern NSString* _Nonnull kGRPCConnectivityNotification; // This interface monitors OS reachability interface for any network status // change. Parties interested in these events should register themselves as @@ -39,8 +39,7 @@ extern NSString * _Nonnull kGRPCConnectivityNotification; // must have a notification method with one parameter of type // (NSNotification *) and should pass it to parameter \a selector. The // parameter of this notification method is not used for now. -+ (void)registerObserver:(_Nonnull id)observer - selector:(_Nonnull SEL)selector; ++ (void)registerObserver:(_Nonnull id)observer selector:(_Nonnull SEL)selector; // Ungegister an object from observers of network status change. + (void)unregisterObserver:(_Nonnull id)observer; diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m index 7f31c7e23e..a36788b35a 100644 --- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m +++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m @@ -41,8 +41,8 @@ GRPCConnectivityStatus CalculateConnectivityStatus(SCNetworkReachabilityFlags fl return result; } -static void ReachabilityCallback( - SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) { +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, + void *info) { GRPCConnectivityStatus newStatus = CalculateConnectivityStatus(flags); if (newStatus != currentStatus) { @@ -69,15 +69,14 @@ static void ReachabilityCallback( SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; if (!SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback, &context) || - !SCNetworkReachabilityScheduleWithRunLoop( - reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes)) { + !SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), + kCFRunLoopCommonModes)) { NSLog(@"gRPC connectivity monitor fail to set"); } } } -+ (void)registerObserver:(_Nonnull id)observer - selector:(SEL)selector { ++ (void)registerObserver:(_Nonnull id)observer selector:(SEL)selector { [[NSNotificationCenter defaultCenter] addObserver:observer selector:selector name:kGRPCConnectivityNotification diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h index a1d2e5fcdd..6697f61be4 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.h +++ b/src/objective-c/GRPCClient/private/GRPCHost.h @@ -47,7 +47,6 @@ struct grpc_channel_credentials; /** The default response size limit is 4MB. Set this to override that default. */ @property(nonatomic, strong, nullable) NSNumber *responseSizeLimitOverride; - - (nullable instancetype)init NS_UNAVAILABLE; /** Host objects initialized with the same address are the same. */ + (nullable instancetype)hostWithAddress:(NSString *)address; diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 152c3d3ed6..283306262a 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -18,10 +18,10 @@ #import "GRPCHost.h" +#import +#import #include #include -#import -#import #ifdef GRPC_COMPILE_WITH_CRONET #import #import @@ -91,16 +91,15 @@ static NSMutableDictionary *kHostCache; + (void)flushChannelCache { @synchronized(kHostCache) { - [kHostCache enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, - GRPCHost * _Nonnull host, - BOOL * _Nonnull stop) { + [kHostCache enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, GRPCHost *_Nonnull host, + BOOL *_Nonnull stop) { [host disconnect]; }]; } } + (void)resetAllHostSettings { - @synchronized (kHostCache) { + @synchronized(kHostCache) { kHostCache = [NSMutableDictionary dictionary]; } } @@ -131,38 +130,38 @@ static NSMutableDictionary *kHostCache; static NSError *kDefaultRootsError; static dispatch_once_t loading; dispatch_once(&loading, ^{ - NSString *defaultPath = @"gRPCCertificates.bundle/roots"; // .pem + NSString *defaultPath = @"gRPCCertificates.bundle/roots"; // .pem // Do not use NSBundle.mainBundle, as it's nil for tests of library projects. NSBundle *bundle = [NSBundle bundleForClass:self.class]; NSString *path = [bundle pathForResource:defaultPath ofType:@"pem"]; NSError *error; // Files in PEM format can have non-ASCII characters in their comments (e.g. for the name of the // issuer). Load them as UTF8 and produce an ASCII equivalent. - NSString *contentInUTF8 = [NSString stringWithContentsOfFile:path - encoding:NSUTF8StringEncoding - error:&error]; + NSString *contentInUTF8 = + [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; if (contentInUTF8 == nil) { kDefaultRootsError = error; return; } - kDefaultRootsASCII = [contentInUTF8 dataUsingEncoding:NSASCIIStringEncoding - allowLossyConversion:YES]; + kDefaultRootsASCII = + [contentInUTF8 dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; }); NSData *rootsASCII; if (pemRootCerts != nil) { - rootsASCII = [pemRootCerts dataUsingEncoding:NSASCIIStringEncoding - allowLossyConversion:YES]; + rootsASCII = [pemRootCerts dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; } else { if (kDefaultRootsASCII == nil) { if (errorPtr) { *errorPtr = kDefaultRootsError; } - NSAssert(kDefaultRootsASCII, @"Could not read gRPCCertificates.bundle/roots.pem. This file, " - "with the root certificates, is needed to establish secure (TLS) connections. " - "Because the file is distributed with the gRPC library, this error is usually a sign " - "that the library wasn't configured correctly for your project. Error: %@", - kDefaultRootsError); + NSAssert( + kDefaultRootsASCII, + @"Could not read gRPCCertificates.bundle/roots.pem. This file, " + "with the root certificates, is needed to establish secure (TLS) connections. " + "Because the file is distributed with the gRPC library, this error is usually a sign " + "that the library wasn't configured correctly for your project. Error: %@", + kDefaultRootsError); return NO; } rootsASCII = kDefaultRootsASCII; @@ -173,10 +172,10 @@ static NSMutableDictionary *kHostCache; creds = grpc_ssl_credentials_create(rootsASCII.bytes, NULL, NULL); } else { grpc_ssl_pem_key_cert_pair key_cert_pair; - NSData *privateKeyASCII = [pemPrivateKey dataUsingEncoding:NSASCIIStringEncoding - allowLossyConversion:YES]; - NSData *certChainASCII = [pemCertChain dataUsingEncoding:NSASCIIStringEncoding - allowLossyConversion:YES]; + NSData *privateKeyASCII = + [pemPrivateKey dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; + NSData *certChainASCII = + [pemCertChain dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; key_cert_pair.private_key = privateKeyASCII.bytes; key_cert_pair.cert_chain = certChainASCII.bytes; creds = grpc_ssl_credentials_create(rootsASCII.bytes, &key_cert_pair, NULL); @@ -212,8 +211,7 @@ static NSMutableDictionary *kHostCache; } if (_compressAlgorithm != GRPC_COMPRESS_NONE) { - args[@GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM] = - [NSNumber numberWithInt:_compressAlgorithm]; + args[@GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM] = [NSNumber numberWithInt:_compressAlgorithm]; } if (_keepaliveInterval != 0) { @@ -247,14 +245,12 @@ static NSMutableDictionary *kHostCache; } #ifdef GRPC_COMPILE_WITH_CRONET if (useCronet) { - channel = [GRPCChannel secureCronetChannelWithHost:_address - channelArgs:args]; + channel = [GRPCChannel secureCronetChannelWithHost:_address channelArgs:args]; } else #endif { - channel = [GRPCChannel secureChannelWithHost:_address - credentials:_channelCreds - channelArgs:args]; + channel = + [GRPCChannel secureChannelWithHost:_address credentials:_channelCreds channelArgs:args]; } } return channel; diff --git a/src/objective-c/GRPCClient/private/GRPCOpBatchLog.h b/src/objective-c/GRPCClient/private/GRPCOpBatchLog.h index ca4b6c5885..700d19a206 100644 --- a/src/objective-c/GRPCClient/private/GRPCOpBatchLog.h +++ b/src/objective-c/GRPCClient/private/GRPCOpBatchLog.h @@ -16,7 +16,6 @@ * */ - #ifdef GRPC_TEST_OBJC /** diff --git a/src/objective-c/GRPCClient/private/GRPCOpBatchLog.m b/src/objective-c/GRPCClient/private/GRPCOpBatchLog.m index fdf0fcd25e..008232464d 100644 --- a/src/objective-c/GRPCClient/private/GRPCOpBatchLog.m +++ b/src/objective-c/GRPCClient/private/GRPCOpBatchLog.m @@ -25,7 +25,7 @@ static NSMutableArray *opBatchLog = nil; @implementation GRPCOpBatchLog + (void)enableOpBatchLog:(BOOL)enabled { - @synchronized (opBatchLog) { + @synchronized(opBatchLog) { if (enabled) { if (!opBatchLog) { opBatchLog = [NSMutableArray array]; @@ -39,13 +39,13 @@ static NSMutableArray *opBatchLog = nil; } + (void)addOpBatchToLog:(NSArray *)batch { - @synchronized (opBatchLog) { + @synchronized(opBatchLog) { [opBatchLog addObject:batch]; } } + (NSArray *)obtainAndCleanOpBatchLog { - @synchronized (opBatchLog) { + @synchronized(opBatchLog) { NSArray *out = opBatchLog; opBatchLog = [NSMutableArray array]; return out; diff --git a/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h b/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h index 9e32fb5df8..2e8e34ee30 100644 --- a/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h +++ b/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h @@ -17,7 +17,8 @@ */ /** - * "X-macro" file that lists the flags names of Apple's Network Reachability API, along with a nice + * "X-macro" file that lists the flags names of Apple's Network Reachability +API, along with a nice * Objective-C method name used to query each of them. * * Example usage: To generate a dictionary from flag value to name, one can do: @@ -29,7 +30,8 @@ #undef GRPC_XMACRO_ITEM }; - XCTAssertEqualObjects(flagNames[@(kSCNetworkReachabilityFlagsIsWWAN)], @"isCell"); + XCTAssertEqualObjects(flagNames[@(kSCNetworkReachabilityFlagsIsWWAN)], +@"isCell"); */ diff --git a/src/objective-c/GRPCClient/private/GRPCRequestHeaders.m b/src/objective-c/GRPCClient/private/GRPCRequestHeaders.m index 5de1d8fff5..fa4f022ff0 100644 --- a/src/objective-c/GRPCClient/private/GRPCRequestHeaders.m +++ b/src/objective-c/GRPCClient/private/GRPCRequestHeaders.m @@ -23,7 +23,7 @@ #import "NSDictionary+GRPC.h" // Used by the setter. -static void CheckIsNonNilASCII(NSString *name, NSString* value) { +static void CheckIsNonNilASCII(NSString *name, NSString *value) { if (!value) { [NSException raise:NSInvalidArgumentException format:@"%@ cannot be nil", name]; } @@ -38,14 +38,18 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) { if ([key hasSuffix:@"-bin"]) { if (![value isKindOfClass:NSData.class]) { [NSException raise:NSInvalidArgumentException - format:@"Expected NSData value for header %@ ending in \"-bin\", " - @"instead got %@", key, value]; + format: + @"Expected NSData value for header %@ ending in \"-bin\", " + @"instead got %@", + key, value]; } } else { if (![value isKindOfClass:NSString.class]) { [NSException raise:NSInvalidArgumentException - format:@"Expected NSString value for header %@ not ending in \"-bin\", " - @"instead got %@", key, value]; + format: + @"Expected NSString value for header %@ not ending in \"-bin\", " + @"instead got %@", + key, value]; } CheckIsNonNilASCII(@"Text header value", (NSString *)value); } @@ -85,8 +89,8 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) { return self; } -- (instancetype)initWithObjects:(const id _Nonnull __unsafe_unretained *)objects - forKeys:(const id _Nonnull __unsafe_unretained *)keys +- (instancetype)initWithObjects:(const id _Nonnull __unsafe_unretained *)objects + forKeys:(const id _Nonnull __unsafe_unretained *)keys count:(NSUInteger)cnt { return [self init]; } @@ -118,7 +122,7 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) { return _delegate.count; } -- (NSEnumerator * _Nonnull)keyEnumerator { +- (NSEnumerator *_Nonnull)keyEnumerator { return [_delegate keyEnumerator]; } diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h index f569895e7c..f711850c2f 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h @@ -29,43 +29,42 @@ @interface GRPCOpSendMetadata : GRPCOperation -- (instancetype)initWithMetadata:(NSDictionary *)metadata - handler:(void(^)(void))handler; +- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)(void))handler; - (instancetype)initWithMetadata:(NSDictionary *)metadata flags:(uint32_t)flags - handler:(void(^)(void))handler NS_DESIGNATED_INITIALIZER; + handler:(void (^)(void))handler NS_DESIGNATED_INITIALIZER; @end @interface GRPCOpSendMessage : GRPCOperation - (instancetype)initWithMessage:(NSData *)message - handler:(void(^)(void))handler NS_DESIGNATED_INITIALIZER; + handler:(void (^)(void))handler NS_DESIGNATED_INITIALIZER; @end @interface GRPCOpSendClose : GRPCOperation -- (instancetype)initWithHandler:(void(^)(void))handler NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithHandler:(void (^)(void))handler NS_DESIGNATED_INITIALIZER; @end @interface GRPCOpRecvMetadata : GRPCOperation -- (instancetype)initWithHandler:(void(^)(NSDictionary *))handler NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithHandler:(void (^)(NSDictionary *))handler NS_DESIGNATED_INITIALIZER; @end @interface GRPCOpRecvMessage : GRPCOperation -- (instancetype)initWithHandler:(void(^)(grpc_byte_buffer *))handler NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler NS_DESIGNATED_INITIALIZER; @end @interface GRPCOpRecvStatus : GRPCOperation -- (instancetype)initWithHandler:(void(^)(NSError *, NSDictionary *))handler +- (instancetype)initWithHandler:(void (^)(NSError *, NSDictionary *))handler NS_DESIGNATED_INITIALIZER; @end @@ -79,7 +78,7 @@ path:(NSString *)path timeout:(NSTimeInterval)timeout NS_DESIGNATED_INITIALIZER; -- (void)startBatchWithOperations:(NSArray *)ops errorHandler:(void(^)(void))errorHandler; +- (void)startBatchWithOperations:(NSArray *)ops errorHandler:(void (^)(void))errorHandler; - (void)startBatchWithOperations:(NSArray *)ops; diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index 9a0fa5954a..f28e494868 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -19,29 +19,29 @@ #import "GRPCWrappedCall.h" #import -#include #include +#include #include #import "GRPCCompletionQueue.h" #import "GRPCHost.h" -#import "NSDictionary+GRPC.h" #import "NSData+GRPC.h" +#import "NSDictionary+GRPC.h" #import "NSError+GRPC.h" #import "GRPCOpBatchLog.h" @implementation GRPCOperation { -@protected + @protected // Most operation subclasses don't set any flags in the grpc_op, and rely on the flag member being // initialized to zero. grpc_op _op; - void(^_handler)(void); + void (^_handler)(void); } - (void)finish { if (_handler) { - void(^handler)(void) = _handler; + void (^handler)(void) = _handler; _handler = nil; handler(); } @@ -54,8 +54,7 @@ return [self initWithMetadata:nil flags:0 handler:nil]; } -- (instancetype)initWithMetadata:(NSDictionary *)metadata - handler:(void (^)(void))handler { +- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)(void))handler { return [self initWithMetadata:metadata flags:0 handler:handler]; } @@ -128,11 +127,11 @@ grpc_metadata_array _headers; } -- (instancetype) init { +- (instancetype)init { return [self initWithHandler:nil]; } -- (instancetype) initWithHandler:(void (^)(NSDictionary *))handler { +- (instancetype)initWithHandler:(void (^)(NSDictionary *))handler { if (self = [super init]) { _op.op = GRPC_OP_RECV_INITIAL_METADATA; grpc_metadata_array_init(&_headers); @@ -142,8 +141,8 @@ __weak typeof(self) weakSelf = self; _handler = ^{ __strong typeof(self) strongSelf = weakSelf; - NSDictionary *metadata = [NSDictionary - grpc_dictionaryFromMetadataArray:strongSelf->_headers]; + NSDictionary *metadata = + [NSDictionary grpc_dictionaryFromMetadataArray:strongSelf->_headers]; handler(metadata); }; } @@ -157,7 +156,7 @@ @end -@implementation GRPCOpRecvMessage{ +@implementation GRPCOpRecvMessage { grpc_byte_buffer *_receivedMessage; } @@ -183,18 +182,18 @@ @end -@implementation GRPCOpRecvStatus{ +@implementation GRPCOpRecvStatus { grpc_status_code _statusCode; grpc_slice _details; size_t _detailsCapacity; grpc_metadata_array _trailers; } -- (instancetype) init { +- (instancetype)init { return [self initWithHandler:nil]; } -- (instancetype) initWithHandler:(void (^)(NSError *, NSDictionary *))handler { +- (instancetype)initWithHandler:(void (^)(NSError *, NSDictionary *))handler { if (self = [super init]) { _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; _op.data.recv_status_on_client.status = &_statusCode; @@ -208,10 +207,10 @@ __strong typeof(self) strongSelf = weakSelf; if (strongSelf) { char *details = grpc_slice_to_c_string(strongSelf->_details); - NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode - details:details]; - NSDictionary *trailers = [NSDictionary - grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; + NSError *error = + [NSError grpc_errorFromStatusCode:strongSelf->_statusCode details:details]; + NSDictionary *trailers = + [NSDictionary grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; handler(error, trailers); gpr_free(details); } @@ -244,8 +243,7 @@ path:(NSString *)path timeout:(NSTimeInterval)timeout { if (!path || !host) { - [NSException raise:NSInvalidArgumentException - format:@"path and host cannot be nil."]; + [NSException raise:NSInvalidArgumentException format:@"path and host cannot be nil."]; } if (self = [super init]) { @@ -270,8 +268,8 @@ } - (void)startBatchWithOperations:(NSArray *)operations errorHandler:(void (^)(void))errorHandler { - // Keep logs of op batches when we are running tests. Disabled when in production for improved - // performance. +// Keep logs of op batches when we are running tests. Disabled when in production for improved +// performance. #ifdef GRPC_TEST_OBJC [GRPCOpBatchLog addOpBatchToLog:operations]; #endif @@ -282,25 +280,26 @@ for (GRPCOperation *operation in operations) { ops_array[i++] = operation.op; } - grpc_call_error error = grpc_call_start_batch(_call, ops_array, nops, - (__bridge_retained void *)(^(bool success){ - if (!success) { - if (errorHandler) { - errorHandler(); - } else { - return; - } - } - for (GRPCOperation *operation in operations) { - [operation finish]; - } - }), NULL); + grpc_call_error error = + grpc_call_start_batch(_call, ops_array, nops, (__bridge_retained void *)(^(bool success) { + if (!success) { + if (errorHandler) { + errorHandler(); + } else { + return; + } + } + for (GRPCOperation *operation in operations) { + [operation finish]; + } + }), + NULL); gpr_free(ops_array); if (error != GRPC_CALL_OK) { - [NSException raise:NSInternalInconsistencyException - format:@"A precondition for calling grpc_call_start_batch wasn't met. Error %i", - error]; + [NSException + raise:NSInternalInconsistencyException + format:@"A precondition for calling grpc_call_start_batch wasn't met. Error %i", error]; } } diff --git a/src/objective-c/GRPCClient/private/NSData+GRPC.m b/src/objective-c/GRPCClient/private/NSData+GRPC.m index 7c46594dd5..5064da310e 100644 --- a/src/objective-c/GRPCClient/private/NSData+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSData+GRPC.m @@ -24,8 +24,8 @@ // TODO(jcanizales): Move these two incantations to the C library. -static void MallocAndCopyByteBufferToCharArray(grpc_byte_buffer *buffer, - size_t *length, char **array) { +static void MallocAndCopyByteBufferToCharArray(grpc_byte_buffer *buffer, size_t *length, + char **array) { grpc_byte_buffer_reader reader; if (!grpc_byte_buffer_reader_init(&reader, buffer)) { // grpc_byte_buffer_reader_init can fail if the data sent by the server @@ -51,8 +51,7 @@ static void MallocAndCopyByteBufferToCharArray(grpc_byte_buffer *buffer, grpc_byte_buffer_reader_destroy(&reader); } -static grpc_byte_buffer *CopyCharArrayToNewByteBuffer(const char *array, - size_t length) { +static grpc_byte_buffer *CopyCharArrayToNewByteBuffer(const char *array, size_t length) { grpc_slice slice = grpc_slice_from_copied_buffer(array, length); grpc_byte_buffer *buffer = grpc_raw_byte_buffer_create(&slice, 1); grpc_slice_unref(slice); @@ -89,7 +88,6 @@ static grpc_byte_buffer *CopyCharArrayToNewByteBuffer(const char *array, // to create an array of grpc_slice objects to pass to // grpc_raw_byte_buffer_create. // That would make it do exactly one copy, always. - return CopyCharArrayToNewByteBuffer((const char *)self.bytes, - (size_t)self.length); + return CopyCharArrayToNewByteBuffer((const char *)self.bytes, (size_t)self.length); } @end diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index 4af7cb9a01..af1ce0bf23 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -74,8 +74,7 @@ NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count]; for (grpc_metadata *entry = entries; entry < entries + count; entry++) { char *key = grpc_slice_to_c_string(entry->key); - NSString *name = [NSString stringWithCString:key - encoding:NSASCIIStringEncoding]; + NSString *name = [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; gpr_free(key); if (!name || metadata[name]) { // Log if name is nil? @@ -97,7 +96,7 @@ - (grpc_metadata *)grpc_metadataArray { grpc_metadata *metadata = gpr_malloc([self count] * sizeof(grpc_metadata)); grpc_metadata *current = metadata; - for (NSString* key in self) { + for (NSString *key in self) { id value = self[key]; current->key = grpc_slice_from_copied_string(key.UTF8String); if ([value respondsToSelector:@selector(grpc_initMetadata:)]) { diff --git a/src/objective-c/GRPCClient/private/NSError+GRPC.m b/src/objective-c/GRPCClient/private/NSError+GRPC.m index 6ba7235df4..74cfa943cc 100644 --- a/src/objective-c/GRPCClient/private/NSError+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSError+GRPC.m @@ -20,7 +20,7 @@ #include -NSString * const kGRPCErrorDomain = @"io.grpc"; +NSString *const kGRPCErrorDomain = @"io.grpc"; @implementation NSError (GRPC) + (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode details:(char *)details { @@ -30,6 +30,6 @@ NSString * const kGRPCErrorDomain = @"io.grpc"; NSString *message = [NSString stringWithCString:details encoding:NSASCIIStringEncoding]; return [NSError errorWithDomain:kGRPCErrorDomain code:statusCode - userInfo:@{NSLocalizedDescriptionKey: message}]; + userInfo:@{NSLocalizedDescriptionKey : message}]; } @end diff --git a/src/objective-c/GRPCClient/private/version.h b/src/objective-c/GRPCClient/private/version.h index a99eb289c3..1298e7e191 100644 --- a/src/objective-c/GRPCClient/private/version.h +++ b/src/objective-c/GRPCClient/private/version.h @@ -22,5 +22,4 @@ // instead. This file can be regenerated from the template by running // `tools/buildgen/generate_projects.sh`. - #define GRPC_OBJC_VERSION_STRING @"1.12.0-dev" -- cgit v1.2.3