| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2019 gRPC authors. |
| 4 |
* |
| 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 |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 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. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#import <objc/runtime.h> |
| 20 |
|
| 21 |
#import "ProtoMethod.h" |
| 22 |
#import "ProtoRPCLegacy.h" |
| 23 |
#import "ProtoService.h" |
| 24 |
|
| 25 |
#pragma clang diagnostic push |
| 26 |
#pragma clang diagnostic ignored "-Wdeprecated-implementations" |
| 27 |
@implementation ProtoService (Legacy) |
| 28 |
#pragma clang diagnostic pop |
| 29 |
|
| 30 |
#pragma clang diagnostic push |
| 31 |
#pragma clang diagnostic ignored "-Wobjc-designated-initializers" |
| 32 |
// Do not call designated initializer here due to nullability incompatibility. This method is from |
| 33 |
// old API and does not assert on nullability of the parameters. |
| 34 |
|
| 35 |
- (instancetype)initWithHost:(NSString *)host |
| 36 |
packageName:(NSString *)packageName |
| 37 |
serviceName:(NSString *)serviceName { |
| 38 |
if ((self = [super init])) { |
| 39 |
Ivar hostIvar = class_getInstanceVariable([ProtoService class], "_host"); |
| 40 |
Ivar packageNameIvar = class_getInstanceVariable([ProtoService class], "_packageName"); |
| 41 |
Ivar serviceNameIvar = class_getInstanceVariable([ProtoService class], "_serviceName"); |
| 42 |
|
| 43 |
object_setIvar(self, hostIvar, [host copy]); |
| 44 |
object_setIvar(self, packageNameIvar, [packageName copy]); |
| 45 |
object_setIvar(self, serviceNameIvar, [serviceName copy]); |
| 46 |
} |
| 47 |
return self; |
| 48 |
} |
| 49 |
#pragma clang diagnostic pop |
| 50 |
|
| 51 |
- (GRPCProtoCall *)RPCToMethod:(NSString *)method |
| 52 |
requestsWriter:(GRXWriter *)requestsWriter |
| 53 |
responseClass:(Class)responseClass |
| 54 |
responsesWriteable:(id<GRXWriteable>)responsesWriteable { |
| 55 |
Ivar hostIvar = class_getInstanceVariable([ProtoService class], "_host"); |
| 56 |
Ivar packageNameIvar = class_getInstanceVariable([ProtoService class], "_packageName"); |
| 57 |
Ivar serviceNameIvar = class_getInstanceVariable([ProtoService class], "_serviceName"); |
| 58 |
NSString *host = object_getIvar(self, hostIvar); |
| 59 |
NSString *packageName = object_getIvar(self, packageNameIvar); |
| 60 |
NSString *serviceName = object_getIvar(self, serviceNameIvar); |
| 61 |
|
| 62 |
GRPCProtoMethod *methodName = [[GRPCProtoMethod alloc] initWithPackage:packageName |
| 63 |
service:serviceName |
| 64 |
method:method]; |
| 65 |
return [[GRPCProtoCall alloc] initWithHost:host |
| 66 |
method:methodName |
| 67 |
requestsWriter:requestsWriter |
| 68 |
responseClass:responseClass |
| 69 |
responsesWriteable:responsesWriteable]; |
| 70 |
} |
| 71 |
|
| 72 |
@end |