Skip to content

Commit 4466400

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Enable Darwin per-controller storage by default. (#30215)
Fixes the parameters bits to allow later adding XPC parameters.
1 parent cc55252 commit 4466400

7 files changed

+48
-10
lines changed

.github/workflows/darwin.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ jobs:
111111
# -enableUndefinedBehaviorSanitizer instruments the code in Matter.framework,
112112
# but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_UBSAN=YES
113113
TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion' CHIP_IS_UBSAN=YES CHIP_IS_BLE=NO GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1'> >(tee /tmp/darwin/framework-tests/darwin-tests-asan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-err.log >&2)
114-
# And the same thing, but with MTR_PER_CONTROLLER_STORAGE_ENABLED turned on.
115-
TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion' CHIP_IS_UBSAN=YES CHIP_IS_BLE=NO GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1 MTR_PER_CONTROLLER_STORAGE_ENABLED=1' > >(tee /tmp/darwin/framework-tests/darwin-tests-asan-controller-storage.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-controller-storage-err.log >&2)
114+
# And the same thing, but with MTR_PER_CONTROLLER_STORAGE_ENABLED turned off, so we test that it does not break for now.
115+
TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion' CHIP_IS_UBSAN=YES CHIP_IS_BLE=NO GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1 MTR_PER_CONTROLLER_STORAGE_ENABLED=0' > >(tee /tmp/darwin/framework-tests/darwin-tests-asan-controller-storage.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-controller-storage-err.log >&2)
116116
# And the same thing, but with MTR_ENABLE_PROVISIONAL also turned on.
117117
TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion' CHIP_IS_UBSAN=YES CHIP_IS_BLE=NO GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_NO_AVAILABILITY=1 MTR_PER_CONTROLLER_STORAGE_ENABLED=1 MTR_ENABLE_PROVISIONAL=1' > >(tee /tmp/darwin/framework-tests/darwin-tests-asan-provisional.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-provisional-err.log >&2)
118118
# And the same thing, but with MTR_NO_AVAILABILITY not turned on. This requires -Wno-unguarded-availability-new to avoid availability errors.

src/darwin/Framework/CHIP/MTRDefines.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#endif
7272

7373
#ifndef MTR_PER_CONTROLLER_STORAGE_ENABLED
74-
#define MTR_PER_CONTROLLER_STORAGE_ENABLED 0
74+
#define MTR_PER_CONTROLLER_STORAGE_ENABLED 1
7575
#endif
7676

7777
#pragma mark - Types

src/darwin/Framework/CHIP/MTRDeviceController.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@class MTRBaseDevice;
2525

2626
#if MTR_PER_CONTROLLER_STORAGE_ENABLED
27-
@class MTRDeviceControllerParameters;
27+
@class MTRDeviceControllerAbstractParameters;
2828
#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED
2929

3030
NS_ASSUME_NONNULL_BEGIN
@@ -58,7 +58,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
5858
* Once this returns non-nil, it's the caller's resposibility to call shutdown
5959
* on the controller to avoid leaking it.
6060
*/
61-
- (nullable instancetype)initWithParameters:(MTRDeviceControllerParameters *)parameters
61+
- (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
6262
error:(NSError * __autoreleasing *)error MTR_NEWLY_AVAILABLE;
6363
#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED
6464

src/darwin/Framework/CHIP/MTRDeviceController.mm

+13-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,17 @@ @interface MTRDeviceController () {
127127

128128
@implementation MTRDeviceController
129129

130-
- (nullable instancetype)initWithParameters:(MTRDeviceControllerParameters *)parameters error:(NSError * __autoreleasing *)error
130+
- (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters error:(NSError * __autoreleasing *)error
131131
{
132+
if (![parameters isKindOfClass:MTRDeviceControllerParameters.class]) {
133+
MTR_LOG_ERROR("Unsupported type of MTRDeviceControllerAbstractParameters: %@", parameters);
134+
135+
if (error) {
136+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT];
137+
}
138+
return nil;
139+
}
140+
132141
__auto_type * factory = [MTRDeviceControllerFactory sharedInstance];
133142
if (!factory.isRunning) {
134143
auto * params = [[MTRDeviceControllerFactoryParams alloc] initWithoutStorage];
@@ -138,7 +147,9 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerParameters *)par
138147
}
139148
}
140149

141-
return [factory initializeController:self withParameters:parameters error:error];
150+
auto * parametersForFactory = static_cast<MTRDeviceControllerParameters *>(parameters);
151+
152+
return [factory initializeController:self withParameters:parametersForFactory error:error];
142153
}
143154

144155
- (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory

src/darwin/Framework/CHIP/MTRDeviceControllerParameters.h

+17-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,29 @@
2828

2929
NS_ASSUME_NONNULL_BEGIN
3030

31+
/**
32+
* Parameters that can be used to initialize an MTRDeviceController. Specific
33+
* interfaces inheriting from this one should be used to actually do the
34+
* initialization.
35+
*/
3136
#if !MTR_PER_CONTROLLER_STORAGE_ENABLED
3237
MTR_HIDDEN
3338
#endif
3439
MTR_NEWLY_AVAILABLE
35-
@interface MTRDeviceControllerParameters : NSObject
36-
40+
@interface MTRDeviceControllerAbstractParameters : NSObject
3741
- (instancetype)init NS_UNAVAILABLE;
3842
+ (instancetype)new NS_UNAVAILABLE;
43+
@end
44+
45+
/**
46+
* Parameters that can be used to initialize an MTRDeviceController which
47+
* has a node identity.
48+
*/
49+
#if !MTR_PER_CONTROLLER_STORAGE_ENABLED
50+
MTR_HIDDEN
51+
#endif
52+
MTR_NEWLY_AVAILABLE
53+
@interface MTRDeviceControllerParameters : MTRDeviceControllerAbstractParameters
3954

4055
/**
4156
* The Product Attestation Authority certificates that are trusted to sign

src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm

+8-1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ - (instancetype)initWithOperationalKeypair:(id<MTRKeypair>)operationalKeypair
251251

252252
@end
253253

254+
@implementation MTRDeviceControllerAbstractParameters
255+
- (instancetype)_initInternal
256+
{
257+
return [super init];
258+
}
259+
@end
260+
254261
@implementation MTRDeviceControllerParameters
255262
- (instancetype)initWithStorageDelegate:(id<MTRDeviceControllerStorageDelegate>)storageDelegate
256263
storageDelegateQueue:(dispatch_queue_t)storageDelegateQueue
@@ -262,7 +269,7 @@ - (instancetype)initWithStorageDelegate:(id<MTRDeviceControllerStorageDelegate>)
262269
intermediateCertificate:(MTRCertificateDERBytes _Nullable)intermediateCertificate
263270
rootCertificate:(MTRCertificateDERBytes)rootCertificate
264271
{
265-
if (!(self = [super init])) {
272+
if (!(self = [super _initInternal])) {
266273
return nil;
267274
}
268275

src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ NS_ASSUME_NONNULL_BEGIN
5252
- (instancetype)initWithParams:(MTRDeviceControllerStartupParams *)params;
5353
@end
5454

55+
@interface MTRDeviceControllerAbstractParameters ()
56+
// Allow init from our subclasses.
57+
- (instancetype)_initInternal;
58+
@end
59+
5560
@interface MTRDeviceControllerParameters ()
5661

5762
- (instancetype)initWithStorageDelegate:(id<MTRDeviceControllerStorageDelegate>)storageDelegate

0 commit comments

Comments
 (0)