diff --git a/examples/chip-tool/commands/common/Commands.cpp b/examples/chip-tool/commands/common/Commands.cpp index c2f49c236738b5..bbea6c8dccb4f8 100644 --- a/examples/chip-tool/commands/common/Commands.cpp +++ b/examples/chip-tool/commands/common/Commands.cpp @@ -290,6 +290,10 @@ CHIP_ERROR Commands::RunCommand(int argc, char ** argv, bool interactive, } chip::Logging::SetLogFilter(mStorage.GetLoggingLevel()); + + std::string storageDirectory = mStorage.GetDirectory(); + std::string platformKVS = storageDirectory + "/chip_tool_kvs"; + chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(platformKVS.c_str()); #endif // CONFIG_USE_LOCAL_STORAGE return command->Run(); diff --git a/src/controller/ExamplePersistentStorage.cpp b/src/controller/ExamplePersistentStorage.cpp index b98b682141b244..77e54549258919 100644 --- a/src/controller/ExamplePersistentStorage.cpp +++ b/src/controller/ExamplePersistentStorage.cpp @@ -39,7 +39,7 @@ constexpr const char kLocalNodeIdKey[] = "LocalNodeId"; constexpr const char kCommissionerCATsKey[] = "CommissionerCATs"; constexpr LogCategory kDefaultLoggingLevel = kLogCategory_Automation; -std::string GetFilename(const char * directory, const char * name) +const char * GetUsedDirectory(const char * directory) { const char * dir = directory; @@ -53,6 +53,13 @@ std::string GetFilename(const char * directory, const char * name) dir = "/tmp"; } + return dir; +} + +std::string GetFilename(const char * directory, const char * name) +{ + const char * dir = GetUsedDirectory(directory); + if (name == nullptr) { return std::string(dir) + "/chip_tool_config.ini"; @@ -182,6 +189,11 @@ CHIP_ERROR PersistentStorage::SyncClearAll() return CommitConfig(mDirectory, mName); } +const char * PersistentStorage::GetDirectory() const +{ + return GetUsedDirectory(mDirectory); +} + CHIP_ERROR PersistentStorage::CommitConfig(const char * directory, const char * name) { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/controller/ExamplePersistentStorage.h b/src/controller/ExamplePersistentStorage.h index 9323c1de501b04..685bcfdd4ae6d9 100644 --- a/src/controller/ExamplePersistentStorage.h +++ b/src/controller/ExamplePersistentStorage.h @@ -65,6 +65,9 @@ class PersistentStorage : public chip::PersistentStorageDelegate // Clear all of the persistent storage for running session. CHIP_ERROR SyncClearAll(); + // Get the directory actually being used for the storage. + const char * GetDirectory() const; + private: CHIP_ERROR CommitConfig(const char * directory, const char * name); inipp::Ini mConfig;