More Id -> ID

pull/20107/head
Muxi Yan 6 years ago
parent 9094826cf5
commit f89e11d037
  1. 4
      src/objective-c/GRPCClient/GRPCCall+Cronet.h
  2. 2
      src/objective-c/GRPCClient/GRPCCall+Cronet.m
  3. 4
      src/objective-c/GRPCClient/GRPCCall.m
  4. 4
      src/objective-c/GRPCClient/GRPCCallOptions.m
  5. 2
      src/objective-c/GRPCClient/GRPCInterceptor.h
  6. 10
      src/objective-c/GRPCClient/GRPCInterceptor.m
  7. 8
      src/objective-c/GRPCClient/GRPCTransport.h
  8. 46
      src/objective-c/GRPCClient/GRPCTransport.m
  9. 4
      src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m
  10. 2
      src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h
  11. 2
      src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m
  12. 4
      src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m
  13. 2
      src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m
  14. 4
      src/objective-c/GRPCClient/private/GRPCTransport+Private.h
  15. 14
      src/objective-c/GRPCClient/private/GRPCTransport+Private.m
  16. 2
      src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m
  17. 4
      src/objective-c/tests/CronetTests/TransportRegistryTests.m
  18. 2
      src/objective-c/tests/InteropTests/InteropTests.m
  19. 8
      src/objective-c/tests/UnitTests/TransportRegistryTests.m

@ -22,9 +22,9 @@
typedef struct stream_engine stream_engine;
// Transport id for Cronet transport
extern const GRPCTransportID gGRPCCoreCronetId;
extern const GRPCTransportID gGRPCCoreCronetID;
// Deprecated class. Please use the gGRPCCoreCronetId with GRPCCallOptions.transport instead.
// Deprecated class. Please use the gGRPCCoreCronetID with GRPCCallOptions.transport instead.
@interface GRPCCall (Cronet)
+ (void)useCronetWithEngine:(stream_engine*)engine;

@ -18,7 +18,7 @@
#import "GRPCCall+Cronet.h"
const GRPCTransportID gGRPCCoreCronetId = "io.grpc.transport.core.cronet";
const GRPCTransportID gGRPCCoreCronetID = "io.grpc.transport.core.cronet";
static BOOL useCronet = NO;
static stream_engine *globalCronetEngine;

@ -186,14 +186,14 @@ NSString *const kGRPCErrorDomain = @"io.grpc";
// continuously create interceptor until one is successfully created
while (_firstInterceptor == nil) {
if (interceptorFactories.count == 0) {
_firstInterceptor = [[GRPCTransportManager alloc] initWithTransportId:_callOptions.transport
_firstInterceptor = [[GRPCTransportManager alloc] initWithTransportID:_callOptions.transport
previousInterceptor:dispatcher];
break;
} else {
_firstInterceptor =
[[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories
previousInterceptor:dispatcher
transportId:_callOptions.transport];
transportID:_callOptions.transport];
if (_firstInterceptor == nil) {
[interceptorFactories removeObjectAtIndex:0];
}

@ -289,7 +289,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) {
if (!areObjectsEqual(callOptions.PEMCertificateChain, _PEMCertificateChain)) return NO;
if (!areObjectsEqual(callOptions.hostNameOverride, _hostNameOverride)) return NO;
if (!(callOptions.transportType == _transportType)) return NO;
if (!(TransportIdIsEqual(callOptions.transport, _transport))) return NO;
if (!(TransportIDIsEqual(callOptions.transport, _transport))) return NO;
if (!areObjectsEqual(callOptions.logContext, _logContext)) return NO;
if (!areObjectsEqual(callOptions.channelPoolDomain, _channelPoolDomain)) return NO;
if (!(callOptions.channelID == _channelID)) return NO;
@ -314,7 +314,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) {
result ^= _PEMCertificateChain.hash;
result ^= _hostNameOverride.hash;
result ^= _transportType;
result ^= TransportIdHash(_transport);
result ^= TransportIDHash(_transport);
result ^= _logContext.hash;
result ^= _channelPoolDomain.hash;
result ^= _channelID;

@ -177,7 +177,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithFactories:(nullable NSArray<id<GRPCInterceptorFactory>> *)factories
previousInterceptor:(nullable id<GRPCResponseHandler>)previousInterceptor
transportId:(GRPCTransportID)transportId;
transportID:(GRPCTransportID)transportID;
/**
* Notify the manager that the interceptor has shut down and the manager should release references

@ -31,13 +31,13 @@
GRPCInterceptor *_thisInterceptor;
dispatch_queue_t _dispatchQueue;
NSArray<id<GRPCInterceptorFactory>> *_factories;
GRPCTransportID _transportId;
GRPCTransportID _transportID;
BOOL _shutDown;
}
- (instancetype)initWithFactories:(NSArray<id<GRPCInterceptorFactory>> *)factories
previousInterceptor:(id<GRPCResponseHandler>)previousInterceptor
transportId:(nonnull GRPCTransportID)transportId {
transportID:(nonnull GRPCTransportID)transportID {
if ((self = [super init])) {
if (factories.count == 0) {
[NSException raise:NSInternalInconsistencyException
@ -62,7 +62,7 @@
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
}
dispatch_set_target_queue(_dispatchQueue, _thisInterceptor.dispatchQueue);
_transportId = transportId;
_transportID = transportID;
}
return self;
}
@ -87,12 +87,12 @@
while (_nextInterceptor == nil) {
if (interceptorFactories.count == 0) {
_nextInterceptor =
[[GRPCTransportManager alloc] initWithTransportId:_transportId previousInterceptor:self];
[[GRPCTransportManager alloc] initWithTransportID:_transportID previousInterceptor:self];
break;
} else {
_nextInterceptor = [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories
previousInterceptor:self
transportId:_transportId];
transportID:_transportID];
if (_nextInterceptor == nil) {
[interceptorFactories removeObjectAtIndex:0];
}

@ -34,10 +34,10 @@ extern const struct GRPCDefaultTransportImplList {
} GRPCDefaultTransportImplList;
/** Returns whether two transport id's are identical. */
BOOL TransportIdIsEqual(GRPCTransportID lhs, GRPCTransportID rhs);
BOOL TransportIDIsEqual(GRPCTransportID lhs, GRPCTransportID rhs);
/** Returns the hash value of a transport id. */
NSUInteger TransportIdHash(GRPCTransportID);
NSUInteger TransportIDHash(GRPCTransportID);
#pragma mark Transport and factory
@ -63,10 +63,10 @@ NSUInteger TransportIdHash(GRPCTransportID);
/**
* 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
* 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
- (void)registerTransportWithID:(GRPCTransportID)transportID
factory:(id<GRPCTransportFactory>)factory;
@end

@ -18,28 +18,28 @@
#import "GRPCTransport.h"
static const GRPCTransportID gGRPCCoreSecureId = "io.grpc.transport.core.secure";
static const GRPCTransportID gGRPCCoreInsecureId = "io.grpc.transport.core.insecure";
static const GRPCTransportID gGRPCCoreSecureID = "io.grpc.transport.core.secure";
static const GRPCTransportID gGRPCCoreInsecureID = "io.grpc.transport.core.insecure";
const struct GRPCDefaultTransportImplList GRPCDefaultTransportImplList = {
.core_secure = gGRPCCoreSecureId, .core_insecure = gGRPCCoreInsecureId};
.core_secure = gGRPCCoreSecureID, .core_insecure = gGRPCCoreInsecureID};
static const GRPCTransportID gDefaultTransportId = gGRPCCoreSecureId;
static const GRPCTransportID gDefaultTransportID = gGRPCCoreSecureID;
static GRPCTransportRegistry *gTransportRegistry = nil;
static dispatch_once_t initTransportRegistry;
BOOL TransportIdIsEqual(GRPCTransportID lhs, GRPCTransportID rhs) {
BOOL TransportIDIsEqual(GRPCTransportID lhs, GRPCTransportID rhs) {
// Directly comparing pointers works because we require users to use the id provided by each
// implementation, not coming up with their own string.
return lhs == rhs;
}
NSUInteger TransportIdHash(GRPCTransportID transportId) {
if (transportId == NULL) {
transportId = gDefaultTransportId;
NSUInteger TransportIDHash(GRPCTransportID transportID) {
if (transportID == NULL) {
transportID = gDefaultTransportID;
}
return [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding].hash;
return [NSString stringWithCString:transportID encoding:NSUTF8StringEncoding].hash;
}
@implementation GRPCTransportRegistry {
@ -66,25 +66,25 @@ NSUInteger TransportIdHash(GRPCTransportID transportId) {
return self;
}
- (void)registerTransportWithId:(GRPCTransportID)transportId
- (void)registerTransportWithID:(GRPCTransportID)transportID
factory:(id<GRPCTransportFactory>)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);
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;
}
_registry[nsTransportId] = factory;
_registry[nsTransportID] = factory;
// if the default transport is registered, mark it.
if (0 == strcmp(transportId, gDefaultTransportId)) {
if (0 == strcmp(transportID, gDefaultTransportID)) {
_defaultFactory = factory;
}
}
- (id<GRPCTransportFactory>)getTransportFactoryWithId:(GRPCTransportID)transportId {
if (transportId == NULL) {
- (id<GRPCTransportFactory>)getTransportFactoryWithID:(GRPCTransportID)transportID {
if (transportID == NULL) {
if (_defaultFactory == nil) {
// fall back to default transport if no transport is provided
[NSException raise:NSInvalidArgumentException
@ -93,17 +93,17 @@ NSUInteger TransportIdHash(GRPCTransportID transportId) {
}
return _defaultFactory;
}
NSString *nsTransportId = [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding];
id<GRPCTransportFactory> transportFactory = _registry[nsTransportId];
NSString *nsTransportID = [NSString stringWithCString:transportID encoding:NSUTF8StringEncoding];
id<GRPCTransportFactory> transportFactory = _registry[nsTransportID];
if (transportFactory == nil) {
if (_defaultFactory != nil) {
// fall back to default transport if no transport is found
NSLog(@"Unable to find transport with id %s; falling back to default transport.",
transportId);
transportID);
return _defaultFactory;
} else {
[NSException raise:NSInvalidArgumentException
format:@"Unable to find transport with id %s", transportId];
format:@"Unable to find transport with id %s", transportID];
return nil;
}
}

@ -53,7 +53,7 @@
- (id<GRPCChannelFactory>)channelFactory {
if (_callOptions.transport != NULL) {
id<GRPCTransportFactory> transportFactory =
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:_callOptions.transport];
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithID:_callOptions.transport];
if (!
[transportFactory respondsToSelector:@selector(createCoreChannelFactoryWithCallOptions:)]) {
// impossible because we are using GRPCCore now
@ -84,7 +84,7 @@
}
case GRPCTransportTypeCronet: {
id<GRPCCoreTransportFactory> transportFactory = (id<GRPCCoreTransportFactory>)[
[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:gGRPCCoreCronetId];
[GRPCTransportRegistry sharedInstance] getTransportFactoryWithID:gGRPCCoreCronetID];
return [transportFactory createCoreChannelFactoryWithCallOptions:_callOptions];
}
case GRPCTransportTypeInsecure:

@ -24,7 +24,7 @@
* 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
* 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<GRPCCoreTransportFactory>

@ -39,7 +39,7 @@ static dispatch_once_t gInitGRPCCoreCronetFactory;
+ (void)load {
[[GRPCTransportRegistry sharedInstance]
registerTransportWithId:gGRPCCoreCronetId
registerTransportWithID:gGRPCCoreCronetID
factory:[GRPCCoreCronetFactory sharedInstance]];
}

@ -40,7 +40,7 @@ static dispatch_once_t gInitGRPCCoreInsecureFactory;
+ (void)load {
[[GRPCTransportRegistry sharedInstance]
registerTransportWithId:GRPCDefaultTransportImplList.core_secure
registerTransportWithID:GRPCDefaultTransportImplList.core_secure
factory:[self sharedInstance]];
}
@ -75,7 +75,7 @@ static dispatch_once_t gInitGRPCCoreInsecureFactory;
+ (void)load {
[[GRPCTransportRegistry sharedInstance]
registerTransportWithId:GRPCDefaultTransportImplList.core_insecure
registerTransportWithID:GRPCDefaultTransportImplList.core_insecure
factory:[self sharedInstance]];
}

@ -115,7 +115,7 @@ static NSMutableDictionary *gHostCache;
if (_transportType == GRPCTransportTypeInsecure) {
options.transport = GRPCDefaultTransportImplList.core_insecure;
} else if ([GRPCCall isUsingCronet]) {
options.transport = gGRPCCoreCronetId;
options.transport = gGRPCCoreCronetID;
} else {
options.transport = GRPCDefaultTransportImplList.core_secure;
}

@ -31,13 +31,13 @@ NS_ASSUME_NONNULL_BEGIN
* registered with the registry, the default transport factory (core + secure) is returned. If the
* default transport does not exist, an exception is thrown.
*/
- (id<GRPCTransportFactory>)getTransportFactoryWithId:(GRPCTransportID)transportId;
- (id<GRPCTransportFactory>)getTransportFactoryWithID:(GRPCTransportID)transportID;
@end
@interface GRPCTransportManager : NSObject<GRPCInterceptorInterface>
- (instancetype)initWithTransportId:(GRPCTransportID)transportId
- (instancetype)initWithTransportID:(GRPCTransportID)transportID
previousInterceptor:(id<GRPCResponseHandler>)previousInterceptor;
/**

@ -21,27 +21,27 @@
#import <GRPCClient/GRPCTransport.h>
@implementation GRPCTransportManager {
GRPCTransportID _transportId;
GRPCTransportID _transportID;
GRPCTransport *_transport;
id<GRPCResponseHandler> _previousInterceptor;
dispatch_queue_t _dispatchQueue;
}
- (instancetype)initWithTransportId:(GRPCTransportID)transportId
- (instancetype)initWithTransportID:(GRPCTransportID)transportID
previousInterceptor:(id<GRPCResponseHandler>)previousInterceptor {
if ((self = [super init])) {
id<GRPCTransportFactory> factory =
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:transportId];
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithID:transportID];
_transport = [factory createTransportWithManager:self];
NSAssert(_transport != nil, @"Failed to create transport with id: %s", transportId);
NSAssert(_transport != nil, @"Failed to create transport with id: %s", transportID);
if (_transport == nil) {
NSLog(@"Failed to create transport with id: %s", transportId);
NSLog(@"Failed to create transport with id: %s", transportID);
return nil;
}
_previousInterceptor = previousInterceptor;
_dispatchQueue = _transport.dispatchQueue;
_transportId = transportId;
_transportID = transportID;
}
return self;
}
@ -58,7 +58,7 @@
- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions
callOptions:(GRPCCallOptions *)callOptions {
if (_transportId != callOptions.transport) {
if (_transportID != callOptions.transport) {
[NSException raise:NSInvalidArgumentException
format:@"Interceptors cannot change the call option 'transport'"];
return;

@ -53,7 +53,7 @@ static int32_t kRemoteInteropServerOverhead = 12;
}
+ (GRPCTransportID)transport {
return gGRPCCoreCronetId;
return gGRPCCoreCronetID;
}
- (int32_t)encodingOverhead {

@ -30,9 +30,9 @@
- (void)testCronetImplementationExist {
id<GRPCTransportFactory> secureTransportFactory = [[GRPCTransportRegistry sharedInstance]
getTransportFactoryWithId:GRPCDefaultTransportImplList.core_secure];
getTransportFactoryWithID:GRPCDefaultTransportImplList.core_secure];
id<GRPCTransportFactory> cronetTransportFactory =
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:gGRPCCoreCronetId];
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithID:gGRPCCoreCronetID];
XCTAssertNotNil(secureTransportFactory);
XCTAssertNotNil(cronetTransportFactory);
XCTAssertNotEqual(secureTransportFactory, cronetTransportFactory);

@ -1268,7 +1268,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
- (void)testKeepaliveWithV2API {
XCTAssertNotNil([[self class] host]);
if ([[self class] transport] == gGRPCCoreCronetId) {
if ([[self class] transport] == gGRPCCoreCronetID) {
// Cronet does not support keepalive
return;
}

@ -30,9 +30,9 @@
- (void)testDefaultImplementationsExist {
id<GRPCTransportFactory> secureTransportFactory = [[GRPCTransportRegistry sharedInstance]
getTransportFactoryWithId:GRPCDefaultTransportImplList.core_secure];
getTransportFactoryWithID:GRPCDefaultTransportImplList.core_secure];
id<GRPCTransportFactory> insecureTransportFactory = [[GRPCTransportRegistry sharedInstance]
getTransportFactoryWithId:GRPCDefaultTransportImplList.core_insecure];
getTransportFactoryWithID:GRPCDefaultTransportImplList.core_insecure];
XCTAssertNotNil(secureTransportFactory);
XCTAssertNotNil(insecureTransportFactory);
XCTAssertNotEqual(secureTransportFactory, insecureTransportFactory);
@ -40,9 +40,9 @@
- (void)testCronetImplementationNotExistAndFallBack {
id<GRPCTransportFactory> secureTransportFactory = [[GRPCTransportRegistry sharedInstance]
getTransportFactoryWithId:GRPCDefaultTransportImplList.core_secure];
getTransportFactoryWithID:GRPCDefaultTransportImplList.core_secure];
id<GRPCTransportFactory> cronetTransportFactory =
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:gGRPCCoreCronetId];
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithID:gGRPCCoreCronetID];
XCTAssertNotNil(secureTransportFactory);
XCTAssertNotNil(cronetTransportFactory);
XCTAssertEqual(secureTransportFactory, cronetTransportFactory);

Loading…
Cancel
Save