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

[darwin-framework-tool] [darwin-framework-tool] Add an optional parameter to the storage view command to only show the entries for a given commissioner #36244

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 @@ -30,6 +30,7 @@
inline constexpr char kIdentityAlpha[] = "alpha";
inline constexpr char kIdentityBeta[] = "beta";
inline constexpr char kIdentityGamma[] = "gamma";
inline constexpr char kControllerIdPrefix[] = "8DCADB14-AF1F-45D0-B084-00000000000";

class CHIPCommandBridge : public Command {
public:
Expand Down Expand Up @@ -69,6 +70,8 @@ class CHIPCommandBridge : public Command {

static OTAProviderDelegate * mOTADelegate;

static NSNumber * GetCommissionerFabricId(const char * identity);

protected:
// Will be called in a setting in which it's safe to touch the CHIP
// stack. The rules for Run() are as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
std::string commissionerName = mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha;
for (size_t i = 0; i < ArraySize(identities); ++i) {
__auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @"8DCADB14-AF1F-45D0-B084-00000000000", @(i)];
__auto_type * fabricId = GetCommissionerFabricId(identities[i]);
__auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @(kControllerIdPrefix), fabricId];
__auto_type * controllerId = [[NSUUID alloc] initWithUUIDString:uuidString];
__auto_type * vendorId = @(mCommissionerVendorId.ValueOr(chip::VendorId::TestVendor1));
__auto_type * fabricId = @(i + 1);
__auto_type * nodeId = @(chip::kTestControllerNodeId);

if (commissionerName.compare(identities[i]) == 0 && mCommissionerNodeId.HasValue()) {
Expand Down Expand Up @@ -218,7 +218,7 @@
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
std::string commissionerName = mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha;
for (size_t i = 0; i < ArraySize(identities); ++i) {
__auto_type * fabricId = @(i + 1);
__auto_type * fabricId = GetCommissionerFabricId(identities[i]);
__auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithIPK:certificateIssuer.ipk
fabricID:fabricId
nocSigner:certificateIssuer.signingKey];
Expand Down Expand Up @@ -264,14 +264,19 @@

NSNumber * CHIPCommandBridge::CurrentCommissionerFabricId()
{
if (mCurrentIdentity.compare(kIdentityAlpha) == 0) {
return GetCommissionerFabricId(mCurrentIdentity.c_str());
}

NSNumber * CHIPCommandBridge::GetCommissionerFabricId(const char * identity)
{
if (strcmp(identity, kIdentityAlpha) == 0) {
return @(1);
} else if (mCurrentIdentity.compare(kIdentityBeta) == 0) {
} else if (strcmp(identity, kIdentityBeta) == 0) {
return @(2);
} else if (mCurrentIdentity.compare(kIdentityGamma) == 0) {
} else if (strcmp(identity, kIdentityGamma) == 0) {
return @(3);
} else {
ChipLogError(chipTool, "Unknown commissioner name: %s. Supported names are [%s, %s, %s]", mCurrentIdentity.c_str(), kIdentityAlpha,
ChipLogError(chipTool, "Unknown commissioner name: %s. Supported names are [%s, %s, %s]", identity, kIdentityAlpha,
kIdentityBeta, kIdentityGamma);
chipDie();
}
Expand Down
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[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;
}
Loading