blob: 3e9cc5c0b2de1957aad8cbebfb9923df1a153ead [file] [log] [blame]
Jorge Canizales2779ccb2015-04-20 23:42:46 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Jorge Canizales2779ccb2015-04-20 23:42:46 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Jorge Canizales2779ccb2015-04-20 23:42:46 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Jorge Canizales2779ccb2015-04-20 23:42:46 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Jorge Canizales2779ccb2015-04-20 23:42:46 -070016 *
17 */
18
19#import "ProtoService.h"
20
Jorge Canizales3936ed72015-06-21 14:43:56 -070021#import <RxLibrary/GRXWriteable.h>
22#import <RxLibrary/GRXWriter.h>
Jorge Canizales2779ccb2015-04-20 23:42:46 -070023
Jorge Canizalesbe808e32015-07-04 14:37:58 -070024#import "ProtoMethod.h"
Jorge Canizales2779ccb2015-04-20 23:42:46 -070025#import "ProtoRPC.h"
26
Muxi Yan45ca2022018-02-05 11:48:00 -080027#pragma clang diagnostic push
28#pragma clang diagnostic ignored "-Wdeprecated-implementations"
Jorge Canizales2779ccb2015-04-20 23:42:46 -070029@implementation ProtoService {
Muxi Yan45ca2022018-02-05 11:48:00 -080030#pragma clang diagnostic pop
Jorge Canizales2779ccb2015-04-20 23:42:46 -070031 NSString *_host;
32 NSString *_packageName;
33 NSString *_serviceName;
34}
35
36- (instancetype)init {
Jorge Canizalesf593fef2015-04-21 01:40:19 -070037 return [self initWithHost:nil packageName:nil serviceName:nil];
Jorge Canizales2779ccb2015-04-20 23:42:46 -070038}
39
40// Designated initializer
41- (instancetype)initWithHost:(NSString *)host
42 packageName:(NSString *)packageName
43 serviceName:(NSString *)serviceName {
44 if (!host || !serviceName) {
45 [NSException raise:NSInvalidArgumentException
46 format:@"Neither host nor serviceName can be nil."];
47 }
48 if ((self = [super init])) {
49 _host = [host copy];
50 _packageName = [packageName copy];
51 _serviceName = [serviceName copy];
52 }
53 return self;
54}
55
Makarand Dharmapurikarfc5f5052016-06-27 13:40:50 -070056- (GRPCProtoCall *)RPCToMethod:(NSString *)method
Makarand Dharmapurikar96e3d1c2016-06-27 16:45:36 -070057 requestsWriter:(GRXWriter *)requestsWriter
58 responseClass:(Class)responseClass
59 responsesWriteable:(id<GRXWriteable>)responsesWriteable {
Muxi Yanc92d90a2018-04-11 18:10:02 -070060 GRPCProtoMethod *methodName =
61 [[GRPCProtoMethod alloc] initWithPackage:_packageName service:_serviceName method:method];
Makarand Dharmapurikarfc5f5052016-06-27 13:40:50 -070062 return [[GRPCProtoCall alloc] initWithHost:_host
Makarand Dharmapurikar7a3c4272016-06-27 16:36:36 -070063 method:methodName
64 requestsWriter:requestsWriter
65 responseClass:responseClass
66 responsesWriteable:responsesWriteable];
Jorge Canizales2779ccb2015-04-20 23:42:46 -070067}
68@end
Makarand Dharmapurikar6f950102016-06-07 16:52:19 -070069
70@implementation GRPCProtoService
71
72@end