Move ProtoMethod to ProtoRPC package

pull/2301/head
Jorge Canizales 10 years ago
parent 1ac8f9a26a
commit be808e36f6
  1. 4
      src/objective-c/GRPCClient/GRPCCall.h
  2. 10
      src/objective-c/GRPCClient/GRPCCall.m
  3. 40
      src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.h
  4. 44
      src/objective-c/GRPCClient/private/GRPCMethodName+HTTP2Encoding.m
  5. 2
      src/objective-c/GRPCClient/private/GRPCWrappedCall.h
  6. 8
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  7. 12
      src/objective-c/ProtoRPC/ProtoMethod.h
  8. 12
      src/objective-c/ProtoRPC/ProtoMethod.m
  9. 2
      src/objective-c/ProtoRPC/ProtoRPC.h
  10. 15
      src/objective-c/ProtoRPC/ProtoRPC.m
  11. 6
      src/objective-c/ProtoRPC/ProtoService.m
  12. 22
      src/objective-c/tests/GRPCClientTests.m
  13. 14
      src/objective-c/tests/LocalClearTextTests.m

@ -48,8 +48,6 @@
#import <Foundation/Foundation.h>
#import <RxLibrary/GRXWriter.h>
@class ProtoMethod;
// 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:(ProtoMethod *)method
path:(NSString *)path
requestsWriter:(id<GRXWriter>)requestsWriter NS_DESIGNATED_INITIALIZER;
// Finishes the request side of this call, notifies the server that the RPC

@ -36,11 +36,9 @@
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#import "ProtoMethod.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:(ProtoMethod *)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.

@ -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 "GRPCClient/ProtoMethod.h"
@interface ProtoMethod (HTTP2Encoding)
- (NSString *)HTTP2Path;
@end

@ -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 ProtoMethod (HTTP2Encoding)
- (NSString *)HTTP2Path {
if (self.package) {
return [NSString stringWithFormat:@"/%@.%@/%@", self.package, self.service, self.method];
} else {
return [NSString stringWithFormat:@"/%@/%@", self.service, self.method];
}
}
@end

@ -84,7 +84,7 @@
@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;

@ -225,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."];
}
@ -247,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;
}

@ -33,16 +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.
// 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 *service;
@property(nonatomic, readonly) NSString *method;
@property(nonatomic, readonly) NSString *HTTP2Path;
- (instancetype)initWithPackage:(NSString *)package
interface:(NSString *)interface
service:(NSString *)service
method:(NSString *)method;
@end

@ -35,13 +35,21 @@
@implementation ProtoMethod
- (instancetype)initWithPackage:(NSString *)package
interface:(NSString *)interface
service:(NSString *)service
method:(NSString *)method {
if ((self = [super init])) {
_package = [package copy];
_service = [interface copy];
_service = [service copy];
_method = [method copy];
}
return self;
}
- (NSString *)HTTP2Path {
if (_package) {
return [NSString stringWithFormat:@"/%@.%@/%@", _package, _service, _method];
} else {
return [NSString stringWithFormat:@"/%@/%@", _service, _method];
}
}
@end

@ -34,6 +34,8 @@
#import <Foundation/Foundation.h>
#import <GRPCClient/GRPCCall.h>
#import "ProtoMethod.h"
@interface ProtoRPC : GRPCCall
- (instancetype)initWithHost:(NSString *)host

@ -42,15 +42,16 @@
id<GRXWriteable> _responseWriteable;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithHost:(NSString *)host
method:(ProtoMethod *)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
@ -70,7 +71,7 @@
// sending GPBMessages.
return [proto data];
}];
if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) {
if ((self = [super initWithHost:host path:method.HTTP2Path requestsWriter:bytesWriter])) {
// A writeable that parses the proto messages received.
_responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
[responsesWriteable writeValue:[responseClass parseFromData:value error:NULL]];

@ -33,10 +33,10 @@
#import "ProtoService.h"
#import <GRPCClient/ProtoMethod.h>
#import <RxLibrary/GRXWriteable.h>
#import <RxLibrary/GRXWriter.h>
#import "ProtoMethod.h"
#import "ProtoRPC.h"
@implementation ProtoService {
@ -70,8 +70,8 @@
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable {
ProtoMethod *methodName = [[ProtoMethod alloc] initWithPackage:_packageName
interface:_serviceName
method:method];
service:_serviceName
method:method];
return [[ProtoRPC alloc] initWithHost:_host
method:methodName
requestsWriter:requestsWriter

@ -35,7 +35,7 @@
#import <XCTest/XCTest.h>
#import <GRPCClient/GRPCCall.h>
#import <GRPCClient/ProtoMethod.h>
#import <ProtoRPC/ProtoMethod.h>
#import <RemoteTest/Messages.pbobjc.h>
#import <RxLibrary/GRXWriteable.h>
#import <RxLibrary/GRXWriter+Immediate.h>
@ -59,21 +59,21 @@ static ProtoMethod *kUnaryCallMethod;
- (void)setUp {
// This method isn't implemented by the remote server.
kInexistentMethod = [[ProtoMethod alloc] initWithPackage:kPackage
interface:kService
method:@"Inexistent"];
service:kService
method:@"Inexistent"];
kEmptyCallMethod = [[ProtoMethod alloc] initWithPackage:kPackage
interface:kService
method:@"EmptyCall"];
service:kService
method:@"EmptyCall"];
kUnaryCallMethod = [[ProtoMethod alloc] initWithPackage:kPackage
interface:kService
method:@"UnaryCall"];
service:kService
method:@"UnaryCall"];
}
- (void)testConnectionToRemoteServer {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
method:kInexistentMethod
path:kInexistentMethod.HTTP2Path
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@ -95,7 +95,7 @@ static ProtoMethod *kUnaryCallMethod;
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
method:kEmptyCallMethod
path:kEmptyCallMethod.HTTP2Path
requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@ -123,7 +123,7 @@ static ProtoMethod *kUnaryCallMethod;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
method:kUnaryCallMethod
path:kUnaryCallMethod.HTTP2Path
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@ -153,7 +153,7 @@ static ProtoMethod *kUnaryCallMethod;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
method:kUnaryCallMethod
path:kUnaryCallMethod.HTTP2Path
requestsWriter:requestsWriter];
call.requestMetadata[@"Authorization"] = @"Bearer bogusToken";

@ -35,7 +35,7 @@
#import <XCTest/XCTest.h>
#import <GRPCClient/GRPCCall.h>
#import <GRPCClient/ProtoMethod.h>
#import <ProtoRPC/ProtoMethod.h>
#import <RouteGuide/RouteGuide.pbobjc.h>
#import <RouteGuide/RouteGuide.pbrpc.h>
#import <RxLibrary/GRXWriteable.h>
@ -88,13 +88,13 @@ static NSString * const kService = @"RouteGuide";
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
ProtoMethod *method = [[ProtoMethod alloc] initWithPackage:kPackage
interface:kService
method:@"RecordRoute"];
service:kService
method:@"RecordRoute"];
id<GRXWriter> requestsWriter = [GRXWriter emptyWriter];
GRPCCall *call = [[GRPCCall alloc] initWithHost:kRouteGuideHost
method:method
path:method.HTTP2Path
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
@ -116,8 +116,8 @@ static NSString * const kService = @"RouteGuide";
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
ProtoMethod *method = [[ProtoMethod alloc] initWithPackage:kPackage
interface:kService
method:@"GetFeature"];
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.HTTP2Path
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {

Loading…
Cancel
Save