@@ -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,26 +668,29 @@ - (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
- // For unit testing only
685
+ // For unit testing only. If this ever changes to not being for unit testing purposes,
686
+ // we would need to move the code outside of where we acquire the lock above.
701
687
#ifdef DEBUG
702
688
id testDelegate = delegate;
703
689
if ([testDelegate respondsToSelector: @selector (unitTestShouldSetUpSubscriptionForDevice: )]) {
704
690
setUpSubscription = [testDelegate unitTestShouldSetUpSubscriptionForDevice: self ];
705
691
}
706
692
#endif
707
693
708
- std::lock_guard lock (_lock);
709
-
710
694
_weakDelegate = [MTRWeakReference weakReferenceWithObject: delegate];
711
695
_delegateQueue = queue;
712
696
@@ -829,13 +813,8 @@ - (BOOL)_subscriptionAbleToReport
829
813
}
830
814
#endif
831
815
832
- // 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
+ // Subscriptions are not able to report if they are not allowed.
817
+ return [self _subscriptionsAllowed ];
839
818
}
840
819
841
820
// Notification that read-through was skipped for an attribute read.
0 commit comments