Move _channel from GRPCCall into GRPCWrappedCall

pull/2754/head
Jorge Canizales 9 years ago
parent faf58b84b5
commit 3a5253eb12
  1. 9
      src/objective-c/GRPCClient/GRPCCall.m
  2. 7
      src/objective-c/GRPCClient/private/GRPCWrappedCall.h
  3. 23
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m

@ -37,7 +37,6 @@
#include <grpc/support/time.h>
#import <RxLibrary/GRXConcurrentWriteable.h>
#import "private/GRPCChannel.h"
#import "private/GRPCWrappedCall.h"
#import "private/NSData+GRPC.h"
#import "private/NSDictionary+GRPC.h"
@ -70,8 +69,6 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
GRPCWrappedCall *_wrappedCall;
dispatch_once_t _callAlreadyInvoked;
GRPCChannel *_channel;
// The C gRPC library has less guarantees on the ordering of events than we
// do. Particularly, in the face of errors, there's no ordering guarantee at
// all. This wrapper over our actual writeable ensures thread-safety and
@ -105,11 +102,7 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
format:@"The requests writer can't be already started."];
}
if ((self = [super init])) {
_channel = [GRPCChannel channelToHost:host];
_wrappedCall = [[GRPCWrappedCall alloc] initWithChannel:_channel
path:path
host:host];
_wrappedCall = [[GRPCWrappedCall alloc] initWithHost:host path:path];
// Serial queue to invoke the non-reentrant methods of the grpc_call object.
_callQueue = dispatch_queue_create("org.grpc.call", NULL);

@ -81,11 +81,12 @@
@end
#pragma mark GRPCWrappedCall
@interface GRPCWrappedCall : NSObject
- (instancetype)initWithChannel:(GRPCChannel *)channel
path:(NSString *)path
host:(NSString *)host NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path NS_DESIGNATED_INITIALIZER;
- (void)startBatchWithOperations:(NSArray *)ops errorHandler:(void(^)())errorHandler;

@ -32,10 +32,13 @@
*/
#import "GRPCWrappedCall.h"
#import <Foundation/Foundation.h>
#include <grpc/grpc.h>
#include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h>
#import "GRPCChannel.h"
#import "GRPCCompletionQueue.h"
#import "NSDictionary+GRPC.h"
#import "NSData+GRPC.h"
@ -219,21 +222,23 @@
@end
#pragma mark GRPCWrappedCall
@implementation GRPCWrappedCall{
GRPCChannel *_channel;
grpc_call *_call;
GRPCCompletionQueue *_queue;
}
- (instancetype)init {
return [self initWithChannel:nil path:nil host:nil];
return [self initWithHost:nil path:nil];
}
- (instancetype)initWithChannel:(GRPCChannel *)channel
path:(NSString *)path
host:(NSString *)host {
if (!channel || !path || !host) {
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path {
if (!path || !host) {
[NSException raise:NSInvalidArgumentException
format:@"channel, method, and host cannot be nil."];
format:@"path and host cannot be nil."];
}
if (self = [super init]) {
@ -246,7 +251,11 @@
if (!_queue) {
return nil;
}
_call = grpc_channel_create_call(channel.unmanagedChannel,
_channel = [GRPCChannel channelToHost:host];
if (!_channel) {
return nil;
}
_call = grpc_channel_create_call(_channel.unmanagedChannel,
_queue.unmanagedQueue,
path.UTF8String,
host.UTF8String,

Loading…
Cancel
Save