Debian Codegraph @

src/objective-c/ProtoRPC/ProtoService.m

raw
1 /*
2 *
3 * Copyright 2015 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 "ProtoService.h"
20
21 #import <GRPCClient/GRPCCall.h>
22 #import <RxLibrary/GRXWriteable.h>
23 #import <RxLibrary/GRXWriter.h>
24
25 #import "ProtoMethod.h"
26 #import "ProtoRPC.h"
27
28 #pragma clang diagnostic push
29 #pragma clang diagnostic ignored "-Wdeprecated-implementations"
30 @implementation ProtoService {
31 #pragma clang diagnostic pop
32
33 GRPCCallOptions *_callOptions;
34 NSString *_host;
35 NSString *_packageName;
36 NSString *_serviceName;
37 }
38
39 #pragma clang diagnostic push
40 #pragma clang diagnostic ignored "-Wnonnull"
41 // Do not call the default init method
42 - (instancetype)init {
43 [NSException raise:NSGenericException format:@"Do not call init method of ProtoService"];
44 return [self initWithHost:nil packageName:nil serviceName:nil callOptions:nil];
45 }
46 #pragma clang diagnostic pop
47
48 // Designated initializer
49 - (instancetype)initWithHost:(NSString *)host
50 packageName:(NSString *)packageName
51 serviceName:(NSString *)serviceName
52 callOptions:(GRPCCallOptions *)callOptions {
53 NSAssert(host.length != 0 && packageName.length != 0 && serviceName.length != 0,
54 @"Invalid parameter.");
55 if (host.length == 0 || packageName.length == 0 || serviceName.length == 0) {
56 return nil;
57 }
58 if ((self = [super init])) {
59 _host = [host copy];
60 _packageName = [packageName copy];
61 _serviceName = [serviceName copy];
62 _callOptions = [callOptions copy];
63 }
64 return self;
65 }
66
67 - (GRPCUnaryProtoCall *)RPCToMethod:(NSString *)method
68 message:(id)message
69 responseHandler:(id<GRPCProtoResponseHandler>)handler
70 callOptions:(GRPCCallOptions *)callOptions
71 responseClass:(Class)responseClass {
72 GRPCProtoMethod *methodName = [[GRPCProtoMethod alloc] initWithPackage:_packageName
73 service:_serviceName
74 method:method];
75 GRPCRequestOptions *requestOptions =
76 [[GRPCRequestOptions alloc] initWithHost:_host
77 path:methodName.HTTPPath
78 safety:GRPCCallSafetyDefault];
79 return [[GRPCUnaryProtoCall alloc] initWithRequestOptions:requestOptions
80 message:message
81 responseHandler:handler
82 callOptions:callOptions ?: _callOptions
83 responseClass:responseClass];
84 }
85
86 - (GRPCStreamingProtoCall *)RPCToMethod:(NSString *)method
87 responseHandler:(id<GRPCProtoResponseHandler>)handler
88 callOptions:(GRPCCallOptions *)callOptions
89 responseClass:(Class)responseClass {
90 GRPCProtoMethod *methodName = [[GRPCProtoMethod alloc] initWithPackage:_packageName
91 service:_serviceName
92 method:method];
93 GRPCRequestOptions *requestOptions =
94 [[GRPCRequestOptions alloc] initWithHost:_host
95 path:methodName.HTTPPath
96 safety:GRPCCallSafetyDefault];
97 return [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions
98 responseHandler:handler
99 callOptions:callOptions ?: _callOptions
100 responseClass:responseClass];
101 }
102
103 @end
104
105 @implementation GRPCProtoService
106
107 @end