Adding isSuspended delegate for MTRDeviceController (#35499)
* Adding delegate
* Restyled by whitespace
* Restyled by clang-format
* Fixing this
* Restyled by clang-format
* Moving these into sync
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm
index 2029097..69bb02d 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm
@@ -383,6 +383,16 @@
}
}
+- (void)_notifyDelegatesOfSuspendState
+{
+ BOOL isSuspended = [self isSuspended];
+ [self _callDelegatesWithBlock:^(id<MTRDeviceControllerDelegate> delegate) {
+ if ([delegate respondsToSelector:@selector(controller:isSuspended:)]) {
+ [delegate controller:self isSuspended:isSuspended];
+ }
+ } logString:__PRETTY_FUNCTION__];
+}
+
- (void)suspend
{
MTR_LOG("%@ suspending", self);
@@ -405,6 +415,8 @@
// * Active commissioning sessions (presumably close them?)
// * CASE sessions in general.
// * Possibly try to see whether we can change our fabric entry to not advertise and restart advertising.
+
+ [self _notifyDelegatesOfSuspendState];
}
}
@@ -424,6 +436,8 @@
for (MTRDevice * device in devicesToResume) {
[device controllerResumed];
}
+
+ [self _notifyDelegatesOfSuspendState];
}
}
diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
index b8b9be9..40382c9 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
+++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDelegate.h
@@ -106,6 +106,13 @@
*/
- (void)controller:(MTRDeviceController *)controller
readCommissioningInfo:(MTRProductIdentity *)info MTR_AVAILABLE(ios(17.0), macos(14.0), watchos(10.0), tvos(17.0));
+
+/**
+ * Notify the delegate when the suspended state changed of the controller, after this happens
+ * the controller will be in the specified state.
+ */
+- (void)controller:(MTRDeviceController *)controller
+ isSuspended:(BOOL)suspended MTR_NEWLY_AVAILABLE;
@end
typedef NS_ENUM(NSUInteger, MTRPairingStatus) {