Debian Codegraph @

examples/objective-c/helloworld/main.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 <UIKit/UIKit.h>
20 #import "AppDelegate.h"
21
22 #import <GRPCClient/GRPCCall+ChannelArg.h>
23 #import <GRPCClient/GRPCCall+Tests.h>
24 #import <GRPCClient/GRPCTransport.h>
25 #if COCOAPODS
26 #import <HelloWorld/Helloworld.pbrpc.h>
27 #else
28 #import "examples/protos/Helloworld.pbrpc.h"
29 #endif
30
31 static NSString * const kHostAddress = @"localhost:50051";
32
33 @interface HLWResponseHandler : NSObject<GRPCProtoResponseHandler>
34
35 @end
36
37 // A response handler object dispatching messages to main queue
38 @implementation HLWResponseHandler
39
40 - (dispatch_queue_t)dispatchQueue {
41 return dispatch_get_main_queue();
42 }
43
44 - (void)didReceiveProtoMessage:(GPBMessage *)message {
45 NSLog(@"%@", message);
46 }
47
48 @end
49
50 int main(int argc, char * argv[]) {
51 @autoreleasepool {
52 HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress];
53
54 HLWHelloRequest *request = [HLWHelloRequest message];
55 request.name = @"Objective-C";
56
57 GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
58 // this example does not use TLS (secure channel); use insecure channel instead
59 options.transport = GRPCDefaultTransportImplList.core_insecure;
60 options.userAgentPrefix = @"HelloWorld/1.0";
61
62 [[client sayHelloWithMessage:request
63 responseHandler:[[HLWResponseHandler alloc] init]
64 callOptions:options] start];
65
66 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
67 }
68 }