|
31 | 31 | #import "MTRDeviceControllerLocalTestStorage.h"
|
32 | 32 | #import "MTRDeviceControllerStartupParams.h"
|
33 | 33 | #import "MTRDeviceControllerStartupParams_Internal.h"
|
34 |
| -#import "MTRDeviceControllerXPCParameters.h" |
35 | 34 | #import "MTRDeviceController_Concrete.h"
|
36 |
| -#import "MTRDeviceController_XPC.h" |
37 |
| -#import "MTRDeviceController_XPC_Internal.h" |
38 | 35 | #import "MTRDevice_Concrete.h"
|
39 | 36 | #import "MTRDevice_Internal.h"
|
40 | 37 | #import "MTRError_Internal.h"
|
@@ -148,49 +145,22 @@ @implementation MTRDeviceController_Concrete {
|
148 | 145 | - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
|
149 | 146 | error:(NSError * __autoreleasing *)error
|
150 | 147 | {
|
151 |
| - /// IF YOU ARE ALARMED BY TYPES: You are right to be alarmed, but do not panic. |
152 |
| - /// _ORDER MATTERS HERE:_ XPC parameters are a subclass of `MTRDeviceControllerParameters` |
153 |
| - /// because of the enormous overlap of params. |
154 |
| - if ([parameters isKindOfClass:MTRDeviceControllerXPCParameters.class]) { |
155 |
| - if ([parameters isKindOfClass:MTRDeviceControllerMachServiceXPCParameters.class]) { |
156 |
| - MTRDeviceControllerMachServiceXPCParameters * xpcParameters = (MTRDeviceControllerMachServiceXPCParameters *) parameters; |
157 |
| - MTR_LOG_DEBUG("%s: got XPC parameters, getting XPC device controller", __PRETTY_FUNCTION__); |
158 |
| - |
159 |
| - NSString * machServiceName = xpcParameters.machServiceName; |
160 |
| - MTR_LOG_DEBUG("%s: machServiceName %@", __PRETTY_FUNCTION__, machServiceName); |
161 |
| - |
162 |
| - MTRDeviceController * xpcDeviceController = [[MTRDeviceController_XPC alloc] initWithMachServiceName:machServiceName options:xpcParameters.connectionOptions]; |
163 |
| - |
164 |
| - /// Being of sound mind, I willfully and voluntarily make this static cast. |
165 |
| - return static_cast<MTRDeviceController_Concrete *>(xpcDeviceController); |
166 |
| - } else { |
167 |
| - MTR_LOG_ERROR("%s: unrecognized XPC parameters class %@", __PRETTY_FUNCTION__, NSStringFromClass(parameters.class)); |
168 |
| - |
169 |
| - // TODO: there's probably a more appropriate error here. |
170 |
| - if (error) { |
171 |
| - *error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_NOT_IMPLEMENTED]; |
172 |
| - } |
173 |
| - |
174 |
| - return nil; |
175 |
| - } |
176 |
| - } else if ([parameters isKindOfClass:MTRDeviceControllerParameters.class]) { |
177 |
| - MTR_LOG_DEBUG("%s: got standard parameters, getting standard device controller from factory", __PRETTY_FUNCTION__); |
178 |
| - auto * controllerParameters = static_cast<MTRDeviceControllerParameters *>(parameters); |
179 |
| - |
180 |
| - // Start us up normally. MTRDeviceControllerFactory will auto-start in per-controller-storage mode if necessary. |
181 |
| - MTRDeviceControllerFactory * factory = MTRDeviceControllerFactory.sharedInstance; |
182 |
| - id controller = [factory initializeController:self |
183 |
| - withParameters:controllerParameters |
184 |
| - error:error]; |
185 |
| - return controller; |
186 |
| - } else { |
187 |
| - // way out of our league |
188 |
| - MTR_LOG_ERROR("Unsupported type of MTRDeviceControllerAbstractParameters: %@", parameters); |
| 148 | + if (![parameters isKindOfClass:MTRDeviceControllerParameters.class]) { |
| 149 | + MTR_LOG_ERROR("Expected MTRDeviceControllerParameters but got: %@", parameters); |
189 | 150 | if (error) {
|
190 | 151 | *error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT];
|
191 | 152 | }
|
192 | 153 | return nil;
|
193 | 154 | }
|
| 155 | + |
| 156 | + auto * controllerParameters = static_cast<MTRDeviceControllerParameters *>(parameters); |
| 157 | + |
| 158 | + // Start us up normally. MTRDeviceControllerFactory will auto-start in per-controller-storage mode if necessary. |
| 159 | + MTRDeviceControllerFactory * factory = MTRDeviceControllerFactory.sharedInstance; |
| 160 | + id controller = [factory initializeController:self |
| 161 | + withParameters:controllerParameters |
| 162 | + error:error]; |
| 163 | + return controller; |
194 | 164 | }
|
195 | 165 |
|
196 | 166 | - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
|
|
0 commit comments