Skip to content

Commit

Permalink
Change chip-tool to put its platform KVS in its storage directory.
Browse files Browse the repository at this point in the history
And also name it chip_tool_kvs, not chip_kvs.  This should avoid chip-tool
stomping on the KVS of server-side apps.
  • Loading branch information
bzbarsky-apple committed Sep 8, 2023
1 parent ce66c4d commit 02e4741
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/controller/ExamplePersistentStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/controller/ExamplePersistentStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> mConfig;
Expand Down

0 comments on commit 02e4741

Please sign in to comment.