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

Add --KVS option for examples/platform/linux in order to specify wher… #14832

Merged
merged 1 commit into from
Feb 7, 2022
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
12 changes: 12 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ int ChipLinuxAppInit(int argc, char ** argv)
err = Platform::MemoryInit();
SuccessOrExit(err);

#ifdef CHIP_CONFIG_KVS_PATH
if (LinuxDeviceOptions::GetInstance().KVS == nullptr)
{
err = DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH);
}
else
{
err = DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(LinuxDeviceOptions::GetInstance().KVS);
}
SuccessOrExit(err);
#endif

err = DeviceLayer::PlatformMgr().InitChipStack();
SuccessOrExit(err);

Expand Down
11 changes: 10 additions & 1 deletion examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum
kDeviceOption_SecuredCommissionerPort = 0x100b,
kDeviceOption_UnsecuredCommissionerPort = 0x100c,
kDeviceOption_Command = 0x100d,
kDeviceOption_PICS = 0x100e
kDeviceOption_PICS = 0x100e,
kDeviceOption_KVS = 0x100f
};

constexpr unsigned kAppUsageLength = 64;
Expand All @@ -74,6 +75,7 @@ OptionDef sDeviceOptionDefs[] = {
{ "unsecured-commissioner-port", kArgumentRequired, kDeviceOption_UnsecuredCommissionerPort },
{ "command", kArgumentRequired, kDeviceOption_Command },
{ "PICS", kArgumentRequired, kDeviceOption_PICS },
{ "KVS", kArgumentRequired, kDeviceOption_KVS },
{}
};

Expand Down Expand Up @@ -129,6 +131,9 @@ const char * sDeviceOptionHelp =
"\n"
" --PICS <filepath>\n"
" A file containing PICS items.\n"
"\n"
" --KVS <filepath>\n"
" A file to store Key Value Store items.\n"
"\n";

bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
Expand Down Expand Up @@ -213,6 +218,10 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
LinuxDeviceOptions::GetInstance().PICS = aValue;
break;

case kDeviceOption_KVS:
LinuxDeviceOptions::GetInstance().KVS = aValue;
break;

default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct LinuxDeviceOptions
uint32_t unsecuredCommissionerPort = CHIP_UDC_PORT;
const char * command = nullptr;
const char * PICS = nullptr;
const char * KVS = nullptr;

static LinuxDeviceOptions & GetInstance();
};
Expand Down
3 changes: 0 additions & 3 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def reboot(self, discriminator):

def factoryReset(self):
storage = '/tmp/chip_kvs'
if platform.system() == 'Darwin':
storage = str(Path.home()) + '/Documents/chip.store'

if os.path.exists(storage):
os.unlink(storage)

Expand Down
7 changes: 0 additions & 7 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
// handler.
SetAttributePersistenceProvider(&mAttributePersister);

#if CHIP_DEVICE_LAYER_TARGET_DARWIN
err = DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init("chip.store");
SuccessOrExit(err);
#elif CHIP_DEVICE_LAYER_TARGET_LINUX
DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH);
#endif

InitDataModelHandler(&mExchangeMgr);

err = mFabrics.Init(&mDeviceStorage);
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Darwin/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@
// TODO - Fine tune MRP default parameters for Darwin platform
#define CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL (15000)
#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32)

#ifndef CHIP_CONFIG_KVS_PATH
#define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs"
#endif // CHIP_CONFIG_KVS_PATH
2 changes: 1 addition & 1 deletion src/platform/Darwin/KeyValueStoreManagerImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context key:(n

url = [NSURL URLWithString:[NSString stringWithUTF8String:fileName] relativeToURL:documentsDirectory];
} else {
url = [NSURL URLWithString:[NSString stringWithUTF8String:fileName]];
url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:fileName]];
}
ReturnErrorCodeIf(url == nullptr, CHIP_ERROR_NO_MEMORY);

Expand Down
2 changes: 1 addition & 1 deletion src/platform/Linux/KeyValueStoreManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class KeyValueStoreManagerImpl : public KeyValueStoreManager
* @brief
* Initalize the KVS, must be called before using.
*/
void Init(const char * file) { mStorage.Init(file); }
CHIP_ERROR Init(const char * file) { return mStorage.Init(file); }

CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0);
CHIP_ERROR _Delete(const char * key);
Expand Down