Skip to content

Commit

Permalink
Hopefully final rename
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Jul 2, 2022
1 parent 7cc10ae commit 8d84f81
Show file tree
Hide file tree
Showing 28 changed files with 278 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NSString * const kCHIPToolDefaultsDomain = @"com.apple.chiptool";

id CHIPGetDomainValueForKey(NSString * domain, NSString * key)
id MTRGetDomainValueForKey(NSString * domain, NSString * key)
{
id value = (id) CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef) key, (CFStringRef) domain));
if (value) {
Expand All @@ -13,13 +13,13 @@ id CHIPGetDomainValueForKey(NSString * domain, NSString * key)
return nil;
}

BOOL CHIPSetDomainValueForKey(NSString * domain, NSString * key, id value)
BOOL MTRSetDomainValueForKey(NSString * domain, NSString * key, id value)
{
CFPreferencesSetAppValue((CFStringRef) key, (__bridge CFPropertyListRef _Nullable)(value), (CFStringRef) domain);
return CFPreferencesAppSynchronize((CFStringRef) domain) == true;
}

BOOL CHIPRemoveDomainValueForKey(NSString * domain, NSString * key)
BOOL MTRRemoveDomainValueForKey(NSString * domain, NSString * key)
{
CFPreferencesSetAppValue((CFStringRef) key, nullptr, (CFStringRef) domain);
return CFPreferencesAppSynchronize((CFStringRef) domain) == true;
Expand All @@ -42,7 +42,7 @@ BOOL CHIPClearAllDomain(NSString * domain)
NSLog(@"Removing keys: %@ %@", allKeys, domain);
for (id key in allKeys) {
NSLog(@"Removing key: %@", key);
if (!CHIPRemoveDomainValueForKey(domain, (NSString *) key)) {
if (!MTRRemoveDomainValueForKey(domain, (NSString *) key)) {
return NO;
}
}
Expand All @@ -60,7 +60,7 @@ - (BOOL)deleteAllStorage

- (nullable NSData *)storageDataForKey:(NSString *)key
{
NSData * value = CHIPGetDomainValueForKey(kCHIPToolDefaultsDomain, key);
NSData * value = MTRGetDomainValueForKey(kCHIPToolDefaultsDomain, key);
NSLog(@"CHIPPersistentStorageDelegate Get Value for Key: %@, value %@", key, value);
return value;
}
Expand All @@ -72,10 +72,10 @@ - (BOOL)setStorageData:(NSData *)value forKey:(NSString *)key

- (BOOL)removeStorageDataForKey:(NSString *)key
{
if (CHIPGetDomainValueForKey(kCHIPToolDefaultsDomain, key) == nil) {
if (MTRGetDomainValueForKey(kCHIPToolDefaultsDomain, key) == nil) {
return NO;
}
return CHIPRemoveDomainValueForKey(kCHIPToolDefaultsDomain, key);
return MTRRemoveDomainValueForKey(kCHIPToolDefaultsDomain, key);
}

@end
22 changes: 11 additions & 11 deletions examples/darwin-framework-tool/commands/common/MTRError.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
int64_t val;
CHIP_ERROR err = data->Get(val);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV signed integer decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV signed integer decoding failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary dictionaryWithObjectsAndKeys:MTRSignedIntegerValueType, MTRTypeKey, [NSNumber numberWithLongLong:val],
Expand All @@ -112,7 +112,7 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
uint64_t val;
CHIP_ERROR err = data->Get(val);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV unsigned integer decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV unsigned integer decoding failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary dictionaryWithObjectsAndKeys:MTRUnsignedIntegerValueType, MTRTypeKey,
Expand All @@ -122,7 +122,7 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
bool val;
CHIP_ERROR err = data->Get(val);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV boolean decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV boolean decoding failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary
Expand All @@ -138,7 +138,7 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
double val;
err = data->Get(val);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV floating point decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV floating point decoding failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary
Expand All @@ -149,7 +149,7 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
const uint8_t * ptr;
CHIP_ERROR err = data->GetDataPtr(ptr);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV UTF8String decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV UTF8String decoding failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary dictionaryWithObjectsAndKeys:MTRUTF8StringValueType, MTRTypeKey,
Expand All @@ -160,7 +160,7 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
const uint8_t * ptr;
CHIP_ERROR err = data->GetDataPtr(ptr);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV ByteString decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV ByteString decoding failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary dictionaryWithObjectsAndKeys:MTROctetStringValueType, MTRTypeKey,
Expand All @@ -186,15 +186,15 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
chip::TLV::TLVType tlvType;
CHIP_ERROR err = data->EnterContainer(tlvType);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV container entering failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV container entering failed", chip::ErrorStr(err));
return nil;
}
NSMutableArray * array = [[NSMutableArray alloc] init];
while ((err = data->Next()) == CHIP_NO_ERROR) {
chip::TLV::Tag tag = data->GetTag();
id value = NSObjectFromCHIPTLV(data);
if (value == nullptr) {
CHIP_LOG_ERROR("Error when decoding TLV container");
MTR_LOG_ERROR("Error when decoding TLV container");
return nil;
}
NSMutableDictionary * arrayElement = [NSMutableDictionary dictionary];
Expand All @@ -205,18 +205,18 @@ id NSObjectFromCHIPTLV(chip::TLV::TLVReader * data)
[array addObject:arrayElement];
}
if (err != CHIP_END_OF_TLV) {
CHIP_LOG_ERROR("Error(%s): TLV container decoding failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV container decoding failed", chip::ErrorStr(err));
return nil;
}
err = data->ExitContainer(tlvType);
if (err != CHIP_NO_ERROR) {
CHIP_LOG_ERROR("Error(%s): TLV container exiting failed", chip::ErrorStr(err));
MTR_LOG_ERROR("Error(%s): TLV container exiting failed", chip::ErrorStr(err));
return nil;
}
return [NSDictionary dictionaryWithObjectsAndKeys:typeName, MTRTypeKey, array, MTRValueKey, nil];
}
default:
CHIP_LOG_ERROR("Error: Unsupported TLV type for conversion: %u", (unsigned) data->GetType());
MTR_LOG_ERROR("Error: Unsupported TLV type for conversion: %u", (unsigned) data->GetType());
return nil;
}
}
12 changes: 6 additions & 6 deletions examples/darwin-framework-tool/commands/common/MTRLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#import <os/log.h>

#if DEBUG
#define CHIP_LOG_DEBUG(format, ...) os_log(OS_LOG_DEFAULT, format, ##__VA_ARGS__)
#define CHIP_LOG_ERROR(format, ...) os_log(OS_LOG_DEFAULT, format, ##__VA_ARGS__)
#define CHIP_LOG_METHOD_ENTRY() \
#define MTR_LOG_DEBUG(format, ...) os_log(OS_LOG_DEFAULT, format, ##__VA_ARGS__)
#define MTR_LOG_ERROR(format, ...) os_log(OS_LOG_DEFAULT, format, ##__VA_ARGS__)
#define MTR_LOG_METHOD_ENTRY() \
({ os_log(OS_LOG_DEFAULT, "[<%@: %p> %@]", NSStringFromClass([self class]), self, NSStringFromSelector(_cmd)); })

#else
#define CHIP_LOG_DEBUG(...)
#define CHIP_LOG_ERROR(...)
#define CHIP_LOG_METHOD_ENTRY() ({})
#define MTR_LOG_DEBUG(...)
#define MTR_LOG_ERROR(...)
#define MTR_LOG_METHOD_ENTRY() ({})

#endif

Expand Down
28 changes: 14 additions & 14 deletions src/darwin/CHIPTool/CHIPTool/Framework Helpers/DefaultsUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ extern NSString * const kNetworkSSIDDefaultsKey;
extern NSString * const kNetworkPasswordDefaultsKey;
extern NSString * const kFabricIdKey;

MTRDeviceController * _Nullable InitializeCHIP(void);
MTRDeviceController * _Nullable CHIPRestartController(MTRDeviceController * controller);
id _Nullable CHIPGetDomainValueForKey(NSString * domain, NSString * key);
BOOL CHIPSetDomainValueForKey(NSString * domain, NSString * key, id _Nullable value);
void CHIPRemoveDomainValueForKey(NSString * domain, NSString * key);
uint64_t CHIPGetNextAvailableDeviceID(void);
MTRDeviceController * _Nullable InitializeMTR(void);
MTRDeviceController * _Nullable MTRRestartController(MTRDeviceController * controller);
id _Nullable MTRGetDomainValueForKey(NSString * domain, NSString * key);
BOOL MTRSetDomainValueForKey(NSString * domain, NSString * key, id _Nullable value);
void MTRRemoveDomainValueForKey(NSString * domain, NSString * key);
uint64_t MTRGetNextAvailableDeviceID(void);
NSString * KeyForPairedDevice(uint64_t id);
uint64_t CHIPGetLastPairedDeviceId(void);
void CHIPSetNextAvailableDeviceID(uint64_t id);
void CHIPSetDevicePaired(uint64_t id, BOOL paired);
BOOL CHIPIsDevicePaired(uint64_t id);
BOOL CHIPGetConnectedDevice(MTRDeviceConnectionCallback completionHandler);
BOOL CHIPGetConnectedDeviceWithID(uint64_t deviceId, MTRDeviceConnectionCallback completionHandler);
void CHIPUnpairDeviceWithID(uint64_t deviceId);
MTRDevice * _Nullable CHIPGetDeviceBeingCommissioned(void);
uint64_t MTRGetLastPairedDeviceId(void);
void MTRSetNextAvailableDeviceID(uint64_t id);
void MTRSetDevicePaired(uint64_t id, BOOL paired);
BOOL MTRIsDevicePaired(uint64_t id);
BOOL MTRGetConnectedDevice(MTRDeviceConnectionCallback completionHandler);
BOOL MTRGetConnectedDeviceWithID(uint64_t deviceId, MTRDeviceConnectionCallback completionHandler);
void MTRUnpairDeviceWithID(uint64_t deviceId);
MTRDevice * _Nullable MTRGetDeviceBeingCommissioned(void);

@interface CHIPToolPersistentStorageDelegate : NSObject <MTRPersistentStorageDelegate>
- (nullable NSData *)storageDataForKey:(NSString *)key;
Expand Down
62 changes: 31 additions & 31 deletions src/darwin/CHIPTool/CHIPTool/Framework Helpers/DefaultsUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
NSString * const kFabricIdKey = @"fabricId";
NSString * const kDevicePairedKey = @"Paired";

id CHIPGetDomainValueForKey(NSString * domain, NSString * key)
id MTRGetDomainValueForKey(NSString * domain, NSString * key)
{
id value = (id) CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef) key, (CFStringRef) domain));
if (value) {
Expand All @@ -34,24 +34,24 @@ id CHIPGetDomainValueForKey(NSString * domain, NSString * key)
return nil;
}

BOOL CHIPSetDomainValueForKey(NSString * domain, NSString * key, id value)
BOOL MTRSetDomainValueForKey(NSString * domain, NSString * key, id value)
{
CFPreferencesSetAppValue((CFStringRef) key, (__bridge CFPropertyListRef _Nullable)(value), (CFStringRef) domain);
return CFPreferencesAppSynchronize((CFStringRef) domain) == true;
}

void CHIPRemoveDomainValueForKey(NSString * domain, NSString * key)
void MTRRemoveDomainValueForKey(NSString * domain, NSString * key)
{
CFPreferencesSetAppValue((CFStringRef) key, NULL, (CFStringRef) domain);
CFPreferencesAppSynchronize((CFStringRef) domain);
}

uint64_t CHIPGetNextAvailableDeviceID(void)
uint64_t MTRGetNextAvailableDeviceID(void)
{
uint64_t nextAvailableDeviceIdentifier = 1;
NSNumber * value = CHIPGetDomainValueForKey(MTRToolDefaultsDomain, MTRNextAvailableDeviceIDKey);
NSNumber * value = MTRGetDomainValueForKey(MTRToolDefaultsDomain, MTRNextAvailableDeviceIDKey);
if (!value) {
CHIPSetDomainValueForKey(MTRToolDefaultsDomain, MTRNextAvailableDeviceIDKey,
MTRSetDomainValueForKey(MTRToolDefaultsDomain, MTRNextAvailableDeviceIDKey,
[NSNumber numberWithUnsignedLongLong:nextAvailableDeviceIdentifier]);
} else {
nextAvailableDeviceIdentifier = [value unsignedLongLongValue];
Expand All @@ -60,9 +60,9 @@ uint64_t CHIPGetNextAvailableDeviceID(void)
return nextAvailableDeviceIdentifier;
}

void CHIPSetNextAvailableDeviceID(uint64_t id)
void MTRSetNextAvailableDeviceID(uint64_t id)
{
CHIPSetDomainValueForKey(MTRToolDefaultsDomain, MTRNextAvailableDeviceIDKey, [NSNumber numberWithUnsignedLongLong:id]);
MTRSetDomainValueForKey(MTRToolDefaultsDomain, MTRNextAvailableDeviceIDKey, [NSNumber numberWithUnsignedLongLong:id]);
}

static CHIPToolPersistentStorageDelegate * storage = nil;
Expand All @@ -71,7 +71,7 @@ void CHIPSetNextAvailableDeviceID(uint64_t id)

static MTRDeviceController * sController = nil;

MTRDeviceController * InitializeCHIP(void)
MTRDeviceController * InitializeMTR(void)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down Expand Up @@ -120,60 +120,60 @@ void CHIPSetNextAvailableDeviceID(uint64_t id)
return sController;
}

uint64_t CHIPGetLastPairedDeviceId(void)
uint64_t MTRGetLastPairedDeviceId(void)
{
uint64_t deviceId = CHIPGetNextAvailableDeviceID();
uint64_t deviceId = MTRGetNextAvailableDeviceID();
if (deviceId > 1) {
deviceId--;
}
return deviceId;
}

BOOL CHIPGetConnectedDevice(MTRDeviceConnectionCallback completionHandler)
BOOL MTRGetConnectedDevice(MTRDeviceConnectionCallback completionHandler)
{
MTRDeviceController * controller = InitializeCHIP();
MTRDeviceController * controller = InitializeMTR();

// Let's use the last device that was paired
uint64_t deviceId = CHIPGetLastPairedDeviceId();
uint64_t deviceId = MTRGetLastPairedDeviceId();
return [controller getDevice:deviceId queue:dispatch_get_main_queue() completionHandler:completionHandler];
}

MTRDevice * CHIPGetDeviceBeingCommissioned(void)
MTRDevice * MTRGetDeviceBeingCommissioned(void)
{
NSError * error;
MTRDeviceController * controller = InitializeCHIP();
MTRDevice * device = [controller getDeviceBeingCommissioned:CHIPGetLastPairedDeviceId() error:&error];
MTRDeviceController * controller = InitializeMTR();
MTRDevice * device = [controller getDeviceBeingCommissioned:MTRGetLastPairedDeviceId() error:&error];
if (error) {
NSLog(@"Error retrieving device being commissioned for deviceId %llu", CHIPGetLastPairedDeviceId());
NSLog(@"Error retrieving device being commissioned for deviceId %llu", MTRGetLastPairedDeviceId());
return nil;
}
return device;
}

BOOL CHIPGetConnectedDeviceWithID(uint64_t deviceId, MTRDeviceConnectionCallback completionHandler)
BOOL MTRGetConnectedDeviceWithID(uint64_t deviceId, MTRDeviceConnectionCallback completionHandler)
{
MTRDeviceController * controller = InitializeCHIP();
MTRDeviceController * controller = InitializeMTR();

return [controller getDevice:deviceId queue:dispatch_get_main_queue() completionHandler:completionHandler];
}

BOOL CHIPIsDevicePaired(uint64_t deviceId)
BOOL MTRIsDevicePaired(uint64_t deviceId)
{
NSString * PairedString = CHIPGetDomainValueForKey(MTRToolDefaultsDomain, KeyForPairedDevice(deviceId));
NSString * PairedString = MTRGetDomainValueForKey(MTRToolDefaultsDomain, KeyForPairedDevice(deviceId));
return [PairedString boolValue];
}

void CHIPSetDevicePaired(uint64_t deviceId, BOOL paired)
void MTRSetDevicePaired(uint64_t deviceId, BOOL paired)
{
CHIPSetDomainValueForKey(MTRToolDefaultsDomain, KeyForPairedDevice(deviceId), paired ? @"YES" : @"NO");
MTRSetDomainValueForKey(MTRToolDefaultsDomain, KeyForPairedDevice(deviceId), paired ? @"YES" : @"NO");
}

NSString * KeyForPairedDevice(uint64_t deviceId) { return [NSString stringWithFormat:@"%@%llu", kDevicePairedKey, deviceId]; }

void CHIPUnpairDeviceWithID(uint64_t deviceId)
void MTRUnpairDeviceWithID(uint64_t deviceId)
{
CHIPSetDevicePaired(deviceId, NO);
CHIPGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable device, NSError * _Nullable error) {
MTRSetDevicePaired(deviceId, NO);
MTRGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable device, NSError * _Nullable error) {
if (error) {
NSLog(@"Failed to unpair device %llu still removing from CHIPTool. %@", deviceId, error);
return;
Expand Down Expand Up @@ -211,22 +211,22 @@ @implementation CHIPToolPersistentStorageDelegate

- (nullable NSData *)storageDataForKey:(NSString *)key
{
NSData * value = CHIPGetDomainValueForKey(MTRToolDefaultsDomain, key);
NSData * value = MTRGetDomainValueForKey(MTRToolDefaultsDomain, key);
NSLog(@"MTRPersistentStorageDelegate Get Value for Key: %@, value %@", key, value);
return value;
}

- (BOOL)setStorageData:(NSData *)value forKey:(NSString *)key
{
return CHIPSetDomainValueForKey(MTRToolDefaultsDomain, key, value);
return MTRSetDomainValueForKey(MTRToolDefaultsDomain, key, value);
}

- (BOOL)removeStorageDataForKey:(NSString *)key
{
if (CHIPGetDomainValueForKey(MTRToolDefaultsDomain, key) == nil) {
if (MTRGetDomainValueForKey(MTRToolDefaultsDomain, key) == nil) {
return NO;
}
CHIPRemoveDomainValueForKey(MTRToolDefaultsDomain, key);
MTRRemoveDomainValueForKey(MTRToolDefaultsDomain, key);
return YES;
}

Expand Down
Loading

0 comments on commit 8d84f81

Please sign in to comment.