Skip to content

Commit 759dd8c

Browse files
Merge branch 'master' into tc-idm-4.3-(python)
2 parents 3900053 + 8fa5422 commit 759dd8c

File tree

4 files changed

+32
-54
lines changed

4 files changed

+32
-54
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+9-30
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,6 @@ - (id)strongObject
141141
} // anonymous namespace
142142

143143
#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-
};
163144

164145
// Utility methods for working with MTRInternalDeviceState, located near the
165146
// enum so it's easier to notice that they need to stay in sync.
@@ -687,26 +668,29 @@ - (void)_setDSTOffsets:(NSArray<MTRTimeSynchronizationClusterDSTOffsetStruct *>
687668

688669
- (BOOL)_subscriptionsAllowed
689670
{
671+
os_unfair_lock_assert_owner(&self->_lock);
672+
673+
// We should not allow a subscription for device controllers over XPC.
690674
return ![_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class];
691675
}
692676

693677
- (void)setDelegate:(id<MTRDeviceDelegate>)delegate queue:(dispatch_queue_t)queue
694678
{
695679
MTR_LOG("%@ setDelegate %@", self, delegate);
696680

697-
// We should not set up a subscription for device controllers over XPC.
681+
std::lock_guard lock(_lock);
682+
698683
BOOL setUpSubscription = [self _subscriptionsAllowed];
699684

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.
701687
#ifdef DEBUG
702688
id testDelegate = delegate;
703689
if ([testDelegate respondsToSelector:@selector(unitTestShouldSetUpSubscriptionForDevice:)]) {
704690
setUpSubscription = [testDelegate unitTestShouldSetUpSubscriptionForDevice:self];
705691
}
706692
#endif
707693

708-
std::lock_guard lock(_lock);
709-
710694
_weakDelegate = [MTRWeakReference weakReferenceWithObject:delegate];
711695
_delegateQueue = queue;
712696

@@ -829,13 +813,8 @@ - (BOOL)_subscriptionAbleToReport
829813
}
830814
#endif
831815

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];
839818
}
840819

841820
// Notification that read-through was skipped for an attribute read.

src/darwin/Framework/CHIP/MTRDevice_Internal.h

+20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ typedef NSDictionary<NSString *, id> * MTRDeviceDataValueDictionary;
3030

3131
typedef void (^MTRDevicePerformAsyncBlock)(MTRBaseDevice * baseDevice);
3232

33+
typedef NS_ENUM(NSUInteger, MTRInternalDeviceState) {
34+
// Unsubscribed means we do not have a subscription and are not trying to set one up.
35+
MTRInternalDeviceStateUnsubscribed = 0,
36+
// Subscribing means we are actively trying to establish our initial subscription (e.g. doing
37+
// DNS-SD discovery, trying to establish CASE to the peer, getting priming reports, etc).
38+
MTRInternalDeviceStateSubscribing = 1,
39+
// InitialSubscriptionEstablished means we have at some point finished setting up a
40+
// subscription. That subscription may have dropped since then, but if so it's the ReadClient's
41+
// responsibility to re-establish it.
42+
MTRInternalDeviceStateInitialSubscriptionEstablished = 2,
43+
// Resubscribing means we had established a subscription, but then
44+
// detected a subscription drop due to not receiving a report on time. This
45+
// covers all the actions that happen when re-subscribing (discovery, CASE,
46+
// getting priming reports, etc).
47+
MTRInternalDeviceStateResubscribing = 3,
48+
// LaterSubscriptionEstablished meant that we had a subscription drop and
49+
// then re-created a subscription.
50+
MTRInternalDeviceStateLaterSubscriptionEstablished = 4,
51+
};
52+
3353
/**
3454
* Information about a cluster: data version and known attribute values.
3555
*/

src/darwin/Framework/CHIPTests/MTRDeviceTests.m

+3-4
Original file line numberDiff line numberDiff line change
@@ -3630,22 +3630,21 @@ - (void)test035_TestMTRDeviceSubscriptionNotEstablishedOverXPC
36303630
__auto_type * device = [MTRDevice deviceWithNodeID:kDeviceId deviceController:remoteController];
36313631
dispatch_queue_t queue = dispatch_get_main_queue();
36323632

3633-
// We should not set up a subscription when creating a MTRDevice with a remote controller.
36343633
XCTestExpectation * subscriptionExpectation = [self expectationWithDescription:@"Subscription has been set up"];
36353634
subscriptionExpectation.inverted = YES;
36363635

36373636
__auto_type * delegate = [[MTRDeviceTestDelegate alloc] init];
36383637

3639-
XCTAssertTrue([device _getInternalState] == MTRInternalDeviceStateUnsubscribed);
3638+
XCTAssertEqual([device _getInternalState], MTRInternalDeviceStateUnsubscribed);
36403639

36413640
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * attributeReport) {
36423641
[subscriptionExpectation fulfill];
36433642
};
36443643

36453644
[device setDelegate:delegate queue:queue];
3646-
[self waitForExpectations:@[ subscriptionExpectation ] timeout:30];
3645+
[self waitForExpectations:@[ subscriptionExpectation ] timeout:5];
36473646

3648-
XCTAssertTrue([device _getInternalState] == MTRInternalDeviceStateUnsubscribed);
3647+
XCTAssertEqual([device _getInternalState], MTRInternalDeviceStateUnsubscribed);
36493648
}
36503649

36513650
@end

src/darwin/Framework/CHIPTests/TestHelpers/MTRTestDeclarations.h

-20
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,6 @@ NS_ASSUME_NONNULL_BEGIN
5959
@end
6060

6161
@interface MTRDevice (TestDebug)
62-
typedef NS_ENUM(NSUInteger, MTRInternalDeviceState) {
63-
// Unsubscribed means we do not have a subscription and are not trying to set one up.
64-
MTRInternalDeviceStateUnsubscribed = 0,
65-
// Subscribing means we are actively trying to establish our initial subscription (e.g. doing
66-
// DNS-SD discovery, trying to establish CASE to the peer, getting priming reports, etc).
67-
MTRInternalDeviceStateSubscribing = 1,
68-
// InitialSubscriptionEstablished means we have at some point finished setting up a
69-
// subscription. That subscription may have dropped since then, but if so it's the ReadClient's
70-
// responsibility to re-establish it.
71-
MTRInternalDeviceStateInitialSubscriptionEstablished = 2,
72-
// Resubscribing means we had established a subscription, but then
73-
// detected a subscription drop due to not receiving a report on time. This
74-
// covers all the actions that happen when re-subscribing (discovery, CASE,
75-
// getting priming reports, etc).
76-
MTRInternalDeviceStateResubscribing = 3,
77-
// LaterSubscriptionEstablished meant that we had a subscription drop and
78-
// then re-created a subscription.
79-
MTRInternalDeviceStateLaterSubscriptionEstablished = 4,
80-
};
81-
8262
- (void)unitTestInjectEventReport:(NSArray<NSDictionary<NSString *, id> *> *)eventReport;
8363
- (void)unitTestInjectAttributeReport:(NSArray<NSDictionary<NSString *, id> *> *)attributeReport fromSubscription:(BOOL)isFromSubscription;
8464
- (NSUInteger)unitTestAttributesReportedSinceLastCheck;

0 commit comments

Comments
 (0)