Debian Codegraph @

src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.m

raw
1 /*
2 *
3 * Copyright 2018 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 "GRPCCronetChannelFactory.h"
20
21 #import "../ChannelArgsUtil.h"
22 #import "../GRPCChannel.h"
23
24 #import <Cronet/Cronet.h>
25 #include <grpc/grpc_cronet.h>
26
27 @implementation GRPCCronetChannelFactory {
28 stream_engine *_cronetEngine;
29 }
30
31 + (instancetype)sharedInstance {
32 static GRPCCronetChannelFactory *instance;
33 static dispatch_once_t onceToken;
34 dispatch_once(&onceToken, ^{
35 instance = [[self alloc] initWithEngine:[Cronet getGlobalEngine]];
36 });
37 return instance;
38 }
39
40 - (instancetype)initWithEngine:(stream_engine *)engine {
41 NSAssert(engine != NULL, @"Cronet engine cannot be empty.");
42 if (!engine) {
43 return nil;
44 }
45 if ((self = [super init])) {
46 _cronetEngine = engine;
47 }
48 return self;
49 }
50
51 - (grpc_channel *)createChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)args {
52 grpc_channel_args *channelArgs = GRPCBuildChannelArgs(args);
53 grpc_channel *unmanagedChannel =
54 grpc_cronet_secure_channel_create(_cronetEngine, host.UTF8String, channelArgs, NULL);
55 GRPCFreeChannelArgs(channelArgs);
56 return unmanagedChannel;
57 }
58
59 @end