34
34
#import " MTRFabricInfo_Internal.h"
35
35
#import " MTRFramework.h"
36
36
#import " MTRLogging_Internal.h"
37
+ #import " MTRMetricKeys.h"
37
38
#import " MTRMetricsCollector.h"
38
39
#import " MTROTAProviderDelegateBridge.h"
39
40
#import " MTROperationalBrowser.h"
66
67
67
68
using namespace chip ;
68
69
using namespace chip ::Controller;
70
+ using namespace chip ::Tracing::DarwinFramework;
69
71
70
72
static bool sExitHandlerRegistered = false ;
71
73
static void ShutdownOnExit ()
@@ -82,6 +84,11 @@ @interface MTRDeviceControllerFactoryParams ()
82
84
83
85
@end
84
86
87
+ MTR_DIRECT_MEMBERS
88
+ @interface MTRDeviceControllerFactory ()
89
+ - (void )preWarmCommissioningSessionDone ;
90
+ @end
91
+
85
92
MTR_DIRECT_MEMBERS
86
93
@implementation MTRDeviceControllerFactory {
87
94
dispatch_queue_t _chipWorkQueue;
@@ -163,6 +170,12 @@ @implementation MTRDeviceControllerFactory {
163
170
// in an atomic way that endpoint IDs are unique.
164
171
NSMutableArray <MTRServerEndpoint *> * _serverEndpoints;
165
172
os_unfair_lock _serverEndpointsLock; // Protects access to _serverEndpoints.
173
+
174
+ class final : public DeviceLayer ::BleScannerDelegate {
175
+ void OnBleScanStopped () override {
176
+ [MTRDeviceControllerFactory.sharedInstance preWarmCommissioningSessionDone ];
177
+ }
178
+ } _preWarmingDelegate;
166
179
}
167
180
168
181
+ (void )initialize
@@ -742,6 +755,32 @@ - (MTRDeviceController * _Nullable)createControllerOnNewFabric:(MTRDeviceControl
742
755
error: error];
743
756
}
744
757
758
+ - (void )preWarmCommissioningSession
759
+ {
760
+ dispatch_async (_chipWorkQueue, ^{
761
+ CHIP_ERROR err = CHIP_ERROR_INCORRECT_STATE;
762
+ if (!self->_running ) {
763
+ MTR_LOG_ERROR (" Can't pre-warm, Matter controller factory is not running" );
764
+ } else {
765
+ MTR_LOG_DEFAULT (" Pre-warming commissioning session" );
766
+ self->_controllerFactory ->EnsureAndRetainSystemState ();
767
+ err = DeviceLayer::PlatformMgrImpl ().StartBleScan (&self->_preWarmingDelegate , DeviceLayer::BleScanMode::kPreWarm );
768
+ if (err != CHIP_NO_ERROR) {
769
+ MTR_LOG_ERROR (" Pre-warming failed: %" CHIP_ERROR_FORMAT, err.Format ());
770
+ self->_controllerFactory ->ReleaseSystemState ();
771
+ }
772
+ }
773
+ MATTER_LOG_METRIC (kMetricPreWarmCommissioning , err);
774
+ });
775
+ }
776
+
777
+ - (void )preWarmCommissioningSessionDone
778
+ {
779
+ assertChipStackLockedByCurrentThread ();
780
+ MTR_LOG_DEFAULT (" Pre-warming done" );
781
+ self->_controllerFactory ->ReleaseSystemState ();
782
+ }
783
+
745
784
// Finds a fabric that matches the given params, if one exists.
746
785
//
747
786
// Returns NO on failure, YES on success. If YES is returned, the
0 commit comments