Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chip-tool-darwin] Add a method to configure the path of the kvs to a… #16005

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -221,6 +224,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 @@ -565,6 +575,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