clang-format

pull/16190/head
Muxi Yan 6 years ago
parent 33022c9172
commit 2895ee9b6a
  1. 22
      src/objective-c/GRPCClient/GRPCCall.m
  2. 11
      src/objective-c/GRPCClient/private/GRPCChannel.h
  3. 15
      src/objective-c/GRPCClient/private/GRPCChannel.m
  4. 3
      src/objective-c/GRPCClient/private/GRPCChannelPool.h
  5. 14
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  6. 5
      src/objective-c/GRPCClient/private/GRPCHost.m
  7. 3
      src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m
  8. 15
      src/objective-c/GRPCClient/private/utilities.h

@ -68,7 +68,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
@implementation GRPCRequestOptions
- (instancetype)initWithHost:(NSString *)host path:(NSString *)path safety:(GRPCCallSafety)safety {
GRPCAssert(host.length != 0 && path.length != 0, NSInvalidArgumentException, @"Host and Path cannot be empty");
GRPCAssert(host.length != 0 && path.length != 0, NSInvalidArgumentException,
@"Host and Path cannot be empty");
if ((self = [super init])) {
_host = [host copy];
_path = [path copy];
@ -115,8 +116,10 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCResponseHandler>)responseHandler
callOptions:(GRPCCallOptions *_Nullable)callOptions {
GRPCAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0, NSInvalidArgumentException, @"Neither host nor path can be nil.");
GRPCAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, NSInvalidArgumentException, @"Invalid call safety value.");
GRPCAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0,
NSInvalidArgumentException, @"Neither host nor path can be nil.");
GRPCAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, NSInvalidArgumentException,
@"Invalid call safety value.");
GRPCAssert(responseHandler != nil, NSInvalidArgumentException, @"Response handler required.");
if ((self = [super init])) {
@ -240,7 +243,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)writeData:(NSData *)data {
dispatch_async(_dispatchQueue, ^{
GRPCAssert(!self->_canceled, NSInternalInconsistencyException, @"Call arleady canceled.");
GRPCAssert(!self->_finished, NSInternalInconsistencyException, @"Call is half-closed before sending data.");
GRPCAssert(!self->_finished, NSInternalInconsistencyException,
@"Call is half-closed before sending data.");
if (self->_call) {
[self->_pipe writeValue:data];
}
@ -400,8 +404,10 @@ const char *kCFStreamVarName = "grpc_cfstream";
callOptions:(GRPCCallOptions *)callOptions {
// Purposely using pointer rather than length ([host length] == 0) for backwards compatibility.
GRPCAssert(host && path, NSInvalidArgumentException, @"Neither host nor path can be nil.");
GRPCAssert(safety <= GRPCCallSafetyCacheableRequest, NSInvalidArgumentException, @"Invalid call safety value.");
GRPCAssert(requestWriter.state == GRXWriterStateNotStarted, NSInvalidArgumentException, @"The requests writer can't be already started.");
GRPCAssert(safety <= GRPCCallSafetyCacheableRequest, NSInvalidArgumentException,
@"Invalid call safety value.");
GRPCAssert(requestWriter.state == GRXWriterStateNotStarted, NSInvalidArgumentException,
@"The requests writer can't be already started.");
if ((self = [super init])) {
_host = [host copy];
_path = [path copy];
@ -786,7 +792,9 @@ const char *kCFStreamVarName = "grpc_cfstream";
_callOptions = callOptions;
}
GRPCAssert(_callOptions.authTokenProvider == nil || _callOptions.oauth2AccessToken == nil, NSInvalidArgumentException, @"authTokenProvider and oauth2AccessToken cannot be set at the same time");
GRPCAssert(_callOptions.authTokenProvider == nil || _callOptions.oauth2AccessToken == nil,
NSInvalidArgumentException,
@"authTokenProvider and oauth2AccessToken cannot be set at the same time");
if (_callOptions.authTokenProvider != nil) {
@synchronized(self) {
self.isWaitingForToken = YES;

@ -64,14 +64,17 @@ NS_ASSUME_NONNULL_BEGIN
* Create a channel with remote \a host and signature \a channelConfigurations. Destroy delay is
* defaulted to 30 seconds.
*/
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration;
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration;
/**
* Create a channel with remote \a host, signature \a channelConfigurations, and destroy delay of
* \a destroyDelay.
*/
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay
NS_DESIGNATED_INITIALIZER;
/**
* Create a grpc core call object from this channel. The channel's refcount is added by 1. If no
@ -82,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path
completionQueue:(GRPCCompletionQueue *)queue
callOptions:(GRPCCallOptions *)callOptions
disconnected:(BOOL * _Nullable)disconnected;
disconnected:(BOOL *_Nullable)disconnected;
/**
* Unref the channel when a call is done. It also decreases the channel's refcount. If the refcount

@ -20,6 +20,7 @@
#include <grpc/support/log.h>
#import "../internal/GRPCCallOptions+Internal.h"
#import "ChannelArgsUtil.h"
#import "GRPCChannelFactory.h"
#import "GRPCChannelPool.h"
@ -27,9 +28,8 @@
#import "GRPCCronetChannelFactory.h"
#import "GRPCInsecureChannelFactory.h"
#import "GRPCSecureChannelFactory.h"
#import "version.h"
#import "utilities.h"
#import "../internal/GRPCCallOptions+Internal.h"
#import "version.h"
#import <GRPCClient/GRPCCall+Cronet.h>
#import <GRPCClient/GRPCCallOptions.h>
@ -172,8 +172,6 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
@end
@implementation GRPCChannel {
GRPCChannelConfiguration *_configuration;
@ -186,14 +184,17 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
}
@synthesize disconnected = _disconnected;
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration {
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration {
return [self initWithChannelConfiguration:channelConfiguration
destroyDelay:kDefaultChannelDestroyDelay];
}
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay {
GRPCAssert(channelConfiguration != nil, NSInvalidArgumentException, @"channelConfiguration must not be empty.");
GRPCAssert(channelConfiguration != nil, NSInvalidArgumentException,
@"channelConfiguration must not be empty.");
GRPCAssert(destroyDelay > 0, NSInvalidArgumentException, @"destroyDelay must be greater than 0.");
if ((self = [super init])) {
_configuration = [channelConfiguration copy];

@ -44,8 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
* Return a channel with a particular configuration. If the channel does not exist, execute \a
* createChannel then add it in the pool. If the channel exists, increase its reference count.
*/
- (GRPCChannel *)channelWithHost:(NSString *)host
callOptions:(GRPCCallOptions *)callOptions;
- (GRPCChannel *)channelWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions;
/**
* This method is deprecated.

@ -26,8 +26,8 @@
#import "GRPCCronetChannelFactory.h"
#import "GRPCInsecureChannelFactory.h"
#import "GRPCSecureChannelFactory.h"
#import "version.h"
#import "utilities.h"
#import "version.h"
#import <GRPCClient/GRPCCall+Cronet.h>
#include <grpc/support/log.h>
@ -62,11 +62,8 @@ static dispatch_once_t gInitChannelPool;
return self;
}
- (GRPCChannel *)channelWithHost:(NSString *)host
callOptions:(GRPCCallOptions *)callOptions {
return [self channelWithHost:host
callOptions:callOptions
destroyDelay:0];
- (GRPCChannel *)channelWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions {
return [self channelWithHost:host callOptions:callOptions destroyDelay:0];
}
- (GRPCChannel *)channelWithHost:(NSString *)host
@ -83,7 +80,8 @@ static dispatch_once_t gInitChannelPool;
if (destroyDelay == 0) {
channel = [[GRPCChannel alloc] initWithChannelConfiguration:configuration];
} else {
channel = [[GRPCChannel alloc] initWithChannelConfiguration:configuration destroyDelay:destroyDelay];
channel = [[GRPCChannel alloc] initWithChannelConfiguration:configuration
destroyDelay:destroyDelay];
}
_channelPool[configuration] = channel;
}
@ -91,8 +89,6 @@ static dispatch_once_t gInitChannelPool;
return channel;
}
+ (void)closeOpenConnections {
[[GRPCChannelPool sharedInstance] destroyAllChannels];
}

@ -32,8 +32,8 @@
#import "GRPCCronetChannelFactory.h"
#import "GRPCSecureChannelFactory.h"
#import "NSDictionary+GRPC.h"
#import "version.h"
#import "utilities.h"
#import "version.h"
NS_ASSUME_NONNULL_BEGIN
@ -122,7 +122,8 @@ static NSMutableDictionary *gHostCache;
if (_transportType == GRPCTransportTypeInsecure) {
options.transportType = GRPCTransportTypeInsecure;
} else {
GRPCAssert(_transportType == GRPCTransportTypeDefault, NSInvalidArgumentException, @"Invalid transport type");
GRPCAssert(_transportType == GRPCTransportTypeDefault, NSInvalidArgumentException,
@"Invalid transport type");
options.transportType = GRPCTransportTypeCronet;
}
} else

@ -84,8 +84,7 @@ NS_ASSUME_NONNULL_BEGIN
*errorPtr = defaultRootsError;
}
GRPCAssertWithArgument(
defaultRootsASCII,
NSObjectNotAvailableException,
defaultRootsASCII, NSObjectNotAvailableException,
@"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 "

@ -20,16 +20,17 @@
/** Raise exception when condition not met. Disregard NS_BLOCK_ASSERTIONS. */
#define GRPCAssert(condition, errorType, errorString) \
do { \
if (!(condition)) { \
[NSException raise:(errorType) format:(errorString)]; \
} \
} while (0)
do { \
if (!(condition)) { \
[NSException raise:(errorType)format:(errorString)]; \
} \
} while (0)
/** The same as GRPCAssert but allows arguments to be put in the raised string. */
/** The same as GRPCAssert but allows arguments to be put in the raised string.
*/
#define GRPCAssertWithArgument(condition, errorType, errorFormat, ...) \
do { \
if (!(condition)) { \
[NSException raise:(errorType) format:(errorFormat), __VA_ARGS__]; \
[NSException raise:(errorType)format:(errorFormat), __VA_ARGS__]; \
} \
} while (0)

Loading…
Cancel
Save