aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@google.com>2015-07-31 23:48:56 -0700
committerGravatar Jorge Canizales <jcanizales@google.com>2015-08-01 18:02:25 -0700
commit3a5253eb129fa712f6962d0b8dc2b680b4e616c3 (patch)
tree43d62830b8d750c1f34e1e1787c93166b3a8e1f1
parentfaf58b84b5076ed4e20d825b2961d9313cd45649 (diff)
Move _channel from GRPCCall into GRPCWrappedCall
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m9
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.h7
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.m23
3 files changed, 21 insertions, 18 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 9d9648ae28..b6d4d52c7e 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.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);
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
index 18f8bb5531..da11cbb761 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
@@ -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;
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
index 1db63df77f..4681994bb2 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
@@ -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,