Debian Codegraph @

src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m

raw
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 "GRPCCoreFactory.h"
20
21 #import <GRPCClient/GRPCTransport.h>
22
23 #import "GRPCCallInternal.h"
24 #import "GRPCInsecureChannelFactory.h"
25 #import "GRPCSecureChannelFactory.h"
26
27 static GRPCCoreSecureFactory *gGRPCCoreSecureFactory = nil;
28 static GRPCCoreInsecureFactory *gGRPCCoreInsecureFactory = nil;
29 static dispatch_once_t gInitGRPCCoreSecureFactory;
30 static dispatch_once_t gInitGRPCCoreInsecureFactory;
31
32 @implementation GRPCCoreSecureFactory
33
34 + (instancetype)sharedInstance {
35 dispatch_once(&gInitGRPCCoreSecureFactory, ^{
36 gGRPCCoreSecureFactory = [[GRPCCoreSecureFactory alloc] init];
37 });
38 return gGRPCCoreSecureFactory;
39 }
40
41 + (void)load {
42 [[GRPCTransportRegistry sharedInstance]
43 registerTransportWithID:GRPCDefaultTransportImplList.core_secure
44 factory:[self sharedInstance]];
45 }
46
47 - (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager {
48 return [[GRPCCall2Internal alloc] initWithTransportManager:transportManager];
49 }
50
51 - (NSArray<id<GRPCInterceptorFactory>> *)transportInterceptorFactories {
52 return nil;
53 }
54
55 - (id<GRPCChannelFactory>)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions {
56 NSError *error;
57 id<GRPCChannelFactory> factory =
58 [GRPCSecureChannelFactory factoryWithPEMRootCertificates:callOptions.PEMRootCertificates
59 privateKey:callOptions.PEMPrivateKey
60 certChain:callOptions.PEMCertificateChain
61 error:&error];
62 if (error != nil) {
63 NSLog(@"Unable to create secure channel factory");
64 return nil;
65 }
66 return factory;
67 }
68
69 @end
70
71 @implementation GRPCCoreInsecureFactory
72
73 + (instancetype)sharedInstance {
74 dispatch_once(&gInitGRPCCoreInsecureFactory, ^{
75 gGRPCCoreInsecureFactory = [[GRPCCoreInsecureFactory alloc] init];
76 });
77 return gGRPCCoreInsecureFactory;
78 }
79
80 + (void)load {
81 [[GRPCTransportRegistry sharedInstance]
82 registerTransportWithID:GRPCDefaultTransportImplList.core_insecure
83 factory:[self sharedInstance]];
84 }
85
86 - (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager {
87 return [[GRPCCall2Internal alloc] initWithTransportManager:transportManager];
88 }
89
90 - (NSArray<id<GRPCInterceptorFactory>> *)transportInterceptorFactories {
91 return nil;
92 }
93
94 - (id<GRPCChannelFactory>)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions {
95 return [GRPCInsecureChannelFactory sharedInstance];
96 }
97
98 @end