@@ -881,24 +881,21 @@ - (MTRDeviceController * _Nullable)maybeInitializeOTAProvider:(MTRDeviceControll
881
881
882
882
- (void )resetOperationalAdvertising
883
883
{
884
- if (!_advertiseOperational) {
885
- // No need to reset anything; we are not advertising the things that
886
- // would need to get reset.
887
- return ;
888
- }
884
+ assertChipStackLockedByCurrentThread ();
889
885
890
- std::lock_guard lock (_controllersLock);
891
- if (_controllers.count != 0 ) {
892
- // We have a running controller. That means we likely need to reset
893
- // operational advertising for that controller.
894
- dispatch_async (_chipWorkQueue, ^{
895
- // StartServer() is the only API we have for resetting DNS-SD
896
- // advertising. It sure would be nice if there were a "restart"
897
- // that was a no-op if the DNS-SD server was not already
898
- // running.
899
- app::DnssdServer::Instance ().StartServer ();
900
- });
886
+ // If we're not advertising, then there's no need to reset anything.
887
+ VerifyOrReturn (_advertiseOperational);
888
+
889
+ // If there are no running controllers there will be no advertisements to reset.
890
+ {
891
+ std::lock_guard lock (_controllersLock);
892
+ VerifyOrReturn (_controllers.count > 0 );
901
893
}
894
+
895
+ // StartServer() is the only API we have for resetting DNS-SD advertising.
896
+ // It sure would be nice if there were a "restart" that was a no-op if the
897
+ // DNS-SD server was not already running.
898
+ app::DnssdServer::Instance ().StartServer ();
902
899
}
903
900
904
901
- (void )controllerShuttingDown : (MTRDeviceController *)controller
@@ -1165,6 +1162,45 @@ - (MTRDeviceController * _Nullable)initializeController:(MTRDeviceController *)c
1165
1162
error: error];
1166
1163
}
1167
1164
1165
+ - (void )setMessageReliabilityProtocolIdleRetransmitMs : (nullable NSNumber *)idleRetransmitMs
1166
+ activeRetransmitMs : (nullable NSNumber *)activeRetransmitMs
1167
+ activeThresholdMs : (nullable NSNumber *)activeThresholdMs
1168
+ additionalRetransmitDelayMs : (nullable NSNumber *)additionalRetransmitDelayMs
1169
+ {
1170
+ [self _assertCurrentQueueIsNotMatterQueue ];
1171
+ dispatch_async (_chipWorkQueue, ^{
1172
+ bool resetAdvertising;
1173
+ if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil ) {
1174
+ Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime (NullOptional);
1175
+ resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig (NullOptional);
1176
+ } else {
1177
+ if (additionalRetransmitDelayMs != nil ) {
1178
+ System::Clock::Timeout additionalBackoff (additionalRetransmitDelayMs.unsignedLongValue );
1179
+ Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime (MakeOptional (additionalBackoff));
1180
+ }
1181
+
1182
+ // Get current MRP parameters, then override the things we were asked to
1183
+ // override.
1184
+ ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig ().ValueOr (GetDefaultMRPConfig ());
1185
+ if (idleRetransmitMs != nil ) {
1186
+ mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32 (idleRetransmitMs.unsignedLongValue );
1187
+ }
1188
+ if (activeRetransmitMs != nil ) {
1189
+ mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32 (activeRetransmitMs.unsignedLongValue );
1190
+ }
1191
+ if (activeThresholdMs != nil ) {
1192
+ mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32 (activeThresholdMs.unsignedLongValue );
1193
+ }
1194
+
1195
+ resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig (MakeOptional (mrpConfig));
1196
+ }
1197
+
1198
+ if (resetAdvertising) {
1199
+ [self resetOperationalAdvertising ];
1200
+ }
1201
+ });
1202
+ }
1203
+
1168
1204
- (PersistentStorageDelegate *)storageDelegate
1169
1205
{
1170
1206
return _persistentStorageDelegate;
@@ -1327,33 +1363,8 @@ void MTRSetMessageReliabilityParameters(NSNumber * _Nullable idleRetransmitMs,
1327
1363
NSNumber * _Nullable activeThresholdMs,
1328
1364
NSNumber * _Nullable additionalRetransmitDelayMs)
1329
1365
{
1330
- bool resetAdvertising = false ;
1331
- if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil ) {
1332
- Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime (NullOptional);
1333
- resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig (NullOptional);
1334
- } else {
1335
- if (additionalRetransmitDelayMs != nil ) {
1336
- System::Clock::Timeout additionalBackoff (additionalRetransmitDelayMs.unsignedLongValue );
1337
- Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime (MakeOptional (additionalBackoff));
1338
- }
1339
-
1340
- // Get current MRP parameters, then override the things we were asked to
1341
- // override.
1342
- ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig ().ValueOr (GetDefaultMRPConfig ());
1343
- if (idleRetransmitMs != nil ) {
1344
- mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32 (idleRetransmitMs.unsignedLongValue );
1345
- }
1346
- if (activeRetransmitMs != nil ) {
1347
- mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32 (activeRetransmitMs.unsignedLongValue );
1348
- }
1349
- if (activeThresholdMs != nil ) {
1350
- mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32 (activeThresholdMs.unsignedLongValue );
1351
- }
1352
-
1353
- resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig (MakeOptional (mrpConfig));
1354
- }
1355
-
1356
- if (resetAdvertising) {
1357
- [[MTRDeviceControllerFactory sharedInstance ] resetOperationalAdvertising ];
1358
- }
1366
+ [MTRDeviceControllerFactory.sharedInstance setMessageReliabilityProtocolIdleRetransmitMs: idleRetransmitMs
1367
+ activeRetransmitMs: activeThresholdMs
1368
+ activeThresholdMs: activeThresholdMs
1369
+ additionalRetransmitDelayMs: additionalRetransmitDelayMs];
1359
1370
}
0 commit comments