|
31 | 31 | #import "DeviceDelegate.h"
|
32 | 32 | #include "MTRError_Utils.h"
|
33 | 33 |
|
| 34 | +#include "xpc/XPCServerRegistry.h" |
| 35 | + |
34 | 36 | #include <map>
|
35 | 37 | #include <string>
|
36 | 38 |
|
|
45 | 47 | bool CHIPCommandBridge::sUseSharedStorage = true;
|
46 | 48 | constexpr char kTrustStorePathVariable[] = "PAA_TRUST_STORE_PATH";
|
47 | 49 |
|
| 50 | +namespace { |
| 51 | +NSString * ToNSString(const chip::Optional<chip::app::DataModel::Nullable<char *>> & string) |
| 52 | +{ |
| 53 | + if (!string.HasValue() && string.Value().IsNull()) { |
| 54 | + return nil; |
| 55 | + } |
| 56 | + |
| 57 | + return @(string.Value().Value()); |
| 58 | +} |
| 59 | +} |
| 60 | + |
48 | 61 | CHIP_ERROR CHIPCommandBridge::Run()
|
49 | 62 | {
|
50 | 63 | // In interactive mode, we want to avoid memory accumulating in the main autorelease pool,
|
|
143 | 156 | productAttestationAuthorityCertificates = nil;
|
144 | 157 | }
|
145 | 158 |
|
| 159 | + [[XPCServerRegistry sharedInstance] start]; |
| 160 | + |
146 | 161 | sUseSharedStorage = mCommissionerSharedStorage.ValueOr(false);
|
147 | 162 | if (sUseSharedStorage) {
|
148 | 163 | return SetUpStackWithSharedStorage(productAttestationAuthorityCertificates);
|
|
202 | 217 |
|
203 | 218 | params.productAttestationAuthorityCertificates = productAttestationAuthorityCertificates;
|
204 | 219 |
|
205 |
| - __auto_type * controller = [[MTRDeviceController alloc] initWithParameters:params error:&error]; |
| 220 | + MTRDeviceController * controller = nil; |
| 221 | + if (mUseXPC.HasValue()) { |
| 222 | + __auto_type * identifier = uuidString; |
| 223 | + controller = [[XPCServerRegistry sharedInstance] createController:identifier serviceName:ToNSString(mUseXPC) params:params error:&error]; |
| 224 | + } else { |
| 225 | + controller = [[MTRDeviceController alloc] initWithParameters:params error:&error]; |
| 226 | + } |
206 | 227 | VerifyOrReturnError(nil != controller, MTRErrorToCHIPErrorCode(error), ChipLogError(chipTool, "Controller startup failure: %@", error));
|
207 | 228 | mControllers[identities[i]] = controller;
|
208 | 229 | }
|
|
237 | 258 | params.nodeId = @(mCommissionerNodeId.Value());
|
238 | 259 | }
|
239 | 260 |
|
240 |
| - // We're not sure whether we're creating a new fabric or using an existing one, so just try both. |
241 |
| - auto controller = [factory createControllerOnExistingFabric:params error:&error]; |
242 |
| - if (controller == nil) { |
243 |
| - // Maybe we didn't have this fabric yet. |
244 |
| - params.vendorID = @(mCommissionerVendorId.ValueOr(chip::VendorId::TestVendor1)); |
245 |
| - controller = [factory createControllerOnNewFabric:params error:&error]; |
| 261 | + MTRDeviceController * controller = nil; |
| 262 | + if (mUseXPC.HasValue()) { |
| 263 | + __auto_type * identifier = @(identities[i]); |
| 264 | + controller = [[XPCServerRegistry sharedInstance] createController:identifier serviceName:ToNSString(mUseXPC) params:params error:&error]; |
| 265 | + } else { |
| 266 | + // We're not sure whether we're creating a new fabric or using an existing one, so just try both. |
| 267 | + controller = [factory createControllerOnExistingFabric:params error:&error]; |
| 268 | + if (controller == nil) { |
| 269 | + // Maybe we didn't have this fabric yet. |
| 270 | + params.vendorID = @(mCommissionerVendorId.ValueOr(chip::VendorId::TestVendor1)); |
| 271 | + controller = [factory createControllerOnNewFabric:params error:&error]; |
| 272 | + } |
246 | 273 | }
|
247 | 274 | VerifyOrReturnError(nil != controller, MTRErrorToCHIPErrorCode(error), ChipLogError(chipTool, "Controller startup failure: %@", error));
|
248 | 275 | mControllers[identities[i]] = controller;
|
|
256 | 283 | if (IsInteractive()) {
|
257 | 284 | return;
|
258 | 285 | }
|
| 286 | + |
| 287 | + [[XPCServerRegistry sharedInstance] stop]; |
259 | 288 | ShutdownCommissioner();
|
260 | 289 | }
|
261 | 290 |
|
|
0 commit comments