aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c
diff options
context:
space:
mode:
Diffstat (limited to 'src/objective-c')
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.h6
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m12
-rw-r--r--src/objective-c/GRPCClient/private/GRPCDelegateWrapper.m2
-rw-r--r--src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.h40
-rw-r--r--src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.m44
-rw-r--r--src/objective-c/GRPCClient/private/GRPCSecureChannel.m8
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.h34
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.m200
-rw-r--r--src/objective-c/GRPCClient/private/NSError+GRPC.m2
-rw-r--r--src/objective-c/ProtoRPC/ProtoMethod.h (renamed from src/objective-c/GRPCClient/GRPCMethodName.h)17
-rw-r--r--src/objective-c/ProtoRPC/ProtoMethod.m (renamed from src/objective-c/GRPCClient/GRPCMethodName.m)16
-rw-r--r--src/objective-c/ProtoRPC/ProtoRPC.h6
-rw-r--r--src/objective-c/ProtoRPC/ProtoRPC.m27
-rw-r--r--src/objective-c/ProtoRPC/ProtoService.m12
-rw-r--r--src/objective-c/RxLibrary/transformations/GRXMappingWriter.h2
-rw-r--r--src/objective-c/examples/Sample/Sample/ViewController.m8
-rw-r--r--src/objective-c/tests/GRPCClientTests.m40
-rw-r--r--src/objective-c/tests/InteropTests.m14
-rw-r--r--src/objective-c/tests/LocalClearTextTests.m24
-rw-r--r--src/objective-c/tests/RxLibraryUnitTests.m6
20 files changed, 209 insertions, 311 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h
index 7b42498d42..cba53fa2f6 100644
--- a/src/objective-c/GRPCClient/GRPCCall.h
+++ b/src/objective-c/GRPCClient/GRPCCall.h
@@ -46,9 +46,7 @@
// transparently on the same TCP connection.
#import <Foundation/Foundation.h>
-#import <gRPC/GRXWriter.h>
-
-@class GRPCMethodName;
+#import <RxLibrary/GRXWriter.h>
// Key used in |NSError|'s |userInfo| dictionary to store the response metadata sent by the server.
extern id const kGRPCStatusMetadataKey;
@@ -90,7 +88,7 @@ extern id const kGRPCStatusMetadataKey;
// the specific remote method called).
// To finish a call right away, invoke cancel.
- (instancetype)initWithHost:(NSString *)host
- method:(GRPCMethodName *)method
+ path:(NSString *)path
requestsWriter:(id<GRXWriter>)requestsWriter NS_DESIGNATED_INITIALIZER;
// Finishes the request side of this call, notifies the server that the RPC
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index a9625a1799..4ac4e4d37f 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -34,13 +34,11 @@
#import "GRPCCall.h"
#include <grpc/grpc.h>
-#include <grpc/support/grpc_time.h>
+#include <grpc/support/time.h>
-#import "GRPCMethodName.h"
#import "private/GRPCChannel.h"
#import "private/GRPCCompletionQueue.h"
#import "private/GRPCDelegateWrapper.h"
-#import "private/GRPCMethodName+HTTP2Encoding.h"
#import "private/GRPCWrappedCall.h"
#import "private/NSData+GRPC.h"
#import "private/NSDictionary+GRPC.h"
@@ -90,14 +88,14 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
@synthesize state = _state;
- (instancetype)init {
- return [self initWithHost:nil method:nil requestsWriter:nil];
+ return [self initWithHost:nil path:nil requestsWriter:nil];
}
// Designated initializer
- (instancetype)initWithHost:(NSString *)host
- method:(GRPCMethodName *)method
+ path:(NSString *)path
requestsWriter:(id<GRXWriter>)requestWriter {
- if (!host || !method) {
+ if (!host || !path) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor method can be nil."];
}
if (requestWriter.state != GRXWriterStateNotStarted) {
@@ -114,7 +112,7 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
_channel = [GRPCChannel channelToHost:host];
_wrappedCall = [[GRPCWrappedCall alloc] initWithChannel:_channel
- method:method.HTTP2Path
+ path:path
host:host];
// Serial queue to invoke the non-reentrant methods of the grpc_call object.
diff --git a/src/objective-c/GRPCClient/private/GRPCDelegateWrapper.m b/src/objective-c/GRPCClient/private/GRPCDelegateWrapper.m
index 7d5ecb56d9..59c0565494 100644
--- a/src/objective-c/GRPCClient/private/GRPCDelegateWrapper.m
+++ b/src/objective-c/GRPCClient/private/GRPCDelegateWrapper.m
@@ -33,7 +33,7 @@
#import "GRPCDelegateWrapper.h"
-#import <gRPC/GRXWriteable.h>
+#import <RxLibrary/GRXWriteable.h>
@interface GRPCDelegateWrapper ()
// These are atomic so that cancellation can nillify them from any thread.
diff --git a/src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.h b/src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.h
deleted file mode 100644
index 28c7374517..0000000000
--- a/src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#import <Foundation/Foundation.h>
-
-#import "GRPCMethodName.h"
-
-@interface GRPCMethodName (HTTP2Encoding)
-- (NSString *)HTTP2Path;
-@end
diff --git a/src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.m b/src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.m
deleted file mode 100644
index 3ad757fb29..0000000000
--- a/src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.m
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#import "GRPCMethodName+HTTP2Encoding.h"
-
-@implementation GRPCMethodName (HTTP2Encoding)
-- (NSString *)HTTP2Path {
- if (self.package) {
- return [NSString stringWithFormat:@"/%@.%@/%@", self.package, self.interface, self.method];
- } else {
- return [NSString stringWithFormat:@"/%@/%@", self.interface, self.method];
- }
-}
-@end
diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannel.m b/src/objective-c/GRPCClient/private/GRPCSecureChannel.m
index 2cbc6e0f83..43a8bd539e 100644
--- a/src/objective-c/GRPCClient/private/GRPCSecureChannel.m
+++ b/src/objective-c/GRPCClient/private/GRPCSecureChannel.m
@@ -38,13 +38,17 @@
@implementation GRPCSecureChannel
- (instancetype)initWithHost:(NSString *)host {
- static const grpc_credentials *kCredentials;
+ static grpc_credentials *kCredentials;
static dispatch_once_t loading;
dispatch_once(&loading, ^{
// Do not use NSBundle.mainBundle, as it's nil for tests of library projects.
NSBundle *bundle = [NSBundle bundleForClass:self.class];
- NSString *certsPath = [bundle pathForResource:@"gRPC.bundle/roots" ofType:@"pem"];
+ NSString *certsPath = [bundle pathForResource:@"gRPCCertificates.bundle/roots" ofType:@"pem"];
+ NSAssert(certsPath.length,
+ @"gRPCCertificates.bundle/roots.pem not found under %@. This file, with the root "
+ "certificates, is needed to establish TLS (HTTPS) connections.", bundle.bundlePath);
NSData *certsData = [NSData dataWithContentsOfFile:certsPath];
+ NSAssert(certsData.length, @"No data read from %@", certsPath);
NSString *certsString = [[NSString alloc] initWithData:certsData encoding:NSUTF8StringEncoding];
kCredentials = grpc_ssl_credentials_create(certsString.UTF8String, NULL);
});
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
index 4deeec0475..18f8bb5531 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
@@ -33,60 +33,58 @@
#import <Foundation/Foundation.h>
#include <grpc/grpc.h>
-#import "GRPCChannel.h"
-
-typedef void(^GRPCCompletionHandler)(NSDictionary *);
-
-@protocol GRPCOp <NSObject>
-- (void)getOp:(grpc_op *)op;
+#import "GRPCChannel.h"
+@interface GRPCOperation : NSObject
+@property(nonatomic, readonly) grpc_op op;
+// Guaranteed to be called when the operation has finished.
- (void)finish;
-
@end
-@interface GRPCOpSendMetadata : NSObject <GRPCOp>
+@interface GRPCOpSendMetadata : GRPCOperation
- (instancetype)initWithMetadata:(NSDictionary *)metadata
- handler:(void(^)(void))handler NS_DESIGNATED_INITIALIZER;
+ handler:(void(^)())handler NS_DESIGNATED_INITIALIZER;
@end
-@interface GRPCOpSendMessage : NSObject <GRPCOp>
+@interface GRPCOpSendMessage : GRPCOperation
- (instancetype)initWithMessage:(NSData *)message
- handler:(void(^)(void))handler NS_DESIGNATED_INITIALIZER;
+ handler:(void(^)())handler NS_DESIGNATED_INITIALIZER;
@end
-@interface GRPCOpSendClose : NSObject <GRPCOp>
+@interface GRPCOpSendClose : GRPCOperation
-- (instancetype)initWithHandler:(void(^)(void))handler NS_DESIGNATED_INITIALIZER;
+- (instancetype)initWithHandler:(void(^)())handler NS_DESIGNATED_INITIALIZER;
@end
-@interface GRPCOpRecvMetadata : NSObject <GRPCOp>
+@interface GRPCOpRecvMetadata : GRPCOperation
- (instancetype)initWithHandler:(void(^)(NSDictionary *))handler NS_DESIGNATED_INITIALIZER;
@end
-@interface GRPCOpRecvMessage : NSObject <GRPCOp>
+@interface GRPCOpRecvMessage : GRPCOperation
- (instancetype)initWithHandler:(void(^)(grpc_byte_buffer *))handler NS_DESIGNATED_INITIALIZER;
@end
-@interface GRPCOpRecvStatus : NSObject <GRPCOp>
+@interface GRPCOpRecvStatus : GRPCOperation
-- (instancetype)initWithHandler:(void(^)(NSError *, NSDictionary *))handler NS_DESIGNATED_INITIALIZER;
+- (instancetype)initWithHandler:(void(^)(NSError *, NSDictionary *))handler
+ NS_DESIGNATED_INITIALIZER;
@end
@interface GRPCWrappedCall : NSObject
- (instancetype)initWithChannel:(GRPCChannel *)channel
- method:(NSString *)method
+ path:(NSString *)path
host:(NSString *)host 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 ea482b29ef..45f10f5d63 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
@@ -41,110 +41,85 @@
#import "NSData+GRPC.h"
#import "NSError+GRPC.h"
-@implementation GRPCOpSendMetadata{
- void(^_handler)(void);
- grpc_metadata *_sendMetadata;
- size_t _count;
+@implementation GRPCOperation {
+@protected
+ // Most operation subclasses don't set any flags in the grpc_op, and rely on the flag member being
+ // initialized to zero.
+ grpc_op _op;
+ void(^_handler)();
}
+- (void)finish {
+ if (_handler) {
+ _handler();
+ }
+}
+@end
+
+@implementation GRPCOpSendMetadata
+
- (instancetype)init {
return [self initWithMetadata:nil handler:nil];
}
-- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)(void))handler {
+- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)())handler {
if (self = [super init]) {
- _sendMetadata = [metadata grpc_metadataArray];
- _count = metadata.count;
+ _op.op = GRPC_OP_SEND_INITIAL_METADATA;
+ _op.data.send_initial_metadata.count = metadata.count;
+ _op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray;
_handler = handler;
}
return self;
}
-- (void)getOp:(grpc_op *)op {
- op->op = GRPC_OP_SEND_INITIAL_METADATA;
- op->data.send_initial_metadata.count = _count;
- op->data.send_initial_metadata.metadata = _sendMetadata;
-}
-
-- (void)finish {
- if (_handler) {
- _handler();
- }
-}
-
- (void)dealloc {
- gpr_free(_sendMetadata);
+ gpr_free(_op.data.send_initial_metadata.metadata);
}
@end
-@implementation GRPCOpSendMessage{
- void(^_handler)(void);
- grpc_byte_buffer *_byteBuffer;
-}
+@implementation GRPCOpSendMessage
- (instancetype)init {
return [self initWithMessage:nil handler:nil];
}
-- (instancetype)initWithMessage:(NSData *)message handler:(void (^)(void))handler {
+- (instancetype)initWithMessage:(NSData *)message handler:(void (^)())handler {
if (!message) {
[NSException raise:NSInvalidArgumentException format:@"message cannot be nil"];
}
if (self = [super init]) {
- _byteBuffer = [message grpc_byteBuffer];
+ _op.op = GRPC_OP_SEND_MESSAGE;
+ _op.data.send_message = message.grpc_byteBuffer;
_handler = handler;
}
return self;
}
-- (void)getOp:(grpc_op *)op {
- op->op = GRPC_OP_SEND_MESSAGE;
- op->data.send_message = _byteBuffer;
-}
-
-- (void)finish {
- if (_handler) {
- _handler();
- }
-}
-
- (void)dealloc {
- gpr_free(_byteBuffer);
+ gpr_free(_op.data.send_message);
}
@end
-@implementation GRPCOpSendClose{
- void(^_handler)(void);
-}
+@implementation GRPCOpSendClose
- (instancetype)init {
return [self initWithHandler:nil];
}
-- (instancetype)initWithHandler:(void (^)(void))handler {
+- (instancetype)initWithHandler:(void (^)())handler {
if (self = [super init]) {
+ _op.op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
_handler = handler;
}
return self;
}
-- (void)getOp:(grpc_op *)op {
- op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
-}
-
-- (void)finish {
- if (_handler) {
- _handler();
- }
-}
-
@end
-@implementation GRPCOpRecvMetadata{
- void(^_handler)(NSDictionary *);
- grpc_metadata_array _recvInitialMetadata;
+@implementation GRPCOpRecvMetadata {
+ grpc_metadata_array _headers;
}
- (instancetype) init {
@@ -153,33 +128,31 @@
- (instancetype) initWithHandler:(void (^)(NSDictionary *))handler {
if (self = [super init]) {
- _handler = handler;
- grpc_metadata_array_init(&_recvInitialMetadata);
+ _op.op = GRPC_OP_RECV_INITIAL_METADATA;
+ grpc_metadata_array_init(&_headers);
+ _op.data.recv_initial_metadata = &_headers;
+ if (handler) {
+ // Prevent reference cycle with _handler
+ __weak typeof(self) weakSelf = self;
+ _handler = ^{
+ __strong typeof(self) strongSelf = weakSelf;
+ NSDictionary *metadata = [NSDictionary
+ grpc_dictionaryFromMetadataArray:strongSelf->_headers];
+ handler(metadata);
+ };
+ }
}
return self;
}
-- (void)getOp:(grpc_op *)op {
- op->op = GRPC_OP_RECV_INITIAL_METADATA;
- op->data.recv_initial_metadata = &_recvInitialMetadata;
-}
-
-- (void)finish {
- NSDictionary *metadata = [NSDictionary grpc_dictionaryFromMetadataArray:_recvInitialMetadata];
- if (_handler) {
- _handler(metadata);
- }
-}
-
- (void)dealloc {
- grpc_metadata_array_destroy(&_recvInitialMetadata);
+ grpc_metadata_array_destroy(&_headers);
}
@end
@implementation GRPCOpRecvMessage{
- void(^_handler)(grpc_byte_buffer *);
- grpc_byte_buffer *_recvMessage;
+ grpc_byte_buffer *_receivedMessage;
}
- (instancetype)init {
@@ -188,30 +161,27 @@
- (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler {
if (self = [super init]) {
- _handler = handler;
+ _op.op = GRPC_OP_RECV_MESSAGE;
+ _op.data.recv_message = &_receivedMessage;
+ if (handler) {
+ // Prevent reference cycle with _handler
+ __weak typeof(self) weakSelf = self;
+ _handler = ^{
+ __strong typeof(self) strongSelf = weakSelf;
+ handler(strongSelf->_receivedMessage);
+ };
+ }
}
return self;
}
-- (void)getOp:(grpc_op *)op {
- op->op = GRPC_OP_RECV_MESSAGE;
- op->data.recv_message = &_recvMessage;
-}
-
-- (void)finish {
- if (_handler) {
- _handler(_recvMessage);
- }
-}
-
@end
@implementation GRPCOpRecvStatus{
- void(^_handler)(NSError *, NSDictionary *);
grpc_status_code _statusCode;
char *_details;
size_t _detailsCapacity;
- grpc_metadata_array _metadata;
+ grpc_metadata_array _trailers;
}
- (instancetype) init {
@@ -220,30 +190,30 @@
- (instancetype) initWithHandler:(void (^)(NSError *, NSDictionary *))handler {
if (self = [super init]) {
- _handler = handler;
- grpc_metadata_array_init(&_metadata);
+ _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ _op.data.recv_status_on_client.status = &_statusCode;
+ _op.data.recv_status_on_client.status_details = &_details;
+ _op.data.recv_status_on_client.status_details_capacity = &_detailsCapacity;
+ grpc_metadata_array_init(&_trailers);
+ _op.data.recv_status_on_client.trailing_metadata = &_trailers;
+ if (handler) {
+ // Prevent reference cycle with _handler
+ __weak typeof(self) weakSelf = self;
+ _handler = ^{
+ __strong typeof(self) strongSelf = weakSelf;
+ NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode
+ details:strongSelf->_details];
+ NSDictionary *trailers = [NSDictionary
+ grpc_dictionaryFromMetadataArray:strongSelf->_trailers];
+ handler(error, trailers);
+ };
+ }
}
return self;
}
-- (void)getOp:(grpc_op *)op {
- op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
- op->data.recv_status_on_client.status = &_statusCode;
- op->data.recv_status_on_client.status_details = &_details;
- op->data.recv_status_on_client.status_details_capacity = &_detailsCapacity;
- op->data.recv_status_on_client.trailing_metadata = &_metadata;
-}
-
-- (void)finish {
- if (_handler) {
- NSError *error = [NSError grpc_errorFromStatusCode:_statusCode details:_details];
- NSDictionary *trailers = [NSDictionary grpc_dictionaryFromMetadataArray:_metadata];
- _handler(error, trailers);
- }
-}
-
- (void)dealloc {
- grpc_metadata_array_destroy(&_metadata);
+ grpc_metadata_array_destroy(&_trailers);
gpr_free(_details);
}
@@ -255,13 +225,13 @@
}
- (instancetype)init {
- return [self initWithChannel:nil method:nil host:nil];
+ return [self initWithChannel:nil path:nil host:nil];
}
- (instancetype)initWithChannel:(GRPCChannel *)channel
- method:(NSString *)method
+ path:(NSString *)path
host:(NSString *)host {
- if (!channel || !method || !host) {
+ if (!channel || !path || !host) {
[NSException raise:NSInvalidArgumentException
format:@"channel, method, and host cannot be nil."];
}
@@ -277,7 +247,7 @@
return nil;
}
_call = grpc_channel_create_call(channel.unmanagedChannel, _queue.unmanagedQueue,
- method.UTF8String, host.UTF8String, gpr_inf_future);
+ path.UTF8String, host.UTF8String, gpr_inf_future);
if (_call == NULL) {
return nil;
}
@@ -293,8 +263,8 @@
size_t nops = operations.count;
grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op));
size_t i = 0;
- for (id op in operations) {
- [op getOp:&ops_array[i++]];
+ for (GRPCOperation *operation in operations) {
+ ops_array[i++] = operation.op;
}
grpc_call_error error = grpc_call_start_batch(_call, ops_array, nops,
(__bridge_retained void *)(^(bool success){
@@ -305,14 +275,16 @@
return;
}
}
- for (id<GRPCOp> operation in operations) {
+ for (GRPCOperation *operation in operations) {
[operation finish];
}
}));
-
+ gpr_free(ops_array);
+
if (error != GRPC_CALL_OK) {
[NSException raise:NSInternalInconsistencyException
- format:@"A precondition for calling grpc_call_start_batch wasn't met"];
+ format:@"A precondition for calling grpc_call_start_batch wasn't met. Error %i",
+ error];
}
}
diff --git a/src/objective-c/GRPCClient/private/NSError+GRPC.m b/src/objective-c/GRPCClient/private/NSError+GRPC.m
index f7390476d9..638f41cb11 100644
--- a/src/objective-c/GRPCClient/private/NSError+GRPC.m
+++ b/src/objective-c/GRPCClient/private/NSError+GRPC.m
@@ -33,7 +33,7 @@
#import "NSError+GRPC.h"
-#include <grpc.h>
+#include <grpc/grpc.h>
NSString * const kGRPCErrorDomain = @"io.grpc";
diff --git a/src/objective-c/GRPCClient/GRPCMethodName.h b/src/objective-c/ProtoRPC/ProtoMethod.h
index fe153dd478..8f554a0483 100644
--- a/src/objective-c/GRPCClient/GRPCMethodName.h
+++ b/src/objective-c/ProtoRPC/ProtoMethod.h
@@ -33,17 +33,16 @@
#import <Foundation/Foundation.h>
-// See the README file for an introduction to this library.
-
-// A fully-qualified gRPC method name. Full qualification is needed because a gRPC endpoint can
-// implement multiple interfaces.
-// TODO(jcanizales): Move to ProtoRPC package.
-// TODO(jcanizales): Rename interface -> service.
-@interface GRPCMethodName : NSObject
+// A fully-qualified proto service method name. Full qualification is needed because a gRPC endpoint
+// can implement multiple services.
+@interface ProtoMethod : NSObject
@property(nonatomic, readonly) NSString *package;
-@property(nonatomic, readonly) NSString *interface;
+@property(nonatomic, readonly) NSString *service;
@property(nonatomic, readonly) NSString *method;
+
+@property(nonatomic, readonly) NSString *HTTPPath;
+
- (instancetype)initWithPackage:(NSString *)package
- interface:(NSString *)interface
+ service:(NSString *)service
method:(NSString *)method;
@end
diff --git a/src/objective-c/GRPCClient/GRPCMethodName.m b/src/objective-c/ProtoRPC/ProtoMethod.m
index 96724073a5..1113b4fbaa 100644
--- a/src/objective-c/GRPCClient/GRPCMethodName.m
+++ b/src/objective-c/ProtoRPC/ProtoMethod.m
@@ -31,17 +31,25 @@
*
*/
-#import "GRPCMethodName.h"
+#import "ProtoMethod.h"
-@implementation GRPCMethodName
+@implementation ProtoMethod
- (instancetype)initWithPackage:(NSString *)package
- interface:(NSString *)interface
+ service:(NSString *)service
method:(NSString *)method {
if ((self = [super init])) {
_package = [package copy];
- _interface = [interface copy];
+ _service = [service copy];
_method = [method copy];
}
return self;
}
+
+- (NSString *)HTTPPath {
+ if (_package) {
+ return [NSString stringWithFormat:@"/%@.%@/%@", _package, _service, _method];
+ } else {
+ return [NSString stringWithFormat:@"/%@/%@", _service, _method];
+ }
+}
@end
diff --git a/src/objective-c/ProtoRPC/ProtoRPC.h b/src/objective-c/ProtoRPC/ProtoRPC.h
index b6375f52d6..fcc0a507fe 100644
--- a/src/objective-c/ProtoRPC/ProtoRPC.h
+++ b/src/objective-c/ProtoRPC/ProtoRPC.h
@@ -32,12 +32,14 @@
*/
#import <Foundation/Foundation.h>
-#import <gRPC/GRPCCall.h>
+#import <GRPCClient/GRPCCall.h>
+
+#import "ProtoMethod.h"
@interface ProtoRPC : GRPCCall
- (instancetype)initWithHost:(NSString *)host
- method:(GRPCMethodName *)method
+ method:(ProtoMethod *)method
requestsWriter:(id<GRXWriter>)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable NS_DESIGNATED_INITIALIZER;
diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m
index b8f8008422..fe3ccf0541 100644
--- a/src/objective-c/ProtoRPC/ProtoRPC.m
+++ b/src/objective-c/ProtoRPC/ProtoRPC.m
@@ -33,28 +33,29 @@
#import "ProtoRPC.h"
-#import <gRPC/GRXWriteable.h>
-#import <gRPC/GRXWriter.h>
-#import <gRPC/GRXWriter+Transformations.h>
-#import <Protobuf/GPBProtocolBuffers.h>
+#import <GPBProtocolBuffers.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter.h>
+#import <RxLibrary/GRXWriter+Transformations.h>
@implementation ProtoRPC {
id<GRXWriteable> _responseWriteable;
}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithHost:(NSString *)host
- method:(GRPCMethodName *)method
+ path:(NSString *)path
requestsWriter:(id<GRXWriter>)requestsWriter {
- return [self initWithHost:host
- method:method
- requestsWriter:requestsWriter
- responseClass:nil
- responsesWriteable:nil];
+ [NSException raise:NSInvalidArgumentException
+ format:@"Please use ProtoRPC's designated initializer instead."];
+ return nil;
}
+#pragma clang diagnostic pop
// Designated initializer
- (instancetype)initWithHost:(NSString *)host
- method:(GRPCMethodName *)method
+ method:(ProtoMethod *)method
requestsWriter:(id<GRXWriter>)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable {
@@ -66,9 +67,11 @@
// A writer that serializes the proto messages to send.
id<GRXWriter> bytesWriter =
[[[GRXWriter alloc] initWithWriter:requestsWriter] map:^id(GPBMessage *proto) {
+ // TODO(jcanizales): Fail with an understandable error message if the requestsWriter isn't
+ // sending GPBMessages.
return [proto data];
}];
- if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) {
+ if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter])) {
// A writeable that parses the proto messages received.
_responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
[responsesWriteable writeValue:[responseClass parseFromData:value error:NULL]];
diff --git a/src/objective-c/ProtoRPC/ProtoService.m b/src/objective-c/ProtoRPC/ProtoService.m
index 453d7b3f1a..d7c5b6a850 100644
--- a/src/objective-c/ProtoRPC/ProtoService.m
+++ b/src/objective-c/ProtoRPC/ProtoService.m
@@ -33,10 +33,10 @@
#import "ProtoService.h"
-#import <gRPC/GRPCMethodName.h>
-#import <gRPC/GRXWriteable.h>
-#import <gRPC/GRXWriter.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter.h>
+#import "ProtoMethod.h"
#import "ProtoRPC.h"
@implementation ProtoService {
@@ -69,9 +69,9 @@
requestsWriter:(id<GRXWriter>)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable {
- GRPCMethodName *methodName = [[GRPCMethodName alloc] initWithPackage:_packageName
- interface:_serviceName
- method:method];
+ ProtoMethod *methodName = [[ProtoMethod alloc] initWithPackage:_packageName
+ service:_serviceName
+ method:method];
return [[ProtoRPC alloc] initWithHost:_host
method:methodName
requestsWriter:requestsWriter
diff --git a/src/objective-c/RxLibrary/transformations/GRXMappingWriter.h b/src/objective-c/RxLibrary/transformations/GRXMappingWriter.h
index dcebb6132a..55f6f82f20 100644
--- a/src/objective-c/RxLibrary/transformations/GRXMappingWriter.h
+++ b/src/objective-c/RxLibrary/transformations/GRXMappingWriter.h
@@ -31,7 +31,7 @@
*
*/
-#import "GRXWriter.h"
+#import "RxLibrary/GRXWriter.h"
// A "proxy" writer that transforms all the values of its input writer by using a mapping function.
@interface GRXMappingWriter : GRXWriter
diff --git a/src/objective-c/examples/Sample/Sample/ViewController.m b/src/objective-c/examples/Sample/Sample/ViewController.m
index 0011a4508d..05bd6fa2db 100644
--- a/src/objective-c/examples/Sample/Sample/ViewController.m
+++ b/src/objective-c/examples/Sample/Sample/ViewController.m
@@ -33,12 +33,12 @@
#import "ViewController.h"
-#import <gRPC/GRPCCall.h>
-#import <gRPC/GRPCMethodName.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXWriteable.h>
+#import <GRPCClient/GRPCCall.h>
+#import <GRPCClient/GRPCMethodName.h>
#import <RemoteTest/Messages.pbobjc.h>
#import <RemoteTest/Test.pbrpc.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
+#import <RxLibrary/GRXWriteable.h>
@implementation ViewController
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index 268e67af2f..f9c2d5d8d6 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -34,11 +34,11 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRPCCall.h>
-#import <gRPC/GRPCMethodName.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXWriteable.h>
+#import <GRPCClient/GRPCCall.h>
+#import <ProtoRPC/ProtoMethod.h>
#import <RemoteTest/Messages.pbobjc.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
// These are a few tests similar to InteropTests, but which use the generic gRPC client (GRPCCall)
// rather than a generated proto library on top of it.
@@ -47,9 +47,9 @@ static NSString * const kHostAddress = @"grpc-test.sandbox.google.com";
static NSString * const kPackage = @"grpc.testing";
static NSString * const kService = @"TestService";
-static GRPCMethodName *kInexistentMethod;
-static GRPCMethodName *kEmptyCallMethod;
-static GRPCMethodName *kUnaryCallMethod;
+static ProtoMethod *kInexistentMethod;
+static ProtoMethod *kEmptyCallMethod;
+static ProtoMethod *kUnaryCallMethod;
@interface GRPCClientTests : XCTestCase
@end
@@ -58,22 +58,22 @@ static GRPCMethodName *kUnaryCallMethod;
- (void)setUp {
// This method isn't implemented by the remote server.
- kInexistentMethod = [[GRPCMethodName alloc] initWithPackage:kPackage
- interface:kService
- method:@"Inexistent"];
- kEmptyCallMethod = [[GRPCMethodName alloc] initWithPackage:kPackage
- interface:kService
- method:@"EmptyCall"];
- kUnaryCallMethod = [[GRPCMethodName alloc] initWithPackage:kPackage
- interface:kService
- method:@"UnaryCall"];
+ kInexistentMethod = [[ProtoMethod alloc] initWithPackage:kPackage
+ service:kService
+ method:@"Inexistent"];
+ kEmptyCallMethod = [[ProtoMethod alloc] initWithPackage:kPackage
+ service:kService
+ method:@"EmptyCall"];
+ kUnaryCallMethod = [[ProtoMethod alloc] initWithPackage:kPackage
+ service:kService
+ method:@"UnaryCall"];
}
- (void)testConnectionToRemoteServer {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
- method:kInexistentMethod
+ path:kInexistentMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@@ -95,7 +95,7 @@ static GRPCMethodName *kUnaryCallMethod;
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
- method:kEmptyCallMethod
+ path:kEmptyCallMethod.HTTPPath
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@@ -123,7 +123,7 @@ static GRPCMethodName *kUnaryCallMethod;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
- method:kUnaryCallMethod
+ path:kUnaryCallMethod.HTTPPath
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@@ -153,7 +153,7 @@ static GRPCMethodName *kUnaryCallMethod;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
- method:kUnaryCallMethod
+ path:kUnaryCallMethod.HTTPPath
requestsWriter:requestsWriter];
call.requestMetadata[@"Authorization"] = @"Bearer bogusToken";
diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m
index 0a512c17dc..74f6b231cf 100644
--- a/src/objective-c/tests/InteropTests.m
+++ b/src/objective-c/tests/InteropTests.m
@@ -36,13 +36,13 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXBufferedPipe.h>
-#import <gRPC/ProtoRPC.h>
+#import <ProtoRPC/ProtoRPC.h>
#import <RemoteTest/Empty.pbobjc.h>
#import <RemoteTest/Messages.pbobjc.h>
#import <RemoteTest/Test.pbobjc.h>
#import <RemoteTest/Test.pbrpc.h>
+#import <RxLibrary/GRXBufferedPipe.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
// Convenience constructors for the generated proto messages:
@@ -174,7 +174,7 @@
__block int index = 0;
[_service streamingOutputCallWithRequest:request
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error){
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@@ -211,7 +211,7 @@
[requestsBuffer writeValue:request];
[_service fullDuplexCallWithRequestsWriter:requestsBuffer
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@@ -242,7 +242,7 @@
- (void)testEmptyStreamRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"];
[_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter]
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@@ -283,7 +283,7 @@
[requestsBuffer writeValue:request];
__block ProtoRPC *call = [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error) {
if (receivedResponse) {
diff --git a/src/objective-c/tests/LocalClearTextTests.m b/src/objective-c/tests/LocalClearTextTests.m
index 68ffd23200..10c9f13ea3 100644
--- a/src/objective-c/tests/LocalClearTextTests.m
+++ b/src/objective-c/tests/LocalClearTextTests.m
@@ -34,12 +34,12 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRPCCall.h>
-#import <gRPC/GRPCMethodName.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXWriteable.h>
+#import <GRPCClient/GRPCCall.h>
+#import <ProtoRPC/ProtoMethod.h>
#import <RouteGuide/RouteGuide.pbobjc.h>
#import <RouteGuide/RouteGuide.pbrpc.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
// These tests require a gRPC "RouteGuide" sample server to be running locally. You can compile and
// run one by following the instructions here: https://github.com/grpc/grpc-common/blob/master/cpp/cpptutorial.md#try-it-out
@@ -87,14 +87,14 @@ static NSString * const kService = @"RouteGuide";
__weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:kPackage
- interface:kService
- method:@"RecordRoute"];
+ ProtoMethod *method = [[ProtoMethod alloc] initWithPackage:kPackage
+ service:kService
+ method:@"RecordRoute"];
id<GRXWriter> requestsWriter = [GRXWriter emptyWriter];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kRouteGuideHost
- method:method
+ path:method.HTTPPath
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@@ -115,9 +115,9 @@ static NSString * const kService = @"RouteGuide";
__weak XCTestExpectation *response = [self expectationWithDescription:@"Response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:kPackage
- interface:kService
- method:@"GetFeature"];
+ ProtoMethod *method = [[ProtoMethod alloc] initWithPackage:kPackage
+ service:kService
+ method:@"GetFeature"];
RGDPoint *point = [RGDPoint message];
point.latitude = 28E7;
@@ -125,7 +125,7 @@ static NSString * const kService = @"RouteGuide";
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[point data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kRouteGuideHost
- method:method
+ path:method.HTTPPath
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
diff --git a/src/objective-c/tests/RxLibraryUnitTests.m b/src/objective-c/tests/RxLibraryUnitTests.m
index 89984d9481..5e3162875a 100644
--- a/src/objective-c/tests/RxLibraryUnitTests.m
+++ b/src/objective-c/tests/RxLibraryUnitTests.m
@@ -34,9 +34,9 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRXBufferedPipe.h>
-#import <gRPC/GRXWriter.h>
-#import <gRPC/GRXWriteable.h>
+#import <RxLibrary/GRXBufferedPipe.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter.h>
// A mock of a GRXSingleValueHandler block that can be queried for how many times it was called and
// what were the last values passed to it.