clang-format

pull/16190/head
Muxi Yan 6 years ago
parent 6ae2ea643d
commit 4264ea2b55
  1. 10
      src/objective-c/GRPCClient/GRPCCall.h
  2. 24
      src/objective-c/GRPCClient/GRPCCall.m
  3. 12
      src/objective-c/GRPCClient/GRPCCallOptions.m
  4. 28
      src/objective-c/GRPCClient/private/GRPCChannel.m
  5. 17
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  6. 6
      src/objective-c/ProtoRPC/ProtoRPC.h
  7. 4
      src/objective-c/ProtoRPC/ProtoRPC.m
  8. 13
      src/objective-c/ProtoRPC/ProtoService.h
  9. 31
      src/objective-c/tests/ChannelTests/ChannelPoolTest.m
  10. 17
      src/objective-c/tests/GRPCClientTests.m
  11. 2
      src/objective-c/tests/InteropTests.m

@ -149,7 +149,7 @@ extern id const kGRPCHeadersKey;
extern id const kGRPCTrailersKey;
/** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCResponseHandler <NSObject>
@protocol GRPCResponseHandler<NSObject>
@optional
@ -188,10 +188,12 @@ extern id const kGRPCTrailersKey;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE;
/** Initialize with all properties. */
- (instancetype)initWithHost:(NSString *)host path:(NSString *)path safety:(GRPCCallSafety)safety NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
safety:(GRPCCallSafety)safety NS_DESIGNATED_INITIALIZER;
/** The host serving the RPC service. */
@property(copy, readonly) NSString *host;
@ -214,7 +216,7 @@ extern id const kGRPCTrailersKey;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE;
/**
* Designated initializer for a call.

@ -28,8 +28,8 @@
#include <grpc/support/time.h>
#import "GRPCCallOptions.h"
#import "private/GRPCHost.h"
#import "private/GRPCConnectivityMonitor.h"
#import "private/GRPCHost.h"
#import "private/GRPCRequestHeaders.h"
#import "private/GRPCWrappedCall.h"
#import "private/NSData+GRPC.h"
@ -115,7 +115,9 @@ const char *kCFStreamVarName = "grpc_cfstream";
_initialMetadataPublished = NO;
_pipe = [GRXBufferedPipe pipe];
if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
_dispatchQueue = dispatch_queue_create(
NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
} else {
// Fallback on earlier versions
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
@ -129,7 +131,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCResponseHandler>)responseHandler {
return [self initWithRequestOptions:requestOptions responseHandler:responseHandler callOptions:nil];
return
[self initWithRequestOptions:requestOptions responseHandler:responseHandler callOptions:nil];
}
- (void)start {
@ -255,8 +258,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
}
}
- (void)issueClosedWithTrailingMetadata:(NSDictionary *)trailingMetadata
error:(NSError *)error {
- (void)issueClosedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
id<GRPCResponseHandler> handler = _handler;
NSDictionary *trailers = _call.responseTrailers;
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
@ -388,7 +390,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
requestsWriter:(GRXWriter *)requestWriter
callOptions:(GRPCCallOptions *)callOptions {
if (host.length == 0 || path.length == 0) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil or empty."];
[NSException raise:NSInvalidArgumentException
format:@"Neither host nor path can be nil or empty."];
}
if (safety > GRPCCallSafetyCacheableRequest) {
[NSException raise:NSInvalidArgumentException format:@"Invalid call safety value."];
@ -457,7 +460,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
}
- (void)cancel {
@synchronized (self) {
@synchronized(self) {
if (!self.isWaitingForToken) {
[self cancelCall];
} else {
@ -720,7 +723,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
[self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable
userInfo:@{
NSLocalizedDescriptionKey : @"Failed to create call or channel."
NSLocalizedDescriptionKey :
@"Failed to create call or channel."
}]];
return;
}
@ -773,11 +777,11 @@ const char *kCFStreamVarName = "grpc_cfstream";
_callOptions = callOptions;
}
if (_callOptions.authTokenProvider != nil) {
@synchronized (self) {
@synchronized(self) {
self.isWaitingForToken = YES;
}
[self.tokenProvider getTokenWithHandler:^(NSString *token) {
@synchronized (self) {
@synchronized(self) {
if (self.isWaitingForToken) {
if (token) {
self->_fetchedOauth2AccessToken = [token copy];

@ -158,7 +158,8 @@ static NSUInteger kDefaultChannelID = 0;
_connectMinTimeout = connectMinTimeout;
_connectInitialBackoff = connectInitialBackoff;
_connectMaxBackoff = connectMaxBackoff;
_additionalChannelArgs = [[NSDictionary alloc] initWithDictionary:additionalChannelArgs copyItems:YES];
_additionalChannelArgs =
[[NSDictionary alloc] initWithDictionary:additionalChannelArgs copyItems:YES];
_PEMRootCertificates = [PEMRootCertificates copy];
_PEMPrivateKey = [PEMPrivateKey copy];
_PEMCertChain = [PEMCertChain copy];
@ -240,8 +241,7 @@ static NSUInteger kDefaultChannelID = 0;
if (!(callOptions.connectInitialBackoff == _connectInitialBackoff)) return NO;
if (!(callOptions.connectMaxBackoff == _connectMaxBackoff)) return NO;
if (!(callOptions.additionalChannelArgs == _additionalChannelArgs ||
[callOptions.additionalChannelArgs
isEqualToDictionary:_additionalChannelArgs]))
[callOptions.additionalChannelArgs isEqualToDictionary:_additionalChannelArgs]))
return NO;
if (!(callOptions.PEMRootCertificates == _PEMRootCertificates ||
[callOptions.PEMRootCertificates isEqualToString:_PEMRootCertificates]))
@ -256,8 +256,7 @@ static NSUInteger kDefaultChannelID = 0;
[callOptions.hostNameOverride isEqualToString:_hostNameOverride]))
return NO;
if (!(callOptions.transportType == _transportType)) return NO;
if (!(callOptions.logContext == _logContext ||
[callOptions.logContext isEqual:_logContext]))
if (!(callOptions.logContext == _logContext || [callOptions.logContext isEqual:_logContext]))
return NO;
if (!(callOptions.channelPoolDomain == _channelPoolDomain ||
[callOptions.channelPoolDomain isEqualToString:_channelPoolDomain]))
@ -482,7 +481,8 @@ static NSUInteger kDefaultChannelID = 0;
}
- (void)setAdditionalChannelArgs:(NSDictionary *)additionalChannelArgs {
_additionalChannelArgs = [[NSDictionary alloc] initWithDictionary:additionalChannelArgs copyItems:YES];
_additionalChannelArgs =
[[NSDictionary alloc] initWithDictionary:additionalChannelArgs copyItems:YES];
}
- (void)setPEMRootCertificates:(NSString *)PEMRootCertificates {

@ -75,8 +75,12 @@ NSTimeInterval kChannelDestroyDelay = 30;
_refCount = 1;
_disconnected = NO;
if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
_timerQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_DEFAULT, -1));
_dispatchQueue = dispatch_queue_create(
NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
_timerQueue =
dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(
DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_DEFAULT, -1));
} else {
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
_timerQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
@ -101,7 +105,8 @@ NSTimeInterval kChannelDestroyDelay = 30;
self->_refCount--;
if (self->_refCount == 0) {
self->_lastDispatch = [NSDate date];
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)kChannelDestroyDelay * 1e9);
dispatch_time_t delay =
dispatch_time(DISPATCH_TIME_NOW, (int64_t)kChannelDestroyDelay * 1e9);
dispatch_after(delay, self->_timerQueue, ^{
[self timerFire];
});
@ -123,7 +128,8 @@ NSTimeInterval kChannelDestroyDelay = 30;
- (void)timerFire {
dispatch_async(_dispatchQueue, ^{
if (self->_disconnected || self->_lastDispatch == nil || -[self->_lastDispatch timeIntervalSinceNow] < -kChannelDestroyDelay) {
if (self->_disconnected || self->_lastDispatch == nil ||
-[self->_lastDispatch timeIntervalSinceNow] < -kChannelDestroyDelay) {
return;
}
self->_lastDispatch = nil;
@ -158,11 +164,12 @@ NSTimeInterval kChannelDestroyDelay = 30;
}
grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String);
gpr_timespec deadline_ms =
timeout == 0 ? gpr_inf_future(GPR_CLOCK_REALTIME)
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));
call = grpc_channel_create_call(
self->_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS, queue.unmanagedQueue, path_slice,
call = grpc_channel_create_call(self->_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS,
queue.unmanagedQueue, path_slice,
serverAuthority ? &host_slice : NULL, deadline_ms, NULL);
if (serverAuthority) {
grpc_slice_unref(host_slice);
@ -214,11 +221,14 @@ NSTimeInterval kChannelDestroyDelay = 30;
if ((self = [super init])) {
_unmanagedChannel = unmanagedChannel;
_configuration = configuration;
_channelRef = [[GRPCChannelRef alloc] initWithDestroyDelay:kChannelDestroyDelay destroyChannelCallback:^{
_channelRef = [[GRPCChannelRef alloc] initWithDestroyDelay:kChannelDestroyDelay
destroyChannelCallback:^{
[self destroyChannel];
}];
if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
_dispatchQueue = dispatch_queue_create(
NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
} else {
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
}

@ -52,7 +52,8 @@ extern const char *kCFStreamVarName;
#ifdef GRPC_COMPILE_WITH_CRONET
if (![GRPCCall isUsingCronet]) {
#endif
factory = [GRPCSecureChannelFactory factoryWithPEMRootCertificates:_callOptions.PEMRootCertificates
factory = [GRPCSecureChannelFactory
factoryWithPEMRootCertificates:_callOptions.PEMRootCertificates
privateKey:_callOptions.PEMPrivateKey
certChain:_callOptions.PEMCertChain
error:&error];
@ -136,7 +137,8 @@ extern const char *kCFStreamVarName;
}
- (nonnull id)copyWithZone:(nullable NSZone *)zone {
GRPCChannelConfiguration *newConfig = [[GRPCChannelConfiguration alloc] initWithHost:_host callOptions:_callOptions];
GRPCChannelConfiguration *newConfig =
[[GRPCChannelConfiguration alloc] initWithHost:_host callOptions:_callOptions];
return newConfig;
}
@ -145,7 +147,8 @@ extern const char *kCFStreamVarName;
NSAssert([object isKindOfClass:[GRPCChannelConfiguration class]], @"Illegal :isEqual");
GRPCChannelConfiguration *obj = (GRPCChannelConfiguration *)object;
if (!(obj.host == _host || [obj.host isEqualToString:_host])) return NO;
if (!(obj.callOptions == _callOptions || [obj.callOptions isChannelOptionsEqualTo:_callOptions])) return NO;
if (!(obj.callOptions == _callOptions || [obj.callOptions isChannelOptionsEqualTo:_callOptions]))
return NO;
return YES;
}
@ -201,7 +204,9 @@ extern const char *kCFStreamVarName;
- (void)removeChannel:(GRPCChannel *)channel {
@synchronized(self) {
[_channelPool enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration * _Nonnull key, GRPCChannel * _Nonnull obj, BOOL * _Nonnull stop) {
[_channelPool
enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration *_Nonnull key,
GRPCChannel *_Nonnull obj, BOOL *_Nonnull stop) {
if (obj == channel) {
[self->_channelPool removeObjectForKey:key];
}
@ -217,7 +222,9 @@ extern const char *kCFStreamVarName;
- (void)removeAndCloseAllChannels {
@synchronized(self) {
[_channelPool enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration * _Nonnull key, GRPCChannel * _Nonnull obj, BOOL * _Nonnull stop) {
[_channelPool
enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration *_Nonnull key,
GRPCChannel *_Nonnull obj, BOOL *_Nonnull stop) {
[obj disconnect];
}];
_channelPool = [NSMutableDictionary dictionary];

@ -24,7 +24,7 @@
@class GPBMessage;
/** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCProtoResponseHandler <NSObject>
@protocol GRPCProtoResponseHandler<NSObject>
@optional
@ -59,7 +59,7 @@
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE;
/**
* Users should not use this initializer directly. Call objects will be created, initialized, and
@ -81,7 +81,7 @@
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE;
/**
* Users should not use this initializer directly. Call objects will be created, initialized, and

@ -88,7 +88,9 @@
_callOptions = [callOptions copy];
_responseClass = responseClass;
if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
_dispatchQueue = dispatch_queue_create(
NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1));
} else {
_dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL);
}

@ -30,14 +30,15 @@
__attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoService
: NSObject
- (instancetype)init NS_UNAVAILABLE;
-
(instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE;
-
(instancetype)initWithHost : (NSString *)host packageName
: (NSString *)packageName serviceName : (NSString *)serviceName callOptions
: (GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithHost:(NSString *)host
packageName:(NSString *)packageName
serviceName:(NSString *)serviceName
callOptions:(GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithHost:(NSString *)host
packageName:(NSString *)packageName

@ -57,11 +57,9 @@ NSString *kDummyHost = @"dummy.host";
GRPCChannelConfiguration *config1 =
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options1];
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCChannel *channel1 =
[pool channelWithConfiguration:config1];
GRPCChannel *channel1 = [pool channelWithConfiguration:config1];
[pool removeChannel:channel1];
GRPCChannel *channel2 =
[pool channelWithConfiguration:config1];
GRPCChannel *channel2 = [pool channelWithConfiguration:config1];
XCTAssertNotEqual(channel1, channel2);
}
@ -74,18 +72,14 @@ extern NSTimeInterval kChannelDestroyDelay;
options1.transportType = GRPCTransportTypeInsecure;
GRPCChannelConfiguration *config1 =
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options1];
GRPCChannelPool *pool =
[[GRPCChannelPool alloc] init];
GRPCChannel *channel1 =
[pool channelWithConfiguration:config1];
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCChannel *channel1 = [pool channelWithConfiguration:config1];
[channel1 unmanagedCallUnref];
sleep(1);
GRPCChannel *channel2 =
[pool channelWithConfiguration:config1];
GRPCChannel *channel2 = [pool channelWithConfiguration:config1];
XCTAssertEqual(channel1, channel2);
sleep((int)kChannelDestroyDelay + 2);
GRPCChannel *channel3 =
[pool channelWithConfiguration:config1];
GRPCChannel *channel3 = [pool channelWithConfiguration:config1];
XCTAssertEqual(channel1, channel3);
kChannelDestroyDelay = kOriginalInterval;
}
@ -101,7 +95,6 @@ extern NSTimeInterval kChannelDestroyDelay;
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options2];
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCChannel *channel1 = [pool channelWithConfiguration:config1];
[pool removeAndCloseAllChannels];
GRPCChannel *channel2 = [pool channelWithConfiguration:config2];
@ -119,17 +112,13 @@ extern NSTimeInterval kChannelDestroyDelay;
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options2];
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCChannel *channel1 =
[pool channelWithConfiguration:config1];
GRPCChannel *channel2 =
[pool channelWithConfiguration:config2];
GRPCChannel *channel1 = [pool channelWithConfiguration:config1];
GRPCChannel *channel2 = [pool channelWithConfiguration:config2];
XCTAssertNotEqual(channel1, channel2);
[pool removeAndCloseAllChannels];
GRPCChannel *channel3 =
[pool channelWithConfiguration:config1];
GRPCChannel *channel4 =
[pool channelWithConfiguration:config2];
GRPCChannel *channel3 = [pool channelWithConfiguration:config1];
GRPCChannel *channel4 = [pool channelWithConfiguration:config2];
XCTAssertNotEqual(channel1, channel3);
XCTAssertNotEqual(channel2, channel4);
}

@ -456,11 +456,9 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
expectedUserAgent = [expectedUserAgent stringByAppendingString:@" grpc-c/"];
expectedUserAgent =
[expectedUserAgent stringByAppendingString:GRPC_C_VERSION_STRING];
expectedUserAgent =
[expectedUserAgent stringByAppendingString:@" (ios; chttp2; "];
expectedUserAgent = [expectedUserAgent stringByAppendingString:@" (ios; chttp2; "];
expectedUserAgent = [expectedUserAgent
stringByAppendingString:[NSString
stringWithUTF8String:grpc_g_stands_for()]];
stringByAppendingString:[NSString stringWithUTF8String:grpc_g_stands_for()]];
expectedUserAgent = [expectedUserAgent stringByAppendingString:@")"];
XCTAssertEqualObjects(userAgent, expectedUserAgent);
@ -474,8 +472,8 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
options:0
error:&error];
NSString *customUserAgent = [regex
stringByReplacingMatchesInString:userAgent
NSString *customUserAgent =
[regex stringByReplacingMatchesInString:userAgent
options:0
range:NSMakeRange(0, [userAgent length])
withTemplate:@""];
@ -742,8 +740,7 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
responseHandler:
[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil
messageCallback:^(id data) {
XCTFail(
@"Failure: response received; Expect: no response received.");
XCTFail(@"Failure: response received; Expect: no response received.");
}
closeCallback:^(NSDictionary *trailingMetadata, NSError *error) {
XCTAssertNotNil(error,
@ -837,7 +834,9 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Timeout in a second."];
NSString *const kDummyAddress = [NSString stringWithFormat:@"127.0.0.1:10000"];
GRPCRequestOptions *requestOptions =
[[GRPCRequestOptions alloc] initWithHost:kDummyAddress path:@"/dummy/path" safety:GRPCCallSafetyDefault];
[[GRPCRequestOptions alloc] initWithHost:kDummyAddress
path:@"/dummy/path"
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
options.connectMinTimeout = timeout;
options.connectInitialBackoff = backoff;

@ -483,7 +483,7 @@ BOOL isRemoteInteropTest(NSString *host) {
id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index]
requestedResponseSize:responses[index]];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
options.transportType = [[self class] transportType ];
options.transportType = [[self class] transportType];
options.PEMRootCertificates = [[self class] PEMRootCertificates];
options.hostNameOverride = [[self class] hostNameOverride];

Loading…
Cancel
Save