From 08b21aed41d92e0e1b8477cd89a5a7b80ecbf75c Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 25 Jul 2019 09:53:15 -0700 Subject: [PATCH] add comments and clang-format --- src/compiler/objective_c_generator.cc | 19 ++- src/compiler/objective_c_generator.h | 9 +- src/compiler/objective_c_plugin.cc | 27 +++- src/objective-c/GRPCClient/GRPCCall+Cronet.h | 3 +- src/objective-c/GRPCClient/GRPCCall.m | 69 ++++---- src/objective-c/GRPCClient/GRPCCallLegacy.h | 2 +- src/objective-c/GRPCClient/GRPCCallLegacy.m | 4 +- src/objective-c/GRPCClient/GRPCCallOptions.m | 14 +- src/objective-c/GRPCClient/GRPCDispatchable.h | 2 +- src/objective-c/GRPCClient/GRPCInterceptor.h | 11 +- src/objective-c/GRPCClient/GRPCInterceptor.m | 147 +++++++++--------- src/objective-c/GRPCClient/GRPCTransport.h | 29 +++- src/objective-c/GRPCClient/GRPCTransport.m | 44 +++--- .../private/GRPCCore/GRPCCallInternal.h | 5 +- .../private/GRPCCore/GRPCCallInternal.m | 46 +++--- .../GRPCClient/private/GRPCCore/GRPCChannel.m | 48 +++--- .../private/GRPCCore/GRPCChannelPool.h | 2 +- .../GRPCCoreCronet/GRPCCoreCronetFactory.h | 9 ++ .../GRPCCoreCronet/GRPCCoreCronetFactory.m | 9 +- .../private/GRPCCore/GRPCCoreFactory.h | 9 +- .../private/GRPCCore/GRPCCoreFactory.m | 20 ++- .../GRPCClient/private/GRPCCore/GRPCHost.m | 4 +- .../private/GRPCTransport+Private.h | 21 ++- .../private/GRPCTransport+Private.m | 11 +- src/objective-c/ProtoRPC/ProtoRPCLegacy.h | 39 ++--- src/objective-c/ProtoRPC/ProtoRPCLegacy.m | 8 +- src/objective-c/ProtoRPC/ProtoService.h | 12 +- src/objective-c/ProtoRPC/ProtoServiceLegacy.m | 5 +- .../InteropTestsRemoteWithCronet.m | 4 +- .../tests/InteropTests/InteropTests.m | 131 ++++++++-------- .../InteropTests/InteropTestsLocalCleartext.m | 4 +- .../tests/InteropTests/InteropTestsLocalSSL.m | 4 +- 32 files changed, 434 insertions(+), 337 deletions(-) diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 837113841a8..122ea3c3b69 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -278,7 +278,8 @@ void PrintMethodImplementations(Printer* printer, return output; } -::grpc::string GetProtocol(const ServiceDescriptor* service, const Parameters& generator_params) { +::grpc::string GetProtocol(const ServiceDescriptor* service, + const Parameters& generator_params) { ::grpc::string output; if (generator_params.no_v1_compatibility) return output; @@ -325,7 +326,8 @@ void PrintMethodImplementations(Printer* printer, return output; } -::grpc::string GetInterface(const ServiceDescriptor* service, const Parameters& generator_params) { +::grpc::string GetInterface(const ServiceDescriptor* service, + const Parameters& generator_params) { ::grpc::string output; // Scope the output stream so it closes and finalizes output to the string. @@ -367,7 +369,8 @@ void PrintMethodImplementations(Printer* printer, return output; } -::grpc::string GetSource(const ServiceDescriptor* service, const Parameters& generator_params) { +::grpc::string GetSource(const ServiceDescriptor* service, + const Parameters& generator_params) { ::grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -422,9 +425,10 @@ void PrintMethodImplementations(Printer* printer, printer.Print("#pragma mark - Class Methods\n\n"); if (!generator_params.no_v1_compatibility) { - printer.Print("+ (instancetype)serviceWithHost:(NSString *)host {\n" - " return [[self alloc] initWithHost:host];\n" - "}\n\n"); + printer.Print( + "+ (instancetype)serviceWithHost:(NSString *)host {\n" + " return [[self alloc] initWithHost:host];\n" + "}\n\n"); } printer.Print( "+ (instancetype)serviceWithHost:(NSString *)host " @@ -435,7 +439,8 @@ void PrintMethodImplementations(Printer* printer, printer.Print("#pragma mark - Method Implementations\n\n"); for (int i = 0; i < service->method_count(); i++) { - PrintMethodImplementations(&printer, service->method(i), generator_params); + PrintMethodImplementations(&printer, service->method(i), + generator_params); } printer.Print("@end\n"); diff --git a/src/compiler/objective_c_generator.h b/src/compiler/objective_c_generator.h index 3f5b3e8b780..518962fceee 100644 --- a/src/compiler/objective_c_generator.h +++ b/src/compiler/objective_c_generator.h @@ -39,7 +39,8 @@ string GetAllMessageClasses(const FileDescriptor* file); // Returns the content to be included defining the @protocol segment at the // insertion point of the generated implementation file. This interface is // legacy and for backwards compatibility. -string GetProtocol(const ServiceDescriptor* service, const Parameters& generator_params); +string GetProtocol(const ServiceDescriptor* service, + const Parameters& generator_params); // Returns the content to be included defining the @protocol segment at the // insertion point of the generated implementation file. @@ -47,11 +48,13 @@ string GetV2Protocol(const ServiceDescriptor* service); // Returns the content to be included defining the @interface segment at the // insertion point of the generated implementation file. -string GetInterface(const ServiceDescriptor* service, const Parameters& generator_params); +string GetInterface(const ServiceDescriptor* service, + const Parameters& generator_params); // Returns the content to be included in the "global_scope" insertion point of // the generated implementation file. -string GetSource(const ServiceDescriptor* service, const Parameters& generator_params); +string GetSource(const ServiceDescriptor* service, + const Parameters& generator_params); } // namespace grpc_objective_c_generator diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index 21c68995cbb..cdd184b6c18 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -104,8 +104,13 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string imports = LocalImport(file_name + ".pbobjc.h"); - ::grpc::string system_imports = (generator_params.no_v1_compatibility ? SystemImport("ProtoRPC/ProtoService.h") : SystemImport("ProtoRPC/ProtoServiceLegacy.h")) + - (generator_params.no_v1_compatibility ? SystemImport("ProtoRPC/ProtoRPC.h") : SystemImport("ProtoRPC/ProtoRPCLegacy.h")); + ::grpc::string system_imports = + (generator_params.no_v1_compatibility + ? SystemImport("ProtoRPC/ProtoService.h") + : SystemImport("ProtoRPC/ProtoServiceLegacy.h")) + + (generator_params.no_v1_compatibility + ? SystemImport("ProtoRPC/ProtoRPC.h") + : SystemImport("ProtoRPC/ProtoRPCLegacy.h")); if (!generator_params.no_v1_compatibility) { system_imports += SystemImport("RxLibrary/GRXWriteable.h") + SystemImport("RxLibrary/GRXWriter.h"); @@ -138,13 +143,15 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string protocols; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); - protocols += grpc_objective_c_generator::GetProtocol(service, generator_params); + protocols += + grpc_objective_c_generator::GetProtocol(service, generator_params); } ::grpc::string interfaces; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); - interfaces += grpc_objective_c_generator::GetInterface(service, generator_params); + interfaces += + grpc_objective_c_generator::GetInterface(service, generator_params); } Write(context, file_name + ".pbrpc.h", @@ -161,9 +168,12 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { { // Generate .pbrpc.m - ::grpc::string imports = LocalImport(file_name + ".pbrpc.h") + - LocalImport(file_name + ".pbobjc.h") + - (generator_params.no_v1_compatibility ? SystemImport("ProtoRPC/ProtoRPC.h") : SystemImport("ProtoRPC/ProtoRPCLegacy.h")); + ::grpc::string imports = + LocalImport(file_name + ".pbrpc.h") + + LocalImport(file_name + ".pbobjc.h") + + (generator_params.no_v1_compatibility + ? SystemImport("ProtoRPC/ProtoRPC.h") + : SystemImport("ProtoRPC/ProtoRPCLegacy.h")); if (!generator_params.no_v1_compatibility) { imports += SystemImport("RxLibrary/GRXWriter+Immediate.h"); } @@ -176,7 +186,8 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string definitions; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); - definitions += grpc_objective_c_generator::GetSource(service, generator_params); + definitions += + grpc_objective_c_generator::GetSource(service, generator_params); } Write(context, file_name + ".pbrpc.m", diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.h b/src/objective-c/GRPCClient/GRPCCall+Cronet.h index c77816b8df6..c49d7cf16f3 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.h +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.h @@ -24,7 +24,7 @@ typedef struct stream_engine stream_engine; // Transport id for Cronet transport extern const GRPCTransportId gGRPCCoreCronetId; -// Deprecated class. Please use the previous transport id with GRPCCallOptions instead. +// Deprecated class. Please use the gGRPCCoreCronetId with GRPCCallOptions.transport instead. @interface GRPCCall (Cronet) + (void)useCronetWithEngine:(stream_engine*)engine; @@ -32,4 +32,3 @@ extern const GRPCTransportId gGRPCCoreCronetId; + (BOOL)isUsingCronet; @end - diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index c62cb03ddd8..26f42032537 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -18,9 +18,9 @@ #import "GRPCCall.h" +#import "GRPCCall+Interceptor.h" #import "GRPCCallOptions.h" #import "GRPCInterceptor.h" -#import "GRPCCall+Interceptor.h" #import "private/GRPCTransport+Private.h" @@ -32,7 +32,7 @@ NSString *const kGRPCTrailersKey = @"io.grpc.TrailersKey"; * dispatch queue of a user provided response handler. It removes the requirement of having to use * serial dispatch queue in the user provided response handler. */ -@interface GRPCResponseDispatcher : NSObject +@interface GRPCResponseDispatcher : NSObject - (nullable instancetype)initWithResponseHandler:(id)responseHandler; @@ -48,7 +48,9 @@ NSString *const kGRPCTrailersKey = @"io.grpc.TrailersKey"; _responseHandler = responseHandler; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 if (@available(iOS 8.0, macOS 10.10, *)) { - _dispatchQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); + _dispatchQueue = dispatch_queue_create( + NULL, + dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); } else { #else { @@ -61,38 +63,38 @@ NSString *const kGRPCTrailersKey = @"io.grpc.TrailersKey"; return self; } - - (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; - } +- (dispatch_queue_t)dispatchQueue { + return _dispatchQueue; +} - - (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata { - if ([_responseHandler respondsToSelector:@selector(didReceiveInitialMetadata:)]) { - [_responseHandler didReceiveInitialMetadata:initialMetadata]; - } +- (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata { + if ([_responseHandler respondsToSelector:@selector(didReceiveInitialMetadata:)]) { + [_responseHandler didReceiveInitialMetadata:initialMetadata]; } +} - - (void)didReceiveData:(id)data { - // For backwards compatibility with didReceiveRawMessage, if the user provided a response handler - // that handles didReceiveRawMesssage, we issue to that method instead - if ([_responseHandler respondsToSelector:@selector(didReceiveRawMessage:)]) { - [_responseHandler didReceiveRawMessage:data]; - } else if ([_responseHandler respondsToSelector:@selector(didReceiveData:)]) { - [_responseHandler didReceiveData:data]; - } +- (void)didReceiveData:(id)data { + // For backwards compatibility with didReceiveRawMessage, if the user provided a response handler + // that handles didReceiveRawMesssage, we issue to that method instead + if ([_responseHandler respondsToSelector:@selector(didReceiveRawMessage:)]) { + [_responseHandler didReceiveRawMessage:data]; + } else if ([_responseHandler respondsToSelector:@selector(didReceiveData:)]) { + [_responseHandler didReceiveData:data]; } +} - - (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata -error:(nullable NSError *)error { +- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata + error:(nullable NSError *)error { if ([_responseHandler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { [_responseHandler didCloseWithTrailingMetadata:trailingMetadata error:error]; } } - - (void)didWriteData { - if ([_responseHandler respondsToSelector:@selector(didWriteData)]) { - [_responseHandler didWriteData]; - } +- (void)didWriteData { + if ([_responseHandler respondsToSelector:@selector(didWriteData)]) { + [_responseHandler didWriteData]; } +} @end @@ -166,10 +168,12 @@ error:(nullable NSError *)error { } _responseHandler = responseHandler; - GRPCResponseDispatcher *dispatcher = [[GRPCResponseDispatcher alloc] initWithResponseHandler:_responseHandler]; + GRPCResponseDispatcher *dispatcher = + [[GRPCResponseDispatcher alloc] initWithResponseHandler:_responseHandler]; NSMutableArray> *interceptorFactories; if (_actualCallOptions.interceptorFactories != nil) { - interceptorFactories = [NSMutableArray arrayWithArray:_actualCallOptions.interceptorFactories]; + interceptorFactories = + [NSMutableArray arrayWithArray:_actualCallOptions.interceptorFactories]; } else { interceptorFactories = [NSMutableArray array]; } @@ -180,12 +184,14 @@ error:(nullable NSError *)error { // continuously create interceptor until one is successfully created while (_firstInterceptor == nil) { if (interceptorFactories.count == 0) { - _firstInterceptor = [[GRPCTransportManager alloc] initWithTransportId:_callOptions.transport previousInterceptor:dispatcher]; + _firstInterceptor = [[GRPCTransportManager alloc] initWithTransportId:_callOptions.transport + previousInterceptor:dispatcher]; break; } else { - _firstInterceptor = [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories - previousInterceptor:dispatcher - transportId:_callOptions.transport]; + _firstInterceptor = + [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories + previousInterceptor:dispatcher + transportId:_callOptions.transport]; if (_firstInterceptor == nil) { [interceptorFactories removeObjectAtIndex:0]; } @@ -211,8 +217,7 @@ error:(nullable NSError *)error { GRPCRequestOptions *requestOptions = _requestOptions; GRPCCallOptions *callOptions = _actualCallOptions; dispatch_async(copiedFirstInterceptor.dispatchQueue, ^{ - [copiedFirstInterceptor startWithRequestOptions:requestOptions - callOptions:callOptions]; + [copiedFirstInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; }); } diff --git a/src/objective-c/GRPCClient/GRPCCallLegacy.h b/src/objective-c/GRPCClient/GRPCCallLegacy.h index 6c2c8ceada8..e6103498639 100644 --- a/src/objective-c/GRPCClient/GRPCCallLegacy.h +++ b/src/objective-c/GRPCClient/GRPCCallLegacy.h @@ -21,8 +21,8 @@ * the API in GRPCCall.h. This API exists solely for the purpose of backwards compatibility. */ -#import "GRPCCallOptions.h" #import +#import "GRPCCallOptions.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" diff --git a/src/objective-c/GRPCClient/GRPCCallLegacy.m b/src/objective-c/GRPCClient/GRPCCallLegacy.m index 18a1eda1b39..e25048cfc7e 100644 --- a/src/objective-c/GRPCClient/GRPCCallLegacy.m +++ b/src/objective-c/GRPCClient/GRPCCallLegacy.m @@ -18,9 +18,9 @@ #import "GRPCCallLegacy.h" +#import "GRPCCall+Cronet.h" #import "GRPCCall+OAuth2.h" #import "GRPCCallOptions.h" -#import "GRPCCall+Cronet.h" #import "private/GRPCCore/GRPCChannelPool.h" #import "private/GRPCCore/GRPCCompletionQueue.h" @@ -552,7 +552,7 @@ static NSString *const kBearerPrefix = @"Bearer "; [[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue]; GRPCPooledChannel *channel = - [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions]; + [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions]; _wrappedCall = [channel wrappedCallWithPath:_path completionQueue:[GRPCCompletionQueue completionQueue] callOptions:_callOptions]; diff --git a/src/objective-c/GRPCClient/GRPCCallOptions.m b/src/objective-c/GRPCClient/GRPCCallOptions.m index 2080f9915a9..7f88098eb6f 100644 --- a/src/objective-c/GRPCClient/GRPCCallOptions.m +++ b/src/objective-c/GRPCClient/GRPCCallOptions.m @@ -17,8 +17,8 @@ */ #import "GRPCCallOptions.h" -#import "internal/GRPCCallOptions+Internal.h" #import "GRPCTransport.h" +#import "internal/GRPCCallOptions+Internal.h" // The default values for the call options. static NSString *const kDefaultServerAuthority = nil; @@ -138,7 +138,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:kDefaultPEMPrivateKey PEMCertificateChain:kDefaultPEMCertificateChain transportType:kDefaultTransportType - transport:kDefaultTransport + transport:kDefaultTransport hostNameOverride:kDefaultHostNameOverride logContext:kDefaultLogContext channelPoolDomain:kDefaultChannelPoolDomain @@ -166,7 +166,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:(NSString *)PEMPrivateKey PEMCertificateChain:(NSString *)PEMCertificateChain transportType:(GRPCTransportType)transportType - transport:(GRPCTransportId)transport + transport:(GRPCTransportId)transport hostNameOverride:(NSString *)hostNameOverride logContext:(id)logContext channelPoolDomain:(NSString *)channelPoolDomain @@ -231,7 +231,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:_PEMPrivateKey PEMCertificateChain:_PEMCertificateChain transportType:_transportType - transport:_transport + transport:_transport hostNameOverride:_hostNameOverride logContext:_logContext channelPoolDomain:_channelPoolDomain @@ -264,7 +264,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:[_PEMPrivateKey copy] PEMCertificateChain:[_PEMCertificateChain copy] transportType:_transportType - transport:_transport + transport:_transport hostNameOverride:[_hostNameOverride copy] logContext:_logContext channelPoolDomain:[_channelPoolDomain copy] @@ -375,7 +375,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:kDefaultPEMPrivateKey PEMCertificateChain:kDefaultPEMCertificateChain transportType:kDefaultTransportType - transport:kDefaultTransport + transport:kDefaultTransport hostNameOverride:kDefaultHostNameOverride logContext:kDefaultLogContext channelPoolDomain:kDefaultChannelPoolDomain @@ -436,7 +436,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:_PEMPrivateKey PEMCertificateChain:_PEMCertificateChain transportType:_transportType - transport:_transport + transport:_transport hostNameOverride:_hostNameOverride logContext:_logContext channelPoolDomain:_channelPoolDomain diff --git a/src/objective-c/GRPCClient/GRPCDispatchable.h b/src/objective-c/GRPCClient/GRPCDispatchable.h index 3322766e3bc..650103603d4 100644 --- a/src/objective-c/GRPCClient/GRPCDispatchable.h +++ b/src/objective-c/GRPCClient/GRPCDispatchable.h @@ -18,7 +18,7 @@ */ /** - * An object that process its methods with a dispatch queue. + * An object that processes its methods with a dispatch queue. */ @protocol GRPCDispatchable diff --git a/src/objective-c/GRPCClient/GRPCInterceptor.h b/src/objective-c/GRPCClient/GRPCInterceptor.h index f8a97ac13e8..509749769b3 100644 --- a/src/objective-c/GRPCClient/GRPCInterceptor.h +++ b/src/objective-c/GRPCClient/GRPCInterceptor.h @@ -169,7 +169,7 @@ NS_ASSUME_NONNULL_BEGIN * invoke shutDown method of its corresponding manager so that references to other interceptors can * be released. */ -@interface GRPCInterceptorManager : NSObject +@interface GRPCInterceptorManager : NSObject - (instancetype)init NS_UNAVAILABLE; @@ -179,6 +179,10 @@ NS_ASSUME_NONNULL_BEGIN previousInterceptor:(nullable id)previousInterceptor transportId:(GRPCTransportId)transportId; +/** + * Notify the manager that the interceptor has shut down and the manager should release references + * to other interceptors and stop forwarding requests/responses. + */ - (void)shutDown; // Methods to forward GRPCInterceptorInterface calls to the next interceptor @@ -230,7 +234,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GRPCInterceptor : NSObject - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)new NS_UNAVAILABLE; ++ (instancetype) new NS_UNAVAILABLE; /** * Initialize the interceptor with the next interceptor in the chain, and provide the dispatch queue @@ -241,7 +245,8 @@ NS_ASSUME_NONNULL_BEGIN // Default implementation of GRPCInterceptorInterface -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions; +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions; - (void)writeData:(id)data; - (void)finish; - (void)cancel; diff --git a/src/objective-c/GRPCClient/GRPCInterceptor.m b/src/objective-c/GRPCClient/GRPCInterceptor.m index aa3380cc024..b18f7550260 100644 --- a/src/objective-c/GRPCClient/GRPCInterceptor.m +++ b/src/objective-c/GRPCClient/GRPCInterceptor.m @@ -40,7 +40,8 @@ transportId:(nonnull GRPCTransportId)transportId { if ((self = [super init])) { if (factories.count == 0) { - [NSException raise:NSInternalInconsistencyException format:@"Interceptor manager must have factories"]; + [NSException raise:NSInternalInconsistencyException + format:@"Interceptor manager must have factories"]; } _thisInterceptor = [factories[0] createInterceptorWithManager:self]; if (_thisInterceptor == nil) { @@ -48,20 +49,22 @@ } _previousInterceptor = previousInterceptor; _factories = factories; - // Generate interceptor + // Generate interceptor #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 if (@available(iOS 8.0, macOS 10.10, *)) { - _dispatchQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); + _dispatchQueue = dispatch_queue_create( + NULL, + dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); } else { #else - { + { #endif - _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - } - dispatch_set_target_queue(_dispatchQueue, _thisInterceptor.dispatchQueue); - _transportId = transportId; + _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); + } + dispatch_set_target_queue(_dispatchQueue, _thisInterceptor.dispatchQueue); + _transportId = transportId; } - return self; + return self; } - (void)shutDown { @@ -71,35 +74,37 @@ _shutDown = YES; } - - (void)createNextInterceptor { - NSAssert(_nextInterceptor == nil, @"Starting the next interceptor more than once"); - NSAssert(_factories.count > 0, @"Interceptor manager of transport cannot start next interceptor"); - if (_nextInterceptor != nil) { - NSLog(@"Starting the next interceptor more than once"); - return; - } - NSMutableArray> *interceptorFactories = [NSMutableArray arrayWithArray:[_factories subarrayWithRange:NSMakeRange(1, _factories.count - 1)]]; - while (_nextInterceptor == nil) { - if (interceptorFactories.count == 0) { - _nextInterceptor = [[GRPCTransportManager alloc] initWithTransportId:_transportId previousInterceptor:self]; - break; - } else { - _nextInterceptor = [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories - previousInterceptor:self - transportId:_transportId]; - if (_nextInterceptor == nil) { - [interceptorFactories removeObjectAtIndex:0]; - } +- (void)createNextInterceptor { + NSAssert(_nextInterceptor == nil, @"Starting the next interceptor more than once"); + NSAssert(_factories.count > 0, @"Interceptor manager of transport cannot start next interceptor"); + if (_nextInterceptor != nil) { + NSLog(@"Starting the next interceptor more than once"); + return; + } + NSMutableArray> *interceptorFactories = [NSMutableArray + arrayWithArray:[_factories subarrayWithRange:NSMakeRange(1, _factories.count - 1)]]; + while (_nextInterceptor == nil) { + if (interceptorFactories.count == 0) { + _nextInterceptor = + [[GRPCTransportManager alloc] initWithTransportId:_transportId previousInterceptor:self]; + break; + } else { + _nextInterceptor = [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories + previousInterceptor:self + transportId:_transportId]; + if (_nextInterceptor == nil) { + [interceptorFactories removeObjectAtIndex:0]; } } - NSAssert(_nextInterceptor != nil, @"Failed to create interceptor or transport."); - if (_nextInterceptor == nil) { - NSLog(@"Failed to create interceptor or transport."); - } } + NSAssert(_nextInterceptor != nil, @"Failed to create interceptor or transport."); + if (_nextInterceptor == nil) { + NSLog(@"Failed to create interceptor or transport."); + } +} - - (void)startNextInterceptorWithRequest:(GRPCRequestOptions *)requestOptions -callOptions:(GRPCCallOptions *)callOptions { +- (void)startNextInterceptorWithRequest:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions { if (_nextInterceptor == nil && !_shutDown) { [self createNextInterceptor]; } @@ -193,8 +198,8 @@ callOptions:(GRPCCallOptions *)callOptions { } /** Forward call close and trailing metadata to the previous interceptor in the chain */ - - (void)forwardPreviousInterceptorCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata -error:(NSError *)error { +- (void)forwardPreviousInterceptorCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata + error:(NSError *)error { if (_previousInterceptor == nil) { return; } @@ -215,54 +220,55 @@ error:(NSError *)error { }); } - - (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; - } +- (dispatch_queue_t)dispatchQueue { + return _dispatchQueue; +} - - (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions { - [_thisInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; - } +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions { + [_thisInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; +} - - (void)writeData:(id)data { - [_thisInterceptor writeData:data]; - } +- (void)writeData:(id)data { + [_thisInterceptor writeData:data]; +} - - (void)finish { - [_thisInterceptor finish]; - } +- (void)finish { + [_thisInterceptor finish]; +} - - (void)cancel { - [_thisInterceptor cancel]; - } +- (void)cancel { + [_thisInterceptor cancel]; +} - - (void)receiveNextMessages:(NSUInteger)numberOfMessages { - [_thisInterceptor receiveNextMessages:numberOfMessages]; - } +- (void)receiveNextMessages:(NSUInteger)numberOfMessages { + [_thisInterceptor receiveNextMessages:numberOfMessages]; +} - - (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata { - if ([_thisInterceptor respondsToSelector:@selector(didReceiveInitialMetadata:)]) { - [_thisInterceptor didReceiveInitialMetadata:initialMetadata]; - } +- (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata { + if ([_thisInterceptor respondsToSelector:@selector(didReceiveInitialMetadata:)]) { + [_thisInterceptor didReceiveInitialMetadata:initialMetadata]; } +} - - (void)didReceiveData:(id)data { - if ([_thisInterceptor respondsToSelector:@selector(didReceiveData:)]) { - [_thisInterceptor didReceiveData:data]; - } +- (void)didReceiveData:(id)data { + if ([_thisInterceptor respondsToSelector:@selector(didReceiveData:)]) { + [_thisInterceptor didReceiveData:data]; } +} - - (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata - error:(nullable NSError *)error { +- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata + error:(nullable NSError *)error { if ([_thisInterceptor respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { [_thisInterceptor didCloseWithTrailingMetadata:trailingMetadata error:error]; } } - - (void)didWriteData { - if ([_thisInterceptor respondsToSelector:@selector(didWriteData)]) { - [_thisInterceptor didWriteData]; - } +- (void)didWriteData { + if ([_thisInterceptor respondsToSelector:@selector(didWriteData)]) { + [_thisInterceptor didWriteData]; } +} @end @@ -272,7 +278,7 @@ error:(NSError *)error { } - (instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager - dispatchQueue:(dispatch_queue_t)dispatchQueue { + dispatchQueue:(dispatch_queue_t)dispatchQueue { if ((self = [super init])) { _manager = interceptorManager; _dispatchQueue = dispatchQueue; @@ -285,7 +291,8 @@ error:(NSError *)error { return _dispatchQueue; } -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions { +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions { [_manager startNextInterceptorWithRequest:requestOptions callOptions:callOptions]; } diff --git a/src/objective-c/GRPCClient/GRPCTransport.h b/src/objective-c/GRPCClient/GRPCTransport.h index 2da6ab3dc6a..d5637922152 100644 --- a/src/objective-c/GRPCClient/GRPCTransport.h +++ b/src/objective-c/GRPCClient/GRPCTransport.h @@ -16,19 +16,27 @@ * */ +// The interface for a transport implementation + #import "GRPCInterceptor.h" NS_ASSUME_NONNULL_BEGIN #pragma mark Transport ID -extern const struct GRPCTransportImplList { +/** + * The default transport implementations available in gRPC. These implementations will be provided + * by gRPC by default unless explicitly excluded. + */ +extern const struct GRPCDefaultTransportImplList { const GRPCTransportId core_secure; const GRPCTransportId core_insecure; -} GRPCTransportImplList; +} GRPCDefaultTransportImplList; +/** Returns whether two transport id's are identical. */ BOOL TransportIdIsEqual(GRPCTransportId lhs, GRPCTransportId rhs); +/** Returns the hash value of a transport id. */ NSUInteger TransportIdHash(GRPCTransportId); #pragma mark Transport and factory @@ -40,20 +48,33 @@ NSUInteger TransportIdHash(GRPCTransportId); @class GRPCCallOptions; @class GRPCTransport; -@protocol GRPCTransportFactory +/** The factory method to create a transport. */ +@protocol GRPCTransportFactory - (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager; @end +/** The registry of transport implementations. */ @interface GRPCTransportRegistry : NSObject + (instancetype)sharedInstance; -- (void)registerTransportWithId:(GRPCTransportId)id factory:(id)factory; +/** + * Register a transport implementation with the registry. All transport implementations to be used + * in a process must register with the registry on process start-up in its +load: class method. + * Parameter \a transportId is the identifier of the implementation, and \a factory is the factory + * object to create the corresponding transport instance. + */ +- (void)registerTransportWithId:(GRPCTransportId)transportId + factory:(id)factory; @end +/** + * Base class for transport implementations. All transport implementation should inherit from this + * class. + */ @interface GRPCTransport : NSObject @end diff --git a/src/objective-c/GRPCClient/GRPCTransport.m b/src/objective-c/GRPCClient/GRPCTransport.m index 0621c4e6450..edb973a8f62 100644 --- a/src/objective-c/GRPCClient/GRPCTransport.m +++ b/src/objective-c/GRPCClient/GRPCTransport.m @@ -3,9 +3,8 @@ static const GRPCTransportId gGRPCCoreSecureId = "io.grpc.transport.core.secure"; static const GRPCTransportId gGRPCCoreInsecureId = "io.grpc.transport.core.insecure"; -const struct GRPCTransportImplList GRPCTransportImplList = { - .core_secure = gGRPCCoreSecureId, - .core_insecure = gGRPCCoreInsecureId}; +const struct GRPCDefaultTransportImplList GRPCDefaultTransportImplList = { + .core_secure = gGRPCCoreSecureId, .core_insecure = gGRPCCoreInsecureId}; static const GRPCTransportId gDefaultTransportId = gGRPCCoreSecureId; @@ -49,10 +48,11 @@ NSUInteger TransportIdHash(GRPCTransportId transportId) { return self; } -- (void)registerTransportWithId:(GRPCTransportId)transportId factory:(id)factory { - NSString *nsTransportId = [NSString stringWithCString:transportId - encoding:NSUTF8StringEncoding]; - NSAssert(_registry[nsTransportId] == nil, @"The transport %@ has already been registered.", nsTransportId); +- (void)registerTransportWithId:(GRPCTransportId)transportId + factory:(id)factory { + NSString *nsTransportId = [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding]; + NSAssert(_registry[nsTransportId] == nil, @"The transport %@ has already been registered.", + nsTransportId); if (_registry[nsTransportId] != nil) { NSLog(@"The transport %@ has already been registered.", nsTransportId); return; @@ -68,17 +68,18 @@ NSUInteger TransportIdHash(GRPCTransportId transportId) { - (id)getTransportFactoryWithId:(GRPCTransportId)transportId { if (transportId == NULL) { if (_defaultFactory == nil) { - [NSException raise:NSInvalidArgumentException format:@"Unable to get default transport factory"]; + [NSException raise:NSInvalidArgumentException + format:@"Unable to get default transport factory"]; return nil; } return _defaultFactory; } - NSString *nsTransportId = [NSString stringWithCString:transportId - encoding:NSUTF8StringEncoding]; + NSString *nsTransportId = [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding]; id transportFactory = _registry[nsTransportId]; if (transportFactory == nil) { // User named a transport id that was not registered with the registry. - [NSException raise:NSInvalidArgumentException format:@"Unable to get transport factory with id %s", transportId]; + [NSException raise:NSInvalidArgumentException + format:@"Unable to get transport factory with id %s", transportId]; return nil; } return transportFactory; @@ -89,28 +90,35 @@ NSUInteger TransportIdHash(GRPCTransportId transportId) { @implementation GRPCTransport - (dispatch_queue_t)dispatchQueue { - [NSException raise:NSGenericException format:@"Implementations should override the dispatch queue"]; + [NSException raise:NSGenericException + format:@"Implementations should override the dispatch queue"]; return nil; } -- (void)startWithRequestOptions:(nonnull GRPCRequestOptions *)requestOptions callOptions:(nonnull GRPCCallOptions *)callOptions { - [NSException raise:NSGenericException format:@"Implementations should override the methods of GRPCTransport"]; +- (void)startWithRequestOptions:(nonnull GRPCRequestOptions *)requestOptions + callOptions:(nonnull GRPCCallOptions *)callOptions { + [NSException raise:NSGenericException + format:@"Implementations should override the methods of GRPCTransport"]; } - (void)writeData:(nonnull id)data { - [NSException raise:NSGenericException format:@"Implementations should override the methods of GRPCTransport"]; + [NSException raise:NSGenericException + format:@"Implementations should override the methods of GRPCTransport"]; } - (void)cancel { - [NSException raise:NSGenericException format:@"Implementations should override the methods of GRPCTransport"]; + [NSException raise:NSGenericException + format:@"Implementations should override the methods of GRPCTransport"]; } - (void)finish { - [NSException raise:NSGenericException format:@"Implementations should override the methods of GRPCTransport"]; + [NSException raise:NSGenericException + format:@"Implementations should override the methods of GRPCTransport"]; } - (void)receiveNextMessages:(NSUInteger)numberOfMessages { - [NSException raise:NSGenericException format:@"Implementations should override the methods of GRPCTransport"]; + [NSException raise:NSGenericException + format:@"Implementations should override the methods of GRPCTransport"]; } @end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h index ff7a9f6e838..641b1fb2e8a 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h @@ -26,9 +26,10 @@ NS_ASSUME_NONNULL_BEGIN @interface GRPCCall2Internal : GRPCTransport -- (instancetype)initWithTransportManager:(GRPCTransportManager*)transportManager; +- (instancetype)initWithTransportManager:(GRPCTransportManager *)transportManager; -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions; +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions; - (void)writeData:(id)data; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m index 7ff8c6a5945..ea01fcaf594 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m @@ -22,8 +22,8 @@ #import #import -#import "GRPCCall+V2API.h" #import "../GRPCTransport+Private.h" +#import "GRPCCall+V2API.h" @implementation GRPCCall2Internal { /** Request for the call. */ @@ -53,20 +53,19 @@ NSUInteger _pendingReceiveNextMessages; } - - (instancetype)initWithTransportManager:(GRPCTransportManager *)transportManager { - dispatch_queue_t dispatchQueue; - // Set queue QoS only when iOS version is 8.0 or above and Xcode version is 9.0 or above +- (instancetype)initWithTransportManager:(GRPCTransportManager *)transportManager { + dispatch_queue_t dispatchQueue; + // Set queue QoS only when iOS version is 8.0 or above and Xcode version is 9.0 or above #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 - if (@available(iOS 8.0, macOS 10.10, *)) { - dispatchQueue = dispatch_queue_create( - NULL, - dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); - } else { + if (@available(iOS 8.0, macOS 10.10, *)) { + dispatchQueue = dispatch_queue_create( + NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); + } else { #else - { + { #endif - dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - } + dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); + } if ((self = [super init])) { _pipe = [GRXBufferedPipe pipe]; _transportManager = transportManager; @@ -79,7 +78,8 @@ return _dispatchQueue; } -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions { +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions { NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0, @"Neither host nor path can be nil."); NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value."); @@ -187,13 +187,17 @@ _pipe = nil; if (_transportManager != nil) { - [_transportManager forwardPreviousInterceptorCloseWithTrailingMetadata:nil - error:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeCancelled - userInfo:@{ - NSLocalizedDescriptionKey : - @"Canceled by app" - }]]; + [_transportManager + forwardPreviousInterceptorCloseWithTrailingMetadata:nil + error: + [NSError + errorWithDomain:kGRPCErrorDomain + code: + GRPCErrorCodeCancelled + userInfo:@{ + NSLocalizedDescriptionKey : + @"Canceled by app" + }]]; [_transportManager shutDown]; } } @@ -258,7 +262,7 @@ - (void)issueClosedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { [_transportManager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata - error:error]; + error:error]; [_transportManager shutDown]; } diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m index 846e8331b4b..e0fd4c18e78 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m @@ -21,15 +21,15 @@ #include #import "../../internal/GRPCCallOptions+Internal.h" +#import "../GRPCTransport+Private.h" #import "ChannelArgsUtil.h" #import "GRPCChannelFactory.h" #import "GRPCChannelPool.h" #import "GRPCCompletionQueue.h" +#import "GRPCCoreFactory.h" #import "GRPCInsecureChannelFactory.h" #import "GRPCSecureChannelFactory.h" #import "version.h" -#import "GRPCCoreFactory.h" -#import "../GRPCTransport+Private.h" #import #import @@ -52,12 +52,16 @@ - (id)channelFactory { if (_callOptions.transport != NULL) { - id transportFactory = [[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:_callOptions.transport]; - if (![transportFactory respondsToSelector:@selector(createCoreChannelFactoryWithCallOptions:)]) { + id transportFactory = + [[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:_callOptions.transport]; + if (! + [transportFactory respondsToSelector:@selector(createCoreChannelFactoryWithCallOptions:)]) { // impossible because we are using GRPCCore now - [NSException raise:NSInternalInconsistencyException format:@"Transport factory type is wrong"]; + [NSException raise:NSInternalInconsistencyException + format:@"Transport factory type is wrong"]; } - id coreTransportFactory = (id)transportFactory; + id coreTransportFactory = + (id)transportFactory; return [coreTransportFactory createCoreChannelFactoryWithCallOptions:_callOptions]; } else { // To maintain backwards compatibility with tranportType @@ -65,22 +69,22 @@ switch (type) { case GRPCTransportTypeChttp2BoringSSL: // TODO (mxyan): Remove when the API is deprecated - { - NSError *error; - id factory = [GRPCSecureChannelFactory - factoryWithPEMRootCertificates:_callOptions.PEMRootCertificates - privateKey:_callOptions.PEMPrivateKey - certChain:_callOptions.PEMCertificateChain - error:&error]; - NSAssert(factory != nil, @"Failed to create secure channel factory"); - if (factory == nil) { - NSLog(@"Error creating secure channel factory: %@", error); - } - return factory; + { + NSError *error; + id factory = [GRPCSecureChannelFactory + factoryWithPEMRootCertificates:_callOptions.PEMRootCertificates + privateKey:_callOptions.PEMPrivateKey + certChain:_callOptions.PEMCertificateChain + error:&error]; + NSAssert(factory != nil, @"Failed to create secure channel factory"); + if (factory == nil) { + NSLog(@"Error creating secure channel factory: %@", error); } - case GRPCTransportTypeCronet: - { - id transportFactory = (id)[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:gGRPCCoreCronetId]; + return factory; + } + case GRPCTransportTypeCronet: { + id transportFactory = (id)[ + [GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:gGRPCCoreCronetId]; return [transportFactory createCoreChannelFactoryWithCallOptions:_callOptions]; } case GRPCTransportTypeInsecure: @@ -191,7 +195,7 @@ grpc_channel *_unmanagedChannel; } - - (instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration { +- (instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration { NSAssert(channelConfiguration != nil, @"channelConfiguration must not be empty."); if (channelConfiguration == nil) { return nil; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h index 5adb9cea168..b83a28a2368 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN * Initialize with an actual channel object \a channel and a reference to the channel pool. */ - (nullable instancetype)initWithChannelConfiguration: -(GRPCChannelConfiguration *)channelConfiguration; + (GRPCChannelConfiguration *)channelConfiguration; /** * Create a GRPCWrappedCall object (grpc_call) from this channel. If channel is disconnected, get a diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h index f1ad1b05e44..83d279d2c72 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h @@ -18,6 +18,15 @@ #import "../GRPCCoreFactory.h" +/** + * The factory for gRPC Core + Cronet transport implementation. The + * implementation is not part of the default transports of gRPC and is for + * testing purpose only on Github. + * + * To use this transport, a user must include the GRPCCoreCronet module as a + * dependency of the project and use gGRPCCoreCronetId in call options to + * specify that this is the transport to be used for a call. + */ @interface GRPCCoreCronetFactory : NSObject @end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m index 0a19e31999e..5772694fc54 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m @@ -18,11 +18,11 @@ #import "GRPCCoreCronetFactory.h" -#import #import +#import -#import "../GRPCCoreFactory.h" #import "../GRPCCallInternal.h" +#import "../GRPCCoreFactory.h" #import "GRPCCronetChannelFactory.h" static GRPCCoreCronetFactory *gGRPCCoreCronetFactory = nil; @@ -38,8 +38,9 @@ static dispatch_once_t gInitGRPCCoreCronetFactory; } + (void)load { - [[GRPCTransportRegistry sharedInstance] registerTransportWithId:gGRPCCoreCronetId - factory:[GRPCCoreCronetFactory sharedInstance]]; + [[GRPCTransportRegistry sharedInstance] + registerTransportWithId:gGRPCCoreCronetId + factory:[GRPCCoreCronetFactory sharedInstance]]; } - (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager { diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h index d4d8ef586df..3cd312d4ad0 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h @@ -23,16 +23,21 @@ NS_ASSUME_NONNULL_BEGIN @protocol GRPCChannelFactory; @protocol GRPCCallOptions; -@protocol GRPCCoreTransportFactory +/** The interface for transport implementations that are based on Core. */ +@protocol GRPCCoreTransportFactory -- (nullable id)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions; +/** Get the channel factory for GRPCChannel from call options. */ +- (nullable id)createCoreChannelFactoryWithCallOptions: + (GRPCCallOptions *)callOptions; @end +/** The factory for gRPC Core + CFStream + TLS secure channel transport implementation. */ @interface GRPCCoreSecureFactory : NSObject @end +/** The factory for gRPC Core + CFStream + insecure channel transport implementation. */ @interface GRPCCoreInsecureFactory : NSObject @end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m index 609cda17697..f5d6276a570 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m @@ -3,8 +3,8 @@ #import #import "GRPCCallInternal.h" -#import "GRPCSecureChannelFactory.h" #import "GRPCInsecureChannelFactory.h" +#import "GRPCSecureChannelFactory.h" static GRPCCoreSecureFactory *gGRPCCoreSecureFactory = nil; static GRPCCoreInsecureFactory *gGRPCCoreInsecureFactory = nil; @@ -21,8 +21,9 @@ static dispatch_once_t gInitGRPCCoreInsecureFactory; } + (void)load { - [[GRPCTransportRegistry sharedInstance] registerTransportWithId:GRPCTransportImplList.core_secure - factory:[self sharedInstance]]; + [[GRPCTransportRegistry sharedInstance] + registerTransportWithId:GRPCDefaultTransportImplList.core_secure + factory:[self sharedInstance]]; } - (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager { @@ -31,9 +32,11 @@ static dispatch_once_t gInitGRPCCoreInsecureFactory; - (id)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions { NSError *error; - id factory = [GRPCSecureChannelFactory factoryWithPEMRootCertificates:callOptions.PEMRootCertificates - privateKey:callOptions.PEMPrivateKey - certChain:callOptions.PEMCertificateChain error:&error]; + id factory = + [GRPCSecureChannelFactory factoryWithPEMRootCertificates:callOptions.PEMRootCertificates + privateKey:callOptions.PEMPrivateKey + certChain:callOptions.PEMCertificateChain + error:&error]; if (error != nil) { NSLog(@"Unable to create secure channel factory"); return nil; @@ -53,8 +56,9 @@ static dispatch_once_t gInitGRPCCoreInsecureFactory; } + (void)load { - [[GRPCTransportRegistry sharedInstance] registerTransportWithId:GRPCTransportImplList.core_insecure - factory:[self sharedInstance]]; + [[GRPCTransportRegistry sharedInstance] + registerTransportWithId:GRPCDefaultTransportImplList.core_insecure + factory:[self sharedInstance]]; } - (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager { diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m index 89a184d8c26..efee85e3108 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m @@ -113,9 +113,9 @@ static NSMutableDictionary *gHostCache; options.PEMCertificateChain = _PEMCertificateChain; options.hostNameOverride = _hostNameOverride; if (_transportType == GRPCTransportTypeInsecure) { - options.transport = GRPCTransportImplList.core_insecure; + options.transport = GRPCDefaultTransportImplList.core_insecure; } else { - options.transport = GRPCTransportImplList.core_secure; + options.transport = GRPCDefaultTransportImplList.core_secure; } options.logContext = _logContext; diff --git a/src/objective-c/GRPCClient/private/GRPCTransport+Private.h b/src/objective-c/GRPCClient/private/GRPCTransport+Private.h index 9115b915659..dd826a8fc1a 100644 --- a/src/objective-c/GRPCClient/private/GRPCTransport+Private.h +++ b/src/objective-c/GRPCClient/private/GRPCTransport+Private.h @@ -16,17 +16,21 @@ * */ -#import #import +#import NS_ASSUME_NONNULL_BEGIN +/** + * Private interfaces of the transport registry. + */ @interface GRPCTransportRegistry (Private) -- (nullable instancetype)initWithTransportId:(GRPCTransportId)transportId - previousInterceptor:(id)previousInterceptor; - -- (id)getTransportFactoryWithId:(GRPCTransportId)id; +/** + * Get a transport implementation's factory by its transport id. If the transport id was not + * registered with the registry, nil is returned. + */ +- (id)getTransportFactoryWithId:(GRPCTransportId)transportId; @end @@ -35,6 +39,10 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithTransportId:(GRPCTransportId)transportId previousInterceptor:(id)previousInterceptor; +/** + * Notify the manager that the transport has shut down and the manager should release references to + * its response handler and stop forwarding requests/responses. + */ - (void)shutDown; /** Forward initial metadata to the previous interceptor in the interceptor chain */ @@ -44,7 +52,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)forwardPreviousInterceptorWithData:(nullable id)data; /** Forward call close and trailing metadata to the previous interceptor in the interceptor chain */ -- (void)forwardPreviousInterceptorCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata +- (void)forwardPreviousInterceptorCloseWithTrailingMetadata: + (nullable NSDictionary *)trailingMetadata error:(nullable NSError *)error; /** Forward write completion to the previous interceptor in the interceptor chain */ diff --git a/src/objective-c/GRPCClient/private/GRPCTransport+Private.m b/src/objective-c/GRPCClient/private/GRPCTransport+Private.m index 1050280e07b..c8198462bd4 100644 --- a/src/objective-c/GRPCClient/private/GRPCTransport+Private.m +++ b/src/objective-c/GRPCClient/private/GRPCTransport+Private.m @@ -12,8 +12,9 @@ - (instancetype)initWithTransportId:(GRPCTransportId)transportId previousInterceptor:(id)previousInterceptor { if ((self = [super init])) { - id factory = [[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:transportId]; - + id factory = + [[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:transportId]; + _transport = [factory createTransportWithManager:self]; NSAssert(_transport != nil, @"Failed to create transport with id: %s", transportId); if (_transport == nil) { @@ -36,9 +37,11 @@ return _dispatchQueue; } -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions { +- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions + callOptions:(GRPCCallOptions *)callOptions { if (_transportId != callOptions.transport) { - [NSException raise:NSInvalidArgumentException format:@"Interceptors cannot change the call option 'transport'"]; + [NSException raise:NSInvalidArgumentException + format:@"Interceptors cannot change the call option 'transport'"]; return; } [_transport startWithRequestOptions:requestOptions callOptions:callOptions]; diff --git a/src/objective-c/ProtoRPC/ProtoRPCLegacy.h b/src/objective-c/ProtoRPC/ProtoRPCLegacy.h index bff487e9a0b..2ceb4339bd1 100644 --- a/src/objective-c/ProtoRPC/ProtoRPCLegacy.h +++ b/src/objective-c/ProtoRPC/ProtoRPCLegacy.h @@ -5,17 +5,17 @@ @protocol GRXWriteable; __attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC -: GRPCCall - -/** - * host parameter should not contain the scheme (http:// or https://), only the name or IP - * addr and the port number, for example @"localhost:5050". - */ -- -(instancetype)initWithHost : (NSString *)host method -: (GRPCProtoMethod *)method requestsWriter : (GRXWriter *)requestsWriter responseClass -: (Class)responseClass responsesWriteable -: (id)responsesWriteable NS_DESIGNATED_INITIALIZER; + : GRPCCall + + /** + * host parameter should not contain the scheme (http:// or https://), only the name or IP + * addr and the port number, for example @"localhost:5050". + */ + - + (instancetype)initWithHost : (NSString *)host method + : (GRPCProtoMethod *)method requestsWriter : (GRXWriter *)requestsWriter responseClass + : (Class)responseClass responsesWriteable + : (id)responsesWriteable NS_DESIGNATED_INITIALIZER; - (void)start; @end @@ -26,14 +26,15 @@ __attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -@interface GRPCProtoCall : ProtoRPC + @interface GRPCProtoCall + : ProtoRPC #pragma clang diagnostic pop -@end - -/** - * Generate an NSError object that represents a failure in parsing a proto class. For gRPC internal - * use only. - */ -NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError); + @end + /** + * Generate an NSError object that represents a failure in parsing a proto class. For gRPC + * internal use only. + */ + NSError * + ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError); diff --git a/src/objective-c/ProtoRPC/ProtoRPCLegacy.m b/src/objective-c/ProtoRPC/ProtoRPCLegacy.m index a4ea1836bdf..b5c0c847c66 100644 --- a/src/objective-c/ProtoRPC/ProtoRPCLegacy.m +++ b/src/objective-c/ProtoRPC/ProtoRPCLegacy.m @@ -11,7 +11,6 @@ #import #import - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-implementations" @implementation ProtoRPC { @@ -63,9 +62,9 @@ [weakSelf finishWithError:ErrorForBadProto(value, responseClass, error)]; } } - completionHandler:^(NSError *errorOrNil) { - [responsesWriteable writesFinishedWithError:errorOrNil]; - }]; + completionHandler:^(NSError *errorOrNil) { + [responsesWriteable writesFinishedWithError:errorOrNil]; + }]; } return self; } @@ -102,4 +101,3 @@ NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError) // TODO(jcanizales): Use kGRPCErrorDomain and GRPCErrorCodeInternal when they're public. return [NSError errorWithDomain:@"io.grpc" code:13 userInfo:info]; } - diff --git a/src/objective-c/ProtoRPC/ProtoService.h b/src/objective-c/ProtoRPC/ProtoService.h index e99d75fd3d8..d55ed30a39b 100644 --- a/src/objective-c/ProtoRPC/ProtoService.h +++ b/src/objective-c/ProtoRPC/ProtoService.h @@ -30,17 +30,17 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" -__attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoService -: NSObject { +__attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoService : NSObject { NSString *_host; NSString *_packageName; NSString *_serviceName; } - - - (nullable instancetype)initWithHost : (nonnull NSString *)host packageName - : (nonnull NSString *)packageName serviceName : (nonnull NSString *)serviceName callOptions - : (nullable GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER; +- (nullable instancetype)initWithHost:(nonnull NSString *)host + packageName:(nonnull NSString *)packageName + serviceName:(nonnull NSString *)serviceName + callOptions:(nullable GRPCCallOptions *)callOptions + NS_DESIGNATED_INITIALIZER; - (nullable GRPCUnaryProtoCall *)RPCToMethod:(nonnull NSString *)method message:(nonnull id)message diff --git a/src/objective-c/ProtoRPC/ProtoServiceLegacy.m b/src/objective-c/ProtoRPC/ProtoServiceLegacy.m index 34f2b0f2cbb..9484f432216 100644 --- a/src/objective-c/ProtoRPC/ProtoServiceLegacy.m +++ b/src/objective-c/ProtoRPC/ProtoServiceLegacy.m @@ -1,6 +1,6 @@ #import "ProtoServiceLegacy.h" -#import "ProtoRPCLegacy.h" #import "ProtoMethod.h" +#import "ProtoRPCLegacy.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-implementations" @@ -23,13 +23,12 @@ return self; } - - (GRPCProtoCall *)RPCToMethod:(NSString *)method requestsWriter:(GRXWriter *)requestsWriter responseClass:(Class)responseClass responsesWriteable:(id)responsesWriteable { GRPCProtoMethod *methodName = - [[GRPCProtoMethod alloc] initWithPackage:_packageName service:_serviceName method:method]; + [[GRPCProtoMethod alloc] initWithPackage:_packageName service:_serviceName method:method]; return [[GRPCProtoCall alloc] initWithHost:_host method:methodName requestsWriter:requestsWriter diff --git a/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m b/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m index 37fa1b418c1..aa1af301b96 100644 --- a/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m +++ b/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m @@ -22,9 +22,8 @@ #import #import -#import "InteropTests.h" #import "../ConfigureCronet.h" - +#import "InteropTests.h" // The server address is derived from preprocessor macro, which is // in turn derived from environment variable of the same name. @@ -49,7 +48,6 @@ static int32_t kRemoteInteropServerOverhead = 12; [super setUp]; } - + (NSString *)host { return kRemoteSSLHost; } diff --git a/src/objective-c/tests/InteropTests/InteropTests.m b/src/objective-c/tests/InteropTests/InteropTests.m index dcdbdc2beb5..2cb5ba21a2f 100644 --- a/src/objective-c/tests/InteropTests/InteropTests.m +++ b/src/objective-c/tests/InteropTests/InteropTests.m @@ -87,8 +87,8 @@ BOOL isRemoteInteropTest(NSString *host) { - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - return [[GRPCInterceptor alloc] initWithInterceptorManager:interceptorManager - dispatchQueue:queue]; + return + [[GRPCInterceptor alloc] initWithInterceptorManager:interceptorManager dispatchQueue:queue]; } @end @@ -96,20 +96,19 @@ BOOL isRemoteInteropTest(NSString *host) { @interface HookInterceptorFactory : NSObject - (instancetype) -initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - startHook:(void (^)(GRPCRequestOptions *requestOptions, - GRPCCallOptions *callOptions, - GRPCInterceptorManager *manager))startHook - writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook - finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook - receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, - GRPCInterceptorManager *manager))receiveNextMessagesHook - responseHeaderHook:(void (^)(NSDictionary *initialMetadata, - GRPCInterceptorManager *manager))responseHeaderHook - responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook - responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, - GRPCInterceptorManager *manager))responseCloseHook - didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; + initWithDispatchQueue:(dispatch_queue_t)dispatchQueue + startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, + GRPCInterceptorManager *manager))startHook + writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook + finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook +receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, + GRPCInterceptorManager *manager))receiveNextMessagesHook + responseHeaderHook:(void (^)(NSDictionary *initialMetadata, + GRPCInterceptorManager *manager))responseHeaderHook + responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook + responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, + GRPCInterceptorManager *manager))responseCloseHook + didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager; @@ -119,7 +118,7 @@ initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - (instancetype) initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager -dispatchQueue:(dispatch_queue_t)dispatchQueue + dispatchQueue:(dispatch_queue_t)dispatchQueue startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook @@ -152,20 +151,19 @@ dispatchQueue:(dispatch_queue_t)dispatchQueue } - (instancetype) -initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - startHook:(void (^)(GRPCRequestOptions *requestOptions, - GRPCCallOptions *callOptions, - GRPCInterceptorManager *manager))startHook - writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook - finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook - receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, - GRPCInterceptorManager *manager))receiveNextMessagesHook - responseHeaderHook:(void (^)(NSDictionary *initialMetadata, - GRPCInterceptorManager *manager))responseHeaderHook - responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook - responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, - GRPCInterceptorManager *manager))responseCloseHook - didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { + initWithDispatchQueue:(dispatch_queue_t)dispatchQueue + startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, + GRPCInterceptorManager *manager))startHook + writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook + finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook +receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, + GRPCInterceptorManager *manager))receiveNextMessagesHook + responseHeaderHook:(void (^)(NSDictionary *initialMetadata, + GRPCInterceptorManager *manager))responseHeaderHook + responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook + responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, + GRPCInterceptorManager *manager))responseCloseHook + didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { if ((self = [super init])) { _dispatchQueue = dispatchQueue; _startHook = startHook; @@ -182,7 +180,7 @@ initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { return [[HookInterceptor alloc] initWithInterceptorManager:interceptorManager - dispatchQueue:_dispatchQueue + dispatchQueue:_dispatchQueue startHook:_startHook writeDataHook:_writeDataHook finishHook:_finishHook @@ -216,7 +214,7 @@ initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - (instancetype) initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager -dispatchQueue:(dispatch_queue_t)dispatchQueue + dispatchQueue:(dispatch_queue_t)dispatchQueue startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook @@ -230,8 +228,7 @@ dispatchQueue:(dispatch_queue_t)dispatchQueue responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { - if ((self = [super initWithInterceptorManager:interceptorManager - dispatchQueue:dispatchQueue])) { + if ((self = [super initWithInterceptorManager:interceptorManager dispatchQueue:dispatchQueue])) { _startHook = startHook; _writeDataHook = writeDataHook; _finishHook = finishHook; @@ -323,14 +320,14 @@ dispatchQueue:(dispatch_queue_t)dispatchQueue - (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue { _enabled = NO; return [super initWithDispatchQueue:dispatchQueue - startHook:nil - writeDataHook:nil - finishHook:nil - receiveNextMessagesHook:nil - responseHeaderHook:nil - responseDataHook:nil - responseCloseHook:nil - didWriteDataHook:nil]; + startHook:nil + writeDataHook:nil + finishHook:nil + receiveNextMessagesHook:nil + responseHeaderHook:nil + responseDataHook:nil + responseCloseHook:nil + didWriteDataHook:nil]; } - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { @@ -621,7 +618,7 @@ static dispatch_once_t initGlobalInterceptorFactory; request.responseStatus.code = GRPC_STATUS_CANCELLED; } GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility + // For backwards compatibility options.transportType = [[self class] transportType]; options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; @@ -1269,7 +1266,6 @@ static dispatch_once_t initGlobalInterceptorFactory; } __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Keepalive"]; - NSNumber *kRequestSize = @27182; NSNumber *kResponseSize = @31415; @@ -1284,18 +1280,19 @@ static dispatch_once_t initGlobalInterceptorFactory; options.keepaliveTimeout = 0; __block GRPCStreamingProtoCall *call = [_service - fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] - initWithInitialMetadataCallback:nil - messageCallback:nil - closeCallback:^(NSDictionary *trailingMetadata, - NSError *error) { - XCTAssertNotNil(error); - XCTAssertEqual(error.code, GRPC_STATUS_UNAVAILABLE, - @"Received status %ld instead of UNAVAILABLE (14).", - error.code); - [expectation fulfill]; - }] - callOptions:options]; + fullDuplexCallWithResponseHandler: + [[InteropTestsBlockCallbacks alloc] + initWithInitialMetadataCallback:nil + messageCallback:nil + closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { + XCTAssertNotNil(error); + XCTAssertEqual( + error.code, GRPC_STATUS_UNAVAILABLE, + @"Received status %ld instead of UNAVAILABLE (14).", + error.code); + [expectation fulfill]; + }] + callOptions:options]; [call writeMessage:request]; [call start]; @@ -1548,7 +1545,7 @@ static dispatch_once_t initGlobalInterceptorFactory; XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED); [expectCallInternalComplete fulfill]; } - didWriteDataHook:nil]; + didWriteDataHook:nil]; NSArray *requests = @[ @1, @2, @3, @4 ]; @@ -1723,15 +1720,15 @@ static dispatch_once_t initGlobalInterceptorFactory; - (void)testConflictingGlobalInterceptors { id factory = [[HookInterceptorFactory alloc] - initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) - startHook:nil - writeDataHook:nil - finishHook:nil - receiveNextMessagesHook:nil - responseHeaderHook:nil - responseDataHook:nil - responseCloseHook:nil - didWriteDataHook:nil]; + initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + startHook:nil + writeDataHook:nil + finishHook:nil + receiveNextMessagesHook:nil + responseHeaderHook:nil + responseDataHook:nil + responseCloseHook:nil + didWriteDataHook:nil]; @try { [GRPCCall2 registerGlobalInterceptor:factory]; XCTFail(@"Did not receive an exception when registering global interceptor the second time"); diff --git a/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m b/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m index c8d21199454..2e638099e1e 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m +++ b/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m @@ -17,8 +17,8 @@ */ #import -#import #import +#import #import "InteropTests.h" @@ -62,7 +62,7 @@ static int32_t kLocalInteropServerOverhead = 10; } + (GRPCTransportId)transport { - return GRPCTransportImplList.core_insecure; + return GRPCDefaultTransportImplList.core_insecure; } @end diff --git a/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m b/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m index d28513cc673..1c1c1ddeb1e 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m +++ b/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m @@ -17,8 +17,8 @@ */ #import -#import #import +#import #import "InteropTests.h" // The server address is derived from preprocessor macro, which is @@ -62,7 +62,7 @@ static int32_t kLocalInteropServerOverhead = 10; } + (GRPCTransportId)transport { - return GRPCTransportImplList.core_secure; + return GRPCDefaultTransportImplList.core_secure; } - (void)setUp {