Skip to content

Commit

Permalink
Removing old API
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Jul 1, 2022
1 parent 95c3753 commit c878aa9
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,31 +226,34 @@ - (void)reportFromUserEnteredSettings
maxInterval:maxIntervalSeconds
params:nil
cacheContainer:nil
reportHandler:^(NSArray<MTRAttributeReport *> * _Nullable reports, NSError * _Nullable error) {
if (error) {
NSLog(@"Status: update reportAttributeMeasuredValue completed with error %@",
[error description]);
return;
}
for (MTRAttributeReport * report in reports) {
// These should be exposed by the SDK
if ([report.path.cluster isEqualToNumber:@(MTRClusterTemperatureMeasurementID)] &&
[report.path.attribute
isEqualToNumber:@(MTRClusterTemperatureMeasurementAttributeMeasuredValueID)]) {
if (report.error != nil) {
NSLog(@"Error reading temperature: %@", report.error);
} else {
__auto_type controller = [TemperatureSensorViewController currentController];
if (controller != nil) {
[controller updateTempInUI:((NSNumber *) report.value).shortValue];
}
}
}
}
attributeReportHandler:^(NSArray * _Nullable reports) {
if ( !reports )
return;
for (MTRAttributeReport * report in reports) {
// These should be exposed by the SDK
if ([report.path.cluster isEqualToNumber:@(MTRClusterTemperatureMeasurementID)] &&
[report.path.attribute
isEqualToNumber:@(MTRClusterTemperatureMeasurementAttributeMeasuredValueID)]) {
if (report.error != nil) {
NSLog(@"Error reading temperature: %@", report.error);
} else {
__auto_type controller = [TemperatureSensorViewController currentController];
if (controller != nil) {
[controller updateTempInUI:((NSNumber *) report.value).shortValue];
}
}
}
}
}
eventReportHandler:nil
errorHandler:^(NSError * error) {
NSLog(@"Status: update reportAttributeMeasuredValue completed with error %@",
[error description]);
}
subscriptionEstablished:^ {

}];
subscriptionEstablished:(nullable void (^)(void))subscriptionEstablishedHandler { if (error) {
NSLog(@"Status: update reportAttributeMeasuredValue completed");
}
];
} else {
NSLog(@"Status: Failed to establish a connection with the device");
}
Expand Down
33 changes: 0 additions & 33 deletions src/darwin/Framework/CHIP/MTRDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,39 +98,6 @@ extern NSString * const MTRArrayValueType;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

/**
* Subscribe to receive attribute reports for everything (all endpoints, all
* clusters, all attributes, all events) on the device.
*
* A non-nil attribute cache container will cache attribute values, retrievable
* through the designated attribute cache container.
*
* reportHandler will be called any time a data update is available (with a
* non-nil "value" and nil "error"), or any time there is an error for the
* entire subscription (with a nil "value" and non-nil "error"). If it's called
* with an error, that will terminate the subscription.
*
* The array passed to reportHandler will contain MTRAttributeReport
* instances. Errors for specific paths, not the whole subscription, will be
* reported via those objects.
*
* reportHandler is not supported over XPC at the moment.
*
* subscriptionEstablished block, if not nil, will be called once the
* subscription is established. This will be _after_ the first (priming) call
* to reportHandler. Note that if the MTRSubscribeParams are set to
* automatically resubscribe this can end up being called more than once.
*
* TODO: Remove this once the replacement below is adopted
*/
- (void)subscribeWithQueue:(dispatch_queue_t)queue
minInterval:(uint16_t)minInterval
maxInterval:(uint16_t)maxInterval
params:(nullable MTRSubscribeParams *)params
cacheContainer:(MTRAttributeCacheContainer * _Nullable)attributeCacheContainer
reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler
subscriptionEstablished:(nullable void (^)(void))subscriptionEstablishedHandler;

/**
* Subscribe to receive attribute reports for everything (all endpoints, all
* clusters, all attributes, all events) on the device.
Expand Down
25 changes: 0 additions & 25 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -336,31 +336,6 @@ - (instancetype)initWithDevice:(chip::DeviceProxy *)device

} // anonymous namespace

- (void)subscribeWithQueue:(dispatch_queue_t)queue
minInterval:(uint16_t)minInterval
maxInterval:(uint16_t)maxInterval
params:(nullable MTRSubscribeParams *)params
cacheContainer:(MTRAttributeCacheContainer * _Nullable)attributeCacheContainer
reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler
subscriptionEstablished:(nullable void (^)(void))subscriptionEstablishedHandler
{
[self subscribeWithQueue:queue
minInterval:minInterval
maxInterval:maxInterval
params:params
cacheContainer:attributeCacheContainer
attributeReportHandler:^(NSArray * _Nullable value) {
reportHandler(value, nil);
}
eventReportHandler:^(NSArray * _Nullable value) {
; // do nothing
}
errorHandler:^(NSError * _Nullable error) {
reportHandler(nil, error);
}
subscriptionEstablished:subscriptionEstablishedHandler];
}

- (void)subscribeWithQueue:(dispatch_queue_t)queue
minInterval:(uint16_t)minInterval
maxInterval:(uint16_t)maxInterval
Expand Down
4 changes: 1 addition & 3 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRDevice * _Nullable device, NSErro
- (BOOL)stopDevicePairing:(uint64_t)deviceID error:(NSError * __autoreleasing *)error;

- (nullable MTRDevice *)getDeviceBeingCommissioned:(uint64_t)deviceId error:(NSError * __autoreleasing *)error;
- (BOOL)getConnectedDevice:(uint64_t)deviceID
queue:(dispatch_queue_t)queue
completionHandler:(MTRDeviceConnectionCallback)completionHandler;
- (BOOL)getDevice:(uint64_t)deviceID queue:(dispatch_queue_t)queue completionHandler:(MTRDeviceConnectionCallback)completionHandler;

- (BOOL)openPairingWindow:(uint64_t)deviceID duration:(NSUInteger)duration error:(NSError * __autoreleasing *)error;
- (nullable NSString *)openPairingWindowWithPIN:(uint64_t)deviceID
Expand Down
20 changes: 10 additions & 10 deletions src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (BOOL)pairDevice:(uint64_t)deviceID
setupPINCode:(uint32_t)setupPINCode
error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support pairDevice over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support pairDevice over XPC");
return NO;
}

Expand All @@ -62,44 +62,44 @@ - (BOOL)pairDevice:(uint64_t)deviceID
setupPINCode:(uint32_t)setupPINCode
error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support pairDevice over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support pairDevice over XPC");
return NO;
}

- (BOOL)pairDevice:(uint64_t)deviceID onboardingPayload:(NSString *)onboardingPayload error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support pairDevice over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support pairDevice over XPC");
return NO;
}

- (BOOL)commissionDevice:(uint64_t)deviceId
commissioningParams:(MTRCommissioningParameters *)commissioningParams
error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support pairDevice over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support pairDevice over XPC");
return NO;
}

- (void)setListenPort:(uint16_t)port
{
CHIP_LOG_ERROR("CHIPDevice doesn't support setListenPort over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support setListenPort over XPC");
}

- (BOOL)stopDevicePairing:(uint64_t)deviceID error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support stopDevicePairing over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support stopDevicePairing over XPC");
return NO;
}

- (nullable MTRDevice *)getDeviceBeingCommissioned:(uint64_t)deviceId error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support getDeviceBeingCommissioned over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support getDeviceBeingCommissioned over XPC");
return nil;
}

- (BOOL)deviceBeingCommissionedOverBLE:(uint64_t)deviceId
{
CHIP_LOG_ERROR("CHIPDevice doesn't support deviceBeingCommissionedOverBLE over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support deviceBeingCommissionedOverBLE over XPC");
return NO;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ - (BOOL)getConnectedDevice:(uint64_t)deviceID

- (BOOL)openPairingWindow:(uint64_t)deviceID duration:(NSUInteger)duration error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support openPairingWindow over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support openPairingWindow over XPC");
return NO;
}

Expand All @@ -156,7 +156,7 @@ - (nullable NSString *)openPairingWindowWithPIN:(uint64_t)deviceID
setupPIN:(NSUInteger)setupPIN
error:(NSError * __autoreleasing *)error
{
CHIP_LOG_ERROR("CHIPDevice doesn't support openPairingWindow over XPC");
CHIP_LOG_ERROR("MTRDevice doesn't support openPairingWindow over XPC");
return nil;
}

Expand Down
10 changes: 6 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceOverXPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
maxInterval:(uint16_t)maxInterval
params:(nullable MTRSubscribeParams *)params
cacheContainer:(MTRAttributeCacheContainer * _Nullable)attributeCacheContainer
reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler
subscriptionEstablished:(void (^_Nullable)(void))subscriptionEstablishedHandler
attributeReportHandler:(void (^)(NSArray * value))attributeReportHandler
eventReportHandler:(void (^)(NSArray * value))eventReportHandler
errorHandler:(void (^)(NSError * error))errorHandler
subscriptionEstablished:(nullable void (^)(void))subscriptionEstablishedHandler;
{
CHIP_LOG_DEBUG("Subscribing all attributes... Note that reportHandler is not supported.");
if (attributeCacheContainer) {
Expand All @@ -70,7 +72,7 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
completion:^(NSError * _Nullable error) {
dispatch_async(queue, ^{
if (error) {
reportHandler(nil, error);
errorHandler(error);
} else {
subscriptionEstablishedHandler();
}
Expand All @@ -81,7 +83,7 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
} else {
CHIP_LOG_ERROR("Failed to obtain XPC connection to write attribute");
dispatch_async(queue, ^{
reportHandler(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
errorHandler([NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
});
}
}];
Expand Down
17 changes: 7 additions & 10 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -708,22 +708,19 @@ - (void)test011_ReadCachedAttribute
XCTestExpectation * subscribeExpectation = [self expectationWithDescription:@"Subscription complete"];

NSLog(@"Subscribing...");
__block void (^reportHandler)(NSArray * _Nullable value, NSError * _Nullable error);
[device subscribeWithQueue:queue
minInterval:2
maxInterval:60
params:nil
cacheContainer:attributeCacheContainer
reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) {
NSLog(@"Received report: %@, error: %@", value, error);
if (reportHandler) {
__auto_type handler = reportHandler;
reportHandler = nil;
handler(value, error);
}
attributeReportHandler:^(NSArray * value) {
NSLog(@"Received report: %@", value);
}
subscriptionEstablished:^{
NSLog(@"Subscription established");
eventReportHandler:nil
errorHandler:^(NSError * error) {
NSLog(@"Received report error: %@", error);
}
subscriptionEstablished:^() {
[subscribeExpectation fulfill];
}];
[self waitForExpectations:@[ subscribeExpectation ] timeout:60];
Expand Down
22 changes: 15 additions & 7 deletions src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,18 @@ - (void)subscribeWithController:(id _Nullable)controller
maxInterval:[maxInterval unsignedShortValue]
params:[MTRDeviceController decodeXPCSubscribeParams:params]
cacheContainer:attributeCacheContainer
reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) {
NSLog(@"Report received: %@, error: %@", value, error);
if (error && ![established[0] boolValue]) {
attributeReportHandler:^(NSArray * value) {
NSLog(@"Received report: %@", value);
}
eventReportHandler:nil
errorHandler:^(NSError * error) {
NSLog(@"Received report error: %@", error);
if (![established[0] boolValue]) {
established[0] = @YES;
completion(error);
}
}
subscriptionEstablished:^{
subscriptionEstablished:^() {
NSLog(@"Attribute cache subscription succeeded for device %llu", nodeId);
if (attributeCacheContainer) {
[self.attributeCacheDictionary setObject:attributeCacheContainer forKey:@(nodeId)];
Expand Down Expand Up @@ -1783,10 +1787,14 @@ - (void)test900_SubscribeAttributeCache
maxInterval:60
params:nil
cacheContainer:attributeCacheContainer
reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) {
NSLog(@"Report for attribute cache: %@, error: %@", value, error);
attributeReportHandler:^(NSArray * value) {
NSLog(@"Report for attribute cache: %@", error);
}
subscriptionEstablished:^{
eventReportHandler:nil
errorHandler:^(NSError * error) {
NSLog(@"Received error for attribute cache: %@", error);
}
subscriptionEstablished:^() {
NSLog(@"Attribute cache subscribed attributes");
[expectation fulfill];
}];
Expand Down
12 changes: 8 additions & 4 deletions src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,24 @@ - (void)subscribeWithDeviceController:(MTRDeviceController *)deviceController
maxInterval:43200
params:params
cacheContainer:self
reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) {
NSLog(@"Report received for attribute cache: %@, error: %@", value, error);
attributeReportHandler:^(NSArray * value) {
NSLog(@"Report received for attribute cache: %@", value);
}
eventReportHandler:nil
errorHandler:^(NSError * error) {
NSLog(@"Report error received for attribute cache: %@", error);
if (![established[0] boolValue]) {
established[0] = @YES;
completionHandler(error);
}
}
subscriptionEstablished:^{
subscriptionEstablished:^() {
NSLog(@"Attribute cache subscription succeeded for device %llu", deviceId);
if (![established[0] boolValue]) {
established[0] = @YES;
completionHandler(nil);
}
}];
}];
}];
}
@end
Expand Down

0 comments on commit c878aa9

Please sign in to comment.