Polish nullability + something else

pull/16190/head
Muxi Yan 6 years ago
parent 6b6ab2bdc9
commit 8a762d4478
  1. 28
      src/objective-c/GRPCClient/GRPCCall.h
  2. 4
      src/objective-c/GRPCClient/GRPCCall.m
  3. 46
      src/objective-c/GRPCClient/GRPCCallOptions.h
  4. 2
      src/objective-c/GRPCClient/private/GRPCChannel.h
  5. 10
      src/objective-c/GRPCClient/private/GRPCChannel.m
  6. 4
      src/objective-c/GRPCClient/private/GRPCChannelFactory.h
  7. 2
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  8. 4
      src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m
  9. 22
      src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m
  10. 10
      src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m
  11. 22
      src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m
  12. 12
      src/objective-c/ProtoRPC/ProtoRPC.h
  13. 14
      src/objective-c/ProtoRPC/ProtoRPC.m
  14. 8
      src/objective-c/tests/InteropTests.m

@ -159,14 +159,14 @@ extern NSString *const kGRPCTrailersKey;
* Issued when initial metadata is received from the server. The task must be scheduled onto the * Issued when initial metadata is received from the server. The task must be scheduled onto the
* dispatch queue in property \a dispatchQueue. * dispatch queue in property \a dispatchQueue.
*/ */
- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata; - (void)receivedInitialMetadata:(nullable NSDictionary *)initialMetadata;
/** /**
* Issued when a message is received from the server. The message is the raw data received from the * Issued when a message is received from the server. The message is the raw data received from the
* server, with decompression and without proto deserialization. The task must be scheduled onto the * server, with decompression and without proto deserialization. The task must be scheduled onto the
* dispatch queue in property \a dispatchQueue. * dispatch queue in property \a dispatchQueue.
*/ */
- (void)receivedRawMessage:(NSData *_Nullable)message; - (void)receivedRawMessage:(nullable NSData *)message;
/** /**
* Issued when a call finished. If the call finished successfully, \a error is nil and \a * Issued when a call finished. If the call finished successfully, \a error is nil and \a
@ -175,8 +175,8 @@ extern NSString *const kGRPCTrailersKey;
* error descriptions. The task must be scheduled onto the dispatch queue in property * error descriptions. The task must be scheduled onto the dispatch queue in property
* \a dispatchQueue. * \a dispatchQueue.
*/ */
- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - (void)closedWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(NSError *_Nullable)error; error:(nullable NSError *)error;
@required @required
@ -234,7 +234,7 @@ extern NSString *const kGRPCTrailersKey;
*/ */
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCResponseHandler>)responseHandler responseHandler:(id<GRPCResponseHandler>)responseHandler
callOptions:(GRPCCallOptions *_Nullable)callOptions callOptions:(nullable GRPCCallOptions *)callOptions
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
/** /**
* Convenience initializer for a call that uses default call options (see GRPCCallOptions.m for * Convenience initializer for a call that uses default call options (see GRPCCallOptions.m for
@ -342,9 +342,9 @@ NS_ASSUME_NONNULL_END
* host parameter should not contain the scheme (http:// or https://), only the name or IP addr * host parameter should not contain the scheme (http:// or https://), only the name or IP addr
* and the port number, for example @"localhost:5050". * and the port number, for example @"localhost:5050".
*/ */
- (instancetype _Null_unspecified)initWithHost:(NSString *_Null_unspecified)host - (null_unspecified instancetype)initWithHost:(null_unspecified NSString *)host
path:(NSString *_Null_unspecified)path path:(null_unspecified NSString *)path
requestsWriter:(GRXWriter *_Null_unspecified)requestWriter; requestsWriter:(null_unspecified GRXWriter *)requestWriter;
/** /**
* Finishes the request side of this call, notifies the server that the RPC should be cancelled, and * Finishes the request side of this call, notifies the server that the RPC should be cancelled, and
@ -356,11 +356,11 @@ NS_ASSUME_NONNULL_END
* The following methods are deprecated. * The following methods are deprecated.
*/ */
+ (void)setCallSafety:(GRPCCallSafety)callSafety + (void)setCallSafety:(GRPCCallSafety)callSafety
host:(NSString *_Null_unspecified)host host:(null_unspecified NSString *)host
path:(NSString *_Null_unspecified)path; path:(null_unspecified NSString *)path;
@property(null_unspecified, atomic, copy, readwrite) NSString *serverName; @property(null_unspecified, atomic, copy, readwrite) NSString *serverName;
@property NSTimeInterval timeout; @property NSTimeInterval timeout;
- (void)setResponseDispatchQueue:(dispatch_queue_t _Null_unspecified)queue; - (void)setResponseDispatchQueue:(null_unspecified dispatch_queue_t)queue;
@end @end
@ -371,11 +371,11 @@ DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.")
@protocol GRPCRequestHeaders<NSObject> @protocol GRPCRequestHeaders<NSObject>
@property(nonatomic, readonly) NSUInteger count; @property(nonatomic, readonly) NSUInteger count;
- (id _Null_unspecified)objectForKeyedSubscript:(id _Null_unspecified)key; - (null_unspecified id)objectForKeyedSubscript:(null_unspecified id)key;
- (void)setObject:(id _Null_unspecified)obj forKeyedSubscript:(id _Null_unspecified)key; - (void)setObject:(null_unspecified id)obj forKeyedSubscript:(null_unspecified id)key;
- (void)removeAllObjects; - (void)removeAllObjects;
- (void)removeObjectForKey:(id _Null_unspecified)key; - (void)removeObjectForKey:(null_unspecified id)key;
@end @end
#pragma clang diagnostic push #pragma clang diagnostic push

@ -114,7 +114,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCResponseHandler>)responseHandler responseHandler:(id<GRPCResponseHandler>)responseHandler
callOptions:(GRPCCallOptions *_Nullable)callOptions { callOptions:(GRPCCallOptions *)callOptions {
NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0, NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0,
@"Neither host nor path can be nil."); @"Neither host nor path can be nil.");
NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest,
@ -134,7 +134,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
if (@available(iOS 8.0, *)) { if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create( _dispatchQueue = dispatch_queue_create(
NULL, NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1)); dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0));
} else { } else {
// Fallback on earlier versions // Fallback on earlier versions
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);

@ -78,7 +78,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* :authority header field of the call and performs an extra check that server's certificate * :authority header field of the call and performs an extra check that server's certificate
* matches the :authority header. * matches the :authority header.
*/ */
@property(copy, readonly) NSString *serverAuthority; @property(copy, readonly, nullable) NSString *serverAuthority;
/** /**
* The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to * The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to
@ -94,18 +94,18 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* request's "authorization" header field. This parameter should not be used simultaneously with * request's "authorization" header field. This parameter should not be used simultaneously with
* \a authTokenProvider. * \a authTokenProvider.
*/ */
@property(copy, readonly) NSString *oauth2AccessToken; @property(copy, readonly, nullable) NSString *oauth2AccessToken;
/** /**
* The interface to get the OAuth2 access token string. gRPC will attempt to acquire token when * The interface to get the OAuth2 access token string. gRPC will attempt to acquire token when
* initiating the call. This parameter should not be used simultaneously with \a oauth2AccessToken. * initiating the call. This parameter should not be used simultaneously with \a oauth2AccessToken.
*/ */
@property(readonly) id<GRPCAuthorizationProtocol> authTokenProvider; @property(readonly, nullable) id<GRPCAuthorizationProtocol> authTokenProvider;
/** /**
* Initial metadata key-value pairs that should be included in the request. * Initial metadata key-value pairs that should be included in the request.
*/ */
@property(copy, readonly) NSDictionary *initialMetadata; @property(copy, readonly, nullable) NSDictionary *initialMetadata;
// Channel parameters; take into account of channel signature. // Channel parameters; take into account of channel signature.
@ -113,7 +113,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* Custom string that is prefixed to a request's user-agent header field before gRPC's internal * Custom string that is prefixed to a request's user-agent header field before gRPC's internal
* user-agent string. * user-agent string.
*/ */
@property(copy, readonly) NSString *userAgentPrefix; @property(copy, readonly, nullable) NSString *userAgentPrefix;
/** /**
* The size limit for the response received from server. If it is exceeded, an error with status * The size limit for the response received from server. If it is exceeded, an error with status
@ -152,7 +152,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* Specify channel args to be used for this call. For a list of channel args available, see * Specify channel args to be used for this call. For a list of channel args available, see
* grpc/grpc_types.h * grpc/grpc_types.h
*/ */
@property(copy, readonly) NSDictionary *additionalChannelArgs; @property(copy, readonly, nullable) NSDictionary *additionalChannelArgs;
// Parameters for SSL authentication. // Parameters for SSL authentication.
@ -160,17 +160,17 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* PEM format root certifications that is trusted. If set to nil, gRPC uses a list of default * PEM format root certifications that is trusted. If set to nil, gRPC uses a list of default
* root certificates. * root certificates.
*/ */
@property(copy, readonly) NSString *PEMRootCertificates; @property(copy, readonly, nullable) NSString *PEMRootCertificates;
/** /**
* PEM format private key for client authentication, if required by the server. * PEM format private key for client authentication, if required by the server.
*/ */
@property(copy, readonly) NSString *PEMPrivateKey; @property(copy, readonly, nullable) NSString *PEMPrivateKey;
/** /**
* PEM format certificate chain for client authentication, if required by the server. * PEM format certificate chain for client authentication, if required by the server.
*/ */
@property(copy, readonly) NSString *PEMCertChain; @property(copy, readonly, nullable) NSString *PEMCertChain;
/** /**
* Select the transport type to be used for this call. * Select the transport type to be used for this call.
@ -180,13 +180,13 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
/** /**
* Override the hostname during the TLS hostname validation process. * Override the hostname during the TLS hostname validation process.
*/ */
@property(copy, readonly) NSString *hostNameOverride; @property(copy, readonly, nullable) NSString *hostNameOverride;
/** /**
* A string that specify the domain where channel is being cached. Channels with different domains * A string that specify the domain where channel is being cached. Channels with different domains
* will not get cached to the same connection. * will not get cached to the same connection.
*/ */
@property(copy, readonly) NSString *channelPoolDomain; @property(copy, readonly, nullable) NSString *channelPoolDomain;
/** /**
* Channel id allows control of channel caching within a channelPoolDomain. A call with a unique * Channel id allows control of channel caching within a channelPoolDomain. A call with a unique
@ -199,7 +199,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
/** /**
* Return if the channel options are equal to another object. * Return if the channel options are equal to another object.
*/ */
- (BOOL)hasChannelOptionsEqualTo:(GRPCCallOptions *)callOptions; - (BOOL)hasChannelOptionsEqualTo:(nonnull GRPCCallOptions *)callOptions;
/** /**
* Hash for channel options. * Hash for channel options.
@ -219,7 +219,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* :authority header field of the call and performs an extra check that server's certificate * :authority header field of the call and performs an extra check that server's certificate
* matches the :authority header. * matches the :authority header.
*/ */
@property(copy, readwrite) NSString *serverAuthority; @property(copy, readwrite, nullable) NSString *serverAuthority;
/** /**
* The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to * The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to
@ -236,18 +236,18 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* request's "authorization" header field. This parameter should not be used simultaneously with * request's "authorization" header field. This parameter should not be used simultaneously with
* \a authTokenProvider. * \a authTokenProvider.
*/ */
@property(copy, readwrite) NSString *oauth2AccessToken; @property(copy, readwrite, nullable) NSString *oauth2AccessToken;
/** /**
* The interface to get the OAuth2 access token string. gRPC will attempt to acquire token when * The interface to get the OAuth2 access token string. gRPC will attempt to acquire token when
* initiating the call. This parameter should not be used simultaneously with \a oauth2AccessToken. * initiating the call. This parameter should not be used simultaneously with \a oauth2AccessToken.
*/ */
@property(readwrite) id<GRPCAuthorizationProtocol> authTokenProvider; @property(readwrite, nullable) id<GRPCAuthorizationProtocol> authTokenProvider;
/** /**
* Initial metadata key-value pairs that should be included in the request. * Initial metadata key-value pairs that should be included in the request.
*/ */
@property(copy, readwrite) NSDictionary *initialMetadata; @property(copy, readwrite, nullable) NSDictionary *initialMetadata;
// Channel parameters; take into account of channel signature. // Channel parameters; take into account of channel signature.
@ -255,7 +255,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* Custom string that is prefixed to a request's user-agent header field before gRPC's internal * Custom string that is prefixed to a request's user-agent header field before gRPC's internal
* user-agent string. * user-agent string.
*/ */
@property(copy, readwrite) NSString *userAgentPrefix; @property(copy, readwrite, nullable) NSString *userAgentPrefix;
/** /**
* The size limit for the response received from server. If it is exceeded, an error with status * The size limit for the response received from server. If it is exceeded, an error with status
@ -296,7 +296,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* Specify channel args to be used for this call. For a list of channel args available, see * Specify channel args to be used for this call. For a list of channel args available, see
* grpc/grpc_types.h * grpc/grpc_types.h
*/ */
@property(copy, readwrite) NSDictionary *additionalChannelArgs; @property(copy, readwrite, nullable) NSDictionary *additionalChannelArgs;
// Parameters for SSL authentication. // Parameters for SSL authentication.
@ -304,17 +304,17 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* PEM format root certifications that is trusted. If set to nil, gRPC uses a list of default * PEM format root certifications that is trusted. If set to nil, gRPC uses a list of default
* root certificates. * root certificates.
*/ */
@property(copy, readwrite) NSString *PEMRootCertificates; @property(copy, readwrite, nullable) NSString *PEMRootCertificates;
/** /**
* PEM format private key for client authentication, if required by the server. * PEM format private key for client authentication, if required by the server.
*/ */
@property(copy, readwrite) NSString *PEMPrivateKey; @property(copy, readwrite, nullable) NSString *PEMPrivateKey;
/** /**
* PEM format certificate chain for client authentication, if required by the server. * PEM format certificate chain for client authentication, if required by the server.
*/ */
@property(copy, readwrite) NSString *PEMCertChain; @property(copy, readwrite, nullable) NSString *PEMCertChain;
/** /**
* Select the transport type to be used for this call. * Select the transport type to be used for this call.
@ -324,7 +324,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
/** /**
* Override the hostname during the TLS hostname validation process. * Override the hostname during the TLS hostname validation process.
*/ */
@property(copy, readwrite) NSString *hostNameOverride; @property(copy, readwrite, nullable) NSString *hostNameOverride;
/** /**
* A string that specify the domain where channel is being cached. Channels with different domains * A string that specify the domain where channel is being cached. Channels with different domains
@ -332,7 +332,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) {
* domain 'io.grpc.example' so that its calls do not reuse the channel created by other modules in * domain 'io.grpc.example' so that its calls do not reuse the channel created by other modules in
* the same process. * the same process.
*/ */
@property(copy, readwrite) NSString *channelPoolDomain; @property(copy, readwrite, nullable) NSString *channelPoolDomain;
/** /**
* Channel id allows a call to force creating a new channel (connection) rather than using a cached * Channel id allows a call to force creating a new channel (connection) rather than using a cached

@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path - (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path
completionQueue:(GRPCCompletionQueue *)queue completionQueue:(GRPCCompletionQueue *)queue
callOptions:(GRPCCallOptions *)callOptions callOptions:(GRPCCallOptions *)callOptions
disconnected:(BOOL *_Nullable)disconnected; disconnected:(nullable BOOL *)disconnected;
/** /**
* Unref the channel when a call is done. It also decreases the channel's refcount. If the refcount * Unref the channel when a call is done. It also decreases the channel's refcount. If the refcount

@ -39,7 +39,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
@implementation GRPCChannelConfiguration @implementation GRPCChannelConfiguration
- (nullable instancetype)initWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions { - (instancetype)initWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions {
NSAssert(host.length, @"Host must not be empty."); NSAssert(host.length, @"Host must not be empty.");
NSAssert(callOptions != nil, @"callOptions must not be empty."); NSAssert(callOptions != nil, @"callOptions must not be empty.");
if ((self = [super init])) { if ((self = [super init])) {
@ -143,7 +143,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
return args; return args;
} }
- (nonnull id)copyWithZone:(nullable NSZone *)zone { - (id)copyWithZone:(NSZone *)zone {
GRPCChannelConfiguration *newConfig = GRPCChannelConfiguration *newConfig =
[[GRPCChannelConfiguration alloc] initWithHost:_host callOptions:_callOptions]; [[GRPCChannelConfiguration alloc] initWithHost:_host callOptions:_callOptions];
@ -184,13 +184,13 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
} }
@synthesize disconnected = _disconnected; @synthesize disconnected = _disconnected;
- (nullable instancetype)initWithChannelConfiguration: - (instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration { (GRPCChannelConfiguration *)channelConfiguration {
return [self initWithChannelConfiguration:channelConfiguration return [self initWithChannelConfiguration:channelConfiguration
destroyDelay:kDefaultChannelDestroyDelay]; destroyDelay:kDefaultChannelDestroyDelay];
} }
- (nullable instancetype)initWithChannelConfiguration: - (instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration (GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay { destroyDelay:(NSTimeInterval)destroyDelay {
NSAssert(channelConfiguration != nil, NSAssert(channelConfiguration != nil,
@ -201,7 +201,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
if (@available(iOS 8.0, *)) { if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create( _dispatchQueue = dispatch_queue_create(
NULL, NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1)); dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0));
} else { } else {
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
} }

@ -26,8 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
@protocol GRPCChannelFactory @protocol GRPCChannelFactory
/** Create a channel with specific channel args to a specific host. */ /** Create a channel with specific channel args to a specific host. */
- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - (nullable grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *_Nullable)args; channelArgs:(nullable NSDictionary *)args;
@end @end

@ -41,7 +41,7 @@ static dispatch_once_t gInitChannelPool;
NSMutableDictionary<GRPCChannelConfiguration *, GRPCChannel *> *_channelPool; NSMutableDictionary<GRPCChannelConfiguration *, GRPCChannel *> *_channelPool;
} }
+ (nullable instancetype)sharedInstance { + (instancetype)sharedInstance {
dispatch_once(&gInitChannelPool, ^{ dispatch_once(&gInitChannelPool, ^{
gChannelPool = [[GRPCChannelPool alloc] init]; gChannelPool = [[GRPCChannelPool alloc] init];
NSAssert(gChannelPool != nil, @"Cannot initialize global channel pool."); NSAssert(gChannelPool != nil, @"Cannot initialize global channel pool.");

@ -76,14 +76,14 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach
} }
} }
+ (void)registerObserver:(_Nonnull id)observer selector:(SEL)selector { + (void)registerObserver:(id)observer selector:(SEL)selector {
[[NSNotificationCenter defaultCenter] addObserver:observer [[NSNotificationCenter defaultCenter] addObserver:observer
selector:selector selector:selector
name:kGRPCConnectivityNotification name:kGRPCConnectivityNotification
object:nil]; object:nil];
} }
+ (void)unregisterObserver:(_Nonnull id)observer { + (void)unregisterObserver:(id)observer {
[[NSNotificationCenter defaultCenter] removeObserver:observer]; [[NSNotificationCenter defaultCenter] removeObserver:observer];
} }

@ -26,13 +26,11 @@
#import <Cronet/Cronet.h> #import <Cronet/Cronet.h>
#include <grpc/grpc_cronet.h> #include <grpc/grpc_cronet.h>
NS_ASSUME_NONNULL_BEGIN
@implementation GRPCCronetChannelFactory { @implementation GRPCCronetChannelFactory {
stream_engine *_cronetEngine; stream_engine *_cronetEngine;
} }
+ (instancetype _Nullable)sharedInstance { + (instancetype)sharedInstance {
static GRPCCronetChannelFactory *instance; static GRPCCronetChannelFactory *instance;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
@ -41,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
return instance; return instance;
} }
- (instancetype _Nullable)initWithEngine:(stream_engine *)engine { - (instancetype)initWithEngine:(stream_engine *)engine {
if (!engine) { 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 nil;
@ -52,8 +50,8 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *_Nullable)args { channelArgs:(NSDictionary *)args {
grpc_channel_args *channelArgs = GRPCBuildChannelArgs(args); grpc_channel_args *channelArgs = GRPCBuildChannelArgs(args);
grpc_channel *unmanagedChannel = grpc_channel *unmanagedChannel =
grpc_cronet_secure_channel_create(_cronetEngine, host.UTF8String, channelArgs, NULL); grpc_cronet_secure_channel_create(_cronetEngine, host.UTF8String, channelArgs, NULL);
@ -63,22 +61,18 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
NS_ASSUME_NONNULL_END
#else #else
NS_ASSUME_NONNULL_BEGIN
@implementation GRPCCronetChannelFactory @implementation GRPCCronetChannelFactory
+ (instancetype _Nullable)sharedInstance { + (instancetype)sharedInstance {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."]; format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."];
return nil; return nil;
} }
- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *_Nullable)args { channelArgs:(NSDictionary *)args {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."]; format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."];
return NULL; return NULL;
@ -86,6 +80,4 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
NS_ASSUME_NONNULL_END
#endif #endif

@ -21,11 +21,9 @@
#import "ChannelArgsUtil.h" #import "ChannelArgsUtil.h"
#import "GRPCChannel.h" #import "GRPCChannel.h"
NS_ASSUME_NONNULL_BEGIN
@implementation GRPCInsecureChannelFactory @implementation GRPCInsecureChannelFactory
+ (instancetype _Nullable)sharedInstance { + (instancetype)sharedInstance {
static GRPCInsecureChannelFactory *instance; static GRPCInsecureChannelFactory *instance;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
@ -34,8 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
return instance; return instance;
} }
- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *_Nullable)args { channelArgs:(NSDictionary *)args {
grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]); grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]);
grpc_channel *unmanagedChannel = grpc_channel *unmanagedChannel =
grpc_insecure_channel_create(host.UTF8String, coreChannelArgs, NULL); grpc_insecure_channel_create(host.UTF8String, coreChannelArgs, NULL);
@ -44,5 +42,3 @@ NS_ASSUME_NONNULL_BEGIN
} }
@end @end
NS_ASSUME_NONNULL_END

@ -24,15 +24,13 @@
#import "GRPCChannel.h" #import "GRPCChannel.h"
#import "utilities.h" #import "utilities.h"
NS_ASSUME_NONNULL_BEGIN
@implementation GRPCSecureChannelFactory { @implementation GRPCSecureChannelFactory {
grpc_channel_credentials *_channelCreds; grpc_channel_credentials *_channelCreds;
} }
+ (instancetype _Nullable)factoryWithPEMRootCertificates:(NSString *_Nullable)rootCerts + (instancetype)factoryWithPEMRootCertificates:(NSString *)rootCerts
privateKey:(NSString *_Nullable)privateKey privateKey:(NSString *)privateKey
certChain:(NSString *_Nullable)certChain certChain:(NSString *)certChain
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
return [[self alloc] initWithPEMRootCerts:rootCerts return [[self alloc] initWithPEMRootCerts:rootCerts
privateKey:privateKey privateKey:privateKey
@ -40,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
error:errorPtr]; error:errorPtr];
} }
- (NSData *_Nullable)nullTerminatedDataWithString:(NSString *_Nullable)string { - (NSData *)nullTerminatedDataWithString:(NSString *)string {
// dataUsingEncoding: does not return a null-terminated string. // dataUsingEncoding: does not return a null-terminated string.
NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
if (data == nil) { if (data == nil) {
@ -51,9 +49,9 @@ NS_ASSUME_NONNULL_BEGIN
return nullTerminated; return nullTerminated;
} }
- (instancetype _Nullable)initWithPEMRootCerts:(NSString *_Nullable)rootCerts - (instancetype)initWithPEMRootCerts:(NSString *)rootCerts
privateKey:(NSString *_Nullable)privateKey privateKey:(NSString *)privateKey
certChain:(NSString *_Nullable)certChain certChain:(NSString *)certChain
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
static NSData *defaultRootsASCII; static NSData *defaultRootsASCII;
static NSError *defaultRootsError; static NSError *defaultRootsError;
@ -117,8 +115,8 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *_Nullable)args { channelArgs:(NSDictionary *)args {
grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]); grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]);
grpc_channel *unmanagedChannel = grpc_channel *unmanagedChannel =
grpc_secure_channel_create(_channelCreds, host.UTF8String, coreChannelArgs, NULL); grpc_secure_channel_create(_channelCreds, host.UTF8String, coreChannelArgs, NULL);
@ -133,5 +131,3 @@ NS_ASSUME_NONNULL_BEGIN
} }
@end @end
NS_ASSUME_NONNULL_END

@ -33,13 +33,13 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
* Issued when initial metadata is received from the server. The task must be scheduled onto the * Issued when initial metadata is received from the server. The task must be scheduled onto the
* dispatch queue in property \a dispatchQueue. */ * dispatch queue in property \a dispatchQueue. */
- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata; - (void)receivedInitialMetadata:(nullable NSDictionary *)initialMetadata;
/** /**
* Issued when a message is received from the server. The message is the deserialized proto object. * Issued when a message is received from the server. The message is the deserialized proto object.
* The task must be scheduled onto the dispatch queue in property \a dispatchQueue. * The task must be scheduled onto the dispatch queue in property \a dispatchQueue.
*/ */
- (void)receivedProtoMessage:(GPBMessage *_Nullable)message; - (void)receivedProtoMessage:(nullable GPBMessage *)message;
/** /**
* Issued when a call finished. If the call finished successfully, \a error is nil and \a * Issued when a call finished. If the call finished successfully, \a error is nil and \a
@ -48,8 +48,8 @@ NS_ASSUME_NONNULL_BEGIN
* error descriptions. The task must be scheduled onto the dispatch queue in property * error descriptions. The task must be scheduled onto the dispatch queue in property
* \a dispatchQueue. * \a dispatchQueue.
*/ */
- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - (void)closedWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(NSError *_Nullable)error; error:(nullable NSError *)error;
@required @required
@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
message:(GPBMessage *)message message:(GPBMessage *)message
responseHandler:(id<GRPCProtoResponseHandler>)handler responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(GRPCCallOptions *_Nullable)callOptions callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER; responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
/** /**
@ -100,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCProtoResponseHandler>)handler responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(GRPCCallOptions *_Nullable)callOptions callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER; responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
/** /**

@ -52,7 +52,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
message:(GPBMessage *)message message:(GPBMessage *)message
responseHandler:(id<GRPCProtoResponseHandler>)handler responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(GRPCCallOptions *_Nullable)callOptions callOptions:(GRPCCallOptions *)callOptions
responseClass:(Class)responseClass { responseClass:(Class)responseClass {
if ((self = [super init])) { if ((self = [super init])) {
_call = [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions _call = [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions
@ -88,7 +88,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCProtoResponseHandler>)handler responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(GRPCCallOptions *_Nullable)callOptions callOptions:(GRPCCallOptions *)callOptions
responseClass:(Class)responseClass { responseClass:(Class)responseClass {
if (requestOptions.host.length == 0 || requestOptions.path.length == 0) { if (requestOptions.host.length == 0 || requestOptions.path.length == 0) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."]; [NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."];
@ -108,7 +108,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
if (@available(iOS 8.0, *)) { if (@available(iOS 8.0, *)) {
_dispatchQueue = dispatch_queue_create( _dispatchQueue = dispatch_queue_create(
NULL, NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1)); dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0));
} else { } else {
_dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); _dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL);
} }
@ -171,7 +171,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}); });
} }
- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata { - (void)receivedInitialMetadata:(NSDictionary *)initialMetadata {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (initialMetadata != nil && [self->_handler respondsToSelector:@selector(initialMetadata:)]) { if (initialMetadata != nil && [self->_handler respondsToSelector:@selector(initialMetadata:)]) {
[self->_handler receivedInitialMetadata:initialMetadata]; [self->_handler receivedInitialMetadata:initialMetadata];
@ -179,7 +179,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}); });
} }
- (void)receivedRawMessage:(NSData *_Nullable)message { - (void)receivedRawMessage:(NSData *)message {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (self->_handler && message != nil) { if (self->_handler && message != nil) {
NSError *error = nil; NSError *error = nil;
@ -202,8 +202,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}); });
} }
- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata
error:(NSError *_Nullable)error { error:(NSError *)error {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if ([self->_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { if ([self->_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
[self->_handler closedWithTrailingMetadata:trailingMetadata error:error]; [self->_handler closedWithTrailingMetadata:trailingMetadata error:error];

@ -102,7 +102,7 @@ BOOL isRemoteInteropTest(NSString *host) {
return self; return self;
} }
- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata { - (void)receivedInitialMetadata:(NSDictionary *)initialMetadata {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (_initialMetadataCallback) { if (_initialMetadataCallback) {
_initialMetadataCallback(initialMetadata); _initialMetadataCallback(initialMetadata);
@ -110,7 +110,7 @@ BOOL isRemoteInteropTest(NSString *host) {
}); });
} }
- (void)receivedProtoMessage:(GPBMessage *_Nullable)message { - (void)receivedProtoMessage:(GPBMessage *)message {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (_messageCallback) { if (_messageCallback) {
_messageCallback(message); _messageCallback(message);
@ -118,8 +118,8 @@ BOOL isRemoteInteropTest(NSString *host) {
}); });
} }
- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata
error:(NSError *_Nullable)error { error:(NSError *)error {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (_closeCallback) { if (_closeCallback) {
_closeCallback(trailingMetadata, error); _closeCallback(trailingMetadata, error);

Loading…
Cancel
Save