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#import "InterfaceController.h"
19
20#if USE_FRAMEWORKS
21#import <RemoteTest/Messages.pbobjc.h>
22#import <RemoteTest/Test.pbrpc.h>
23#else
24#import "src/objective-c/examples/RemoteTestClient/Messages.pbobjc.h"
25#import "src/objective-c/examples/RemoteTestClient/Test.pbrpc.h"
26#endif
27#import <GRPCClient/GRPCCallOptions.h>
28#import <ProtoRPC/ProtoRPC.h>
29
30@interface InterfaceController () <GRPCProtoResponseHandler>
31
32@end
33
34@implementation InterfaceController {
35  GRPCCallOptions *_options;
36  RMTTestService *_service;
37}
38
39- (void)awakeWithContext:(id)context {
40  [super awakeWithContext:context];
41
42  // Configure interface objects here.
43
44  GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
45  _options = options;
46
47  _service = [[RMTTestService alloc] initWithHost:@"grpc-test.sandbox.googleapis.com"
48                                      callOptions:_options];
49}
50
51- (IBAction)makeCall {
52  RMTSimpleRequest *request = [RMTSimpleRequest message];
53  request.responseSize = 100;
54  GRPCUnaryProtoCall *call = [_service unaryCallWithMessage:request
55                                            responseHandler:self
56                                                callOptions:nil];
57  [call start];
58}
59
60- (void)didReceiveProtoMessage:(GPBMessage *)message {
61  NSLog(@"%@", [message data]);
62}
63
64- (dispatch_queue_t)dispatchQueue {
65  return dispatch_get_main_queue();
66}
67
68@end
69