Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * 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 Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * 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 Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #import "ProtoService.h" |
| 20 | |
Jorge Canizales | 3936ed7 | 2015-06-21 14:43:56 -0700 | [diff] [blame] | 21 | #import <RxLibrary/GRXWriteable.h> |
| 22 | #import <RxLibrary/GRXWriter.h> |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 23 | |
Jorge Canizales | be808e3 | 2015-07-04 14:37:58 -0700 | [diff] [blame] | 24 | #import "ProtoMethod.h" |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 25 | #import "ProtoRPC.h" |
| 26 | |
Muxi Yan | 45ca202 | 2018-02-05 11:48:00 -0800 | [diff] [blame] | 27 | #pragma clang diagnostic push |
| 28 | #pragma clang diagnostic ignored "-Wdeprecated-implementations" |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 29 | @implementation ProtoService { |
Muxi Yan | 45ca202 | 2018-02-05 11:48:00 -0800 | [diff] [blame] | 30 | #pragma clang diagnostic pop |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 31 | NSString *_host; |
| 32 | NSString *_packageName; |
| 33 | NSString *_serviceName; |
| 34 | } |
| 35 | |
| 36 | - (instancetype)init { |
Jorge Canizales | f593fef | 2015-04-21 01:40:19 -0700 | [diff] [blame] | 37 | return [self initWithHost:nil packageName:nil serviceName:nil]; |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 38 | } |
| 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 Dharmapurikar | fc5f505 | 2016-06-27 13:40:50 -0700 | [diff] [blame] | 56 | - (GRPCProtoCall *)RPCToMethod:(NSString *)method |
Makarand Dharmapurikar | 96e3d1c | 2016-06-27 16:45:36 -0700 | [diff] [blame] | 57 | requestsWriter:(GRXWriter *)requestsWriter |
| 58 | responseClass:(Class)responseClass |
| 59 | responsesWriteable:(id<GRXWriteable>)responsesWriteable { |
Muxi Yan | c92d90a | 2018-04-11 18:10:02 -0700 | [diff] [blame] | 60 | GRPCProtoMethod *methodName = |
| 61 | [[GRPCProtoMethod alloc] initWithPackage:_packageName service:_serviceName method:method]; |
Makarand Dharmapurikar | fc5f505 | 2016-06-27 13:40:50 -0700 | [diff] [blame] | 62 | return [[GRPCProtoCall alloc] initWithHost:_host |
Makarand Dharmapurikar | 7a3c427 | 2016-06-27 16:36:36 -0700 | [diff] [blame] | 63 | method:methodName |
| 64 | requestsWriter:requestsWriter |
| 65 | responseClass:responseClass |
| 66 | responsesWriteable:responsesWriteable]; |
Jorge Canizales | 2779ccb | 2015-04-20 23:42:46 -0700 | [diff] [blame] | 67 | } |
| 68 | @end |
Makarand Dharmapurikar | 6f95010 | 2016-06-07 16:52:19 -0700 | [diff] [blame] | 69 | |
| 70 | @implementation GRPCProtoService |
| 71 | |
| 72 | @end |