Skip to content

Commit d51b737

Browse files
committed
Addressed review comments
1 parent e3dfc8a commit d51b737

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+12-7
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,6 @@ - (void)_handleReportBegin
17011701
assertChipStackLockedByCurrentThread();
17021702

17031703
std::lock_guard lock(_lock);
1704-
self.lastSubscriptionActiveTime = [NSDate now];
17051704

17061705
_receivingReport = YES;
17071706
if (_state != MTRDeviceStateReachable) {
@@ -2888,6 +2887,10 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
28882887
^(void) {
28892888
mtr_strongify(self);
28902889
VerifyOrReturn(self, MTR_LOG_DEBUG("_setupSubscriptionWithReason subscription report begin called back with nil MTRDevice"));
2890+
{
2891+
std::lock_guard lock(self->_lock);
2892+
self.lastSubscriptionActiveTime = [NSDate now];
2893+
}
28912894

28922895
MTR_LOG("%@ got report begin", self);
28932896
[self _handleReportBegin];
@@ -4745,18 +4748,20 @@ - (BOOL)_deviceHasActiveSubscription
47454748
return HaveSubscriptionEstablishedRightNow(_internalDeviceState);
47464749
}
47474750

4748-
// TODO: make this configurable - for now use 500ms or 0.5 seconds
4749-
#define MTRDEVICE_ACTIVE_COMMUNICATION_THRESHOLD_SECONDS (0.5)
4751+
// TODO: make this configurable - for now use 1.5 second
4752+
#define MTRDEVICE_ACTIVE_COMMUNICATION_THRESHOLD_SECONDS (1.5)
47504753

47514754
- (void)_deviceMayBeReachable
47524755
{
47534756
// Ignore this call if actively receiving communication from this device
47544757
{
47554758
std::lock_guard lock(self->_lock);
4756-
NSTimeInterval intervalSinceDeviceLastActive = -[self.lastSubscriptionActiveTime timeIntervalSinceNow];
4757-
if (intervalSinceDeviceLastActive < MTRDEVICE_ACTIVE_COMMUNICATION_THRESHOLD_SECONDS) {
4758-
MTR_LOG("%@ _deviceMayBeReachable called and ignored, because last received communication from device %.6lf seconds ago", self, intervalSinceDeviceLastActive);
4759-
return;
4759+
if (self.lastSubscriptionActiveTime) {
4760+
NSTimeInterval intervalSinceDeviceLastActive = -[self.lastSubscriptionActiveTime timeIntervalSinceNow];
4761+
if (intervalSinceDeviceLastActive < MTRDEVICE_ACTIVE_COMMUNICATION_THRESHOLD_SECONDS) {
4762+
MTR_LOG("%@ _deviceMayBeReachable called and ignored, because last received communication from device %.6lf seconds ago", self, intervalSinceDeviceLastActive);
4763+
return;
4764+
}
47604765
}
47614766
}
47624767

0 commit comments

Comments
 (0)