@@ -141,25 +141,6 @@ - (id)strongObject
141
141
} // anonymous namespace
142
142
143
143
#pragma mark - MTRDevice
144
- typedef NS_ENUM(NSUInteger, MTRInternalDeviceState) {
145
- // Unsubscribed means we do not have a subscription and are not trying to set one up.
146
- MTRInternalDeviceStateUnsubscribed = 0,
147
- // Subscribing means we are actively trying to establish our initial subscription (e.g. doing
148
- // DNS-SD discovery, trying to establish CASE to the peer, getting priming reports, etc).
149
- MTRInternalDeviceStateSubscribing = 1,
150
- // InitialSubscriptionEstablished means we have at some point finished setting up a
151
- // subscription. That subscription may have dropped since then, but if so it's the ReadClient's
152
- // responsibility to re-establish it.
153
- MTRInternalDeviceStateInitialSubscriptionEstablished = 2,
154
- // Resubscribing means we had established a subscription, but then
155
- // detected a subscription drop due to not receiving a report on time. This
156
- // covers all the actions that happen when re-subscribing (discovery, CASE,
157
- // getting priming reports, etc).
158
- MTRInternalDeviceStateResubscribing = 3,
159
- // LaterSubscriptionEstablished meant that we had a subscription drop and
160
- // then re-created a subscription.
161
- MTRInternalDeviceStateLaterSubscriptionEstablished = 4,
162
- };
163
144
164
145
// Utility methods for working with MTRInternalDeviceState, located near the
165
146
// enum so it's easier to notice that they need to stay in sync.
@@ -687,16 +668,20 @@ - (void)_setDSTOffsets:(NSArray<MTRTimeSynchronizationClusterDSTOffsetStruct *>
687
668
688
669
- (BOOL)_subscriptionsAllowed
689
670
{
671
+ os_unfair_lock_assert_owner(&self->_lock);
672
+
673
+ // We should not allow a subscription for device controllers over XPC.
690
674
return ![_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class];
691
675
}
692
676
693
677
- (void)setDelegate:(id<MTRDeviceDelegate>)delegate queue:(dispatch_queue_t)queue
694
678
{
695
679
MTR_LOG("%@ setDelegate %@", self, delegate);
696
680
697
- // We should not set up a subscription for device controllers over XPC.
681
+ std::lock_guard lock(_lock);
682
+
698
683
BOOL setUpSubscription = [self _subscriptionsAllowed];
699
-
684
+
700
685
// For unit testing only
701
686
#ifdef DEBUG
702
687
id testDelegate = delegate;
@@ -705,8 +690,6 @@ - (void)setDelegate:(id<MTRDeviceDelegate>)delegate queue:(dispatch_queue_t)queu
705
690
}
706
691
#endif
707
692
708
- std::lock_guard lock(_lock);
709
-
710
693
_weakDelegate = [MTRWeakReference weakReferenceWithObject:delegate];
711
694
_delegateQueue = queue;
712
695
@@ -830,12 +813,8 @@ - (BOOL)_subscriptionAbleToReport
830
813
#endif
831
814
832
815
// Unfortunately, we currently have no subscriptions over our hacked-up XPC
833
- // setup. Try to detect that situation.
834
- if ([_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class]) {
835
- return NO;
836
- }
837
-
838
- return YES;
816
+ // setup. Based on whether subscriptions are allowed or not, return YES or NO.
817
+ return [self _subscriptionsAllowed];
839
818
}
840
819
841
820
// Notification that read-through was skipped for an attribute read.
0 commit comments