Skip to content

Commit

Permalink
[chip-tool-darwin] Add a method to configure the path of the kvs to a…
Browse files Browse the repository at this point in the history
…void conflicts between chip-tool and chip-tool-darwin (#16005)
  • Loading branch information
vivien-apple authored and pull[bot] committed Mar 29, 2022
1 parent 1558ede commit 60acf55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
}

[mController setListenPort:kListenPort];
[mController setKeyValueStoreManagerPath:"/tmp/chip_kvs_darwin"];

[nocSigner createOrLoadKeys:storage];

Expand Down
2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ typedef void (^CHIPDeviceConnectionCallback)(CHIPDevice * _Nullable device, NSEr
*/
- (void)setPairingDelegate:(id<CHIPDevicePairingDelegate>)delegate queue:(dispatch_queue_t)queue;

- (void)setKeyValueStoreManagerPath:(const char *)keyValueStorePath;

/**
* Start the CHIP Stack. Repeated calls to startup without calls to shutdown in between are NO-OPs. Use the isRunning property to
* check if the stack needs to be started up.
Expand Down
15 changes: 15 additions & 0 deletions src/darwin/Framework/CHIP/CHIPDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
static const char * const CHIP_COMMISSIONER_DEVICE_ID_KEY = "com.zigbee.chip.commissioner.device_id";

static NSString * const kErrorMemoryInit = @"Init Memory failure";
static NSString * const kErrorKVSInit = @"Init Key Value Store failure";
static NSString * const kErrorCommissionerInit = @"Init failure while initializing a commissioner";
static NSString * const kErrorOperationalCredentialsInit = @"Init failure while creating operational credentials delegate";
static NSString * const kErrorPairingInit = @"Init failure while creating a pairing delegate";
Expand All @@ -69,6 +70,7 @@ @interface CHIPDeviceController ()
@property (readonly) CHIPP256KeypairBridge keypairBridge;
@property (readonly) chip::NodeId localDeviceId;
@property (readonly) uint16_t listenPort;
@property (readonly) const char * kvsPath;
@end

// TODO Replace Shared Controller with a Controller Factory Singleton
Expand All @@ -91,6 +93,7 @@ - (instancetype)init
CHIP_ERROR errorCode = CHIP_NO_ERROR;

_chipWorkQueue = chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue();
_kvsPath = nullptr;

errorCode = chip::Platform::MemoryInit();
if ([self checkForInitError:(CHIP_NO_ERROR == errorCode) logMsg:kErrorMemoryInit]) {
Expand Down Expand Up @@ -222,6 +225,13 @@ - (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate
commissionerParams.controllerNOC = noc;
commissionerParams.controllerVendorId = vendorId;

if (_kvsPath != nullptr) {
errorCode = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(_kvsPath);
if ([self checkForInitError:(CHIP_NO_ERROR == errorCode) logMsg:kErrorKVSInit]) {
return;
}
}

// TODO Replace Shared Controller with a Controller Factory Singleton
auto & factory = chip::Controller::DeviceControllerFactory::GetInstance();
errorCode = factory.Init(params);
Expand Down Expand Up @@ -566,6 +576,11 @@ - (void)setPairingDelegate:(id<CHIPDevicePairingDelegate>)delegate queue:(dispat
});
}

- (void)setKeyValueStoreManagerPath:(const char *)kvsPath
{
_kvsPath = kvsPath;
}

- (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg
{
if (condition) {
Expand Down

0 comments on commit 60acf55

Please sign in to comment.