Skip to content

Commit

Permalink
[darwin-framework-tool] Add an optional parameter to the storage view…
Browse files Browse the repository at this point in the history
… command to only show the entries for a given commissioner
  • Loading branch information
vivien-apple committed Oct 25, 2024
1 parent fb9e85c commit 65fb533
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern NSString * const kDarwinFrameworkToolControllerDomain;

- (NSData *)valueForKey:(NSString *)key;
- (void)storeValue:(NSData *)value forKey:key;
- (void)print;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ - (void)storeValue:(NSData *)value forKey:key
self.storage[controllerKey] = value;
}

- (void)print
{
NSLog(@"%@ (%@)", kDarwinFrameworkToolControllerDomain, _keyScopingPrefix);
for (NSString * controllerKey in self.storage) {
if (![self _isControllerScopedKey:controllerKey]) {
continue;
}

__auto_type * key = [self _controllerScopedKeyToKey:controllerKey];
__auto_type * data = [self.storage objectForKeyedSubscript:controllerKey];
NSLog(@" * %@: %@", key, data);
}
}

- (NSString *)_keyToControllerScopedKey:(NSString *)key
{
return [NSString stringWithFormat:@"%@%@", _keyScopingPrefix, key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ class StorageClearAll : public Command
class StorageViewAll : public Command
{
public:
StorageViewAll() : Command("view-all") {}
StorageViewAll() : Command("view")
{
AddArgument("commissioner-name", &mCommissionerName,
"If specified, only the keys associated with the given commissioner will be displayed. Valid options are: "
"‘alpha’, ‘beta’, ‘gamma’.");
}

CHIP_ERROR Run() override;

private:
chip::Optional<char *> mCommissionerName;
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,22 @@

CHIP_ERROR StorageViewAll::Run()
{
__auto_type * domains = GetDomains();
for (NSString * domain in domains) {
__auto_type * storage = [[PreferencesStorage alloc] initWithDomain:domain];
[storage print];
if (!mCommissionerName.HasValue()) {
__auto_type * domains = GetDomains();
for (NSString * domain in domains) {
__auto_type * storage = [[PreferencesStorage alloc] initWithDomain:domain];
[storage print];
}

return CHIP_NO_ERROR;
}

const char * commissionerName = mCommissionerName.Value();
__auto_type * fabricId = CHIPCommandBridge::GetCommissionerFabricId(commissionerName);
__auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @(kControllerIdPrefix), fabricId];
__auto_type * controllerId = [[NSUUID alloc] initWithUUIDString:uuidString];
__auto_type * storage = [[ControllerStorage alloc] initWithControllerID:controllerId];
[storage print];

return CHIP_NO_ERROR;
}

0 comments on commit 65fb533

Please sign in to comment.