Skip to content

Commit

Permalink
[Darwin] Duplicate / begin raising MTRDeviceController (project-chi…
Browse files Browse the repository at this point in the history
…p#34832)

* Keep MTRDeviceController.mm

* Copy MTRDeviceController.mm into MTRDeviceController_Concrete.mm

* Set back MTRDeviceController.mm file

* Keep MTRDeviceController.h

* Copy MTRDeviceController.h into MTRDeviceController_Concrete.h

* Set back MTRDeviceController.h file

* add `MTRDeviceController_Concrete` files

* WIP:  bring up `MTRDeviceController_Concrete`

* temporary init implementation

* only vend `MTRDeviceController` pointers

not concrete class (`instancetype`) pointers

* add `storedFabricIndex` (currently broken)

* reduce access of internal properties

* move C++-style fabric index and keypairs to protected ivars

* return base class pointer from constructors

rather than `instancetype`

* clean up property synthesis/ivars in concrete

* update merged code

* WIP:  get us building again, plus plan comments

* remove superfluous comments

* Update src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h

* Restyled by clang-format

* move MTRDeviceController protected ivars

to standard `MTRDeviceController.h` header

* `MTRDeviceController_Concrete` isn't public API

thus no `MTR_AVAILABLE`

* remove commented code

* move ivar extension back to internal header

* Fixing TAPI

* Restyled by whitespace

* Restyled by clang-format

---------

Co-authored-by: Justin Wood <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent d95acb4 commit 78ce5b0
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 221 deletions.
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
* Once this returns non-nil, it's the caller's responsibility to call shutdown
* on the controller to avoid leaking it.
*/
- (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
error:(NSError * __autoreleasing *)error MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6));
- (nullable MTRDeviceController *)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
error:(NSError * __autoreleasing *)error MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6));

/**
* If true, the controller has not been shut down yet.
Expand Down
30 changes: 14 additions & 16 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@
using namespace chip::Tracing::DarwinFramework;

@implementation MTRDeviceController {
// Atomic because they can be touched from multiple threads.
std::atomic<chip::FabricIndex> _storedFabricIndex;
std::atomic<std::optional<uint64_t>> _storedCompressedFabricID;

// queue used to serialize all work performed by the MTRDeviceController
dispatch_queue_t _chipWorkQueue;

Expand All @@ -120,8 +116,6 @@ @implementation MTRDeviceController {
chip::Credentials::DefaultDACVerifier * _defaultDACVerifier;
MTRDeviceControllerDelegateBridge * _deviceControllerDelegateBridge;
MTROperationalCredentialsDelegate * _operationalCredentialsDelegate;
MTRP256KeypairBridge _signingKeypairBridge;
MTRP256KeypairBridge _operationalKeypairBridge;
MTRDeviceAttestationDelegateBridge * _deviceAttestationDelegateBridge;
MTRDeviceControllerFactory * _factory;
NSMapTable * _nodeIDToDeviceMap;
Expand All @@ -133,9 +127,22 @@ @implementation MTRDeviceController {
NSMutableArray<MTRServerEndpoint *> * _serverEndpoints;

MTRDeviceStorageBehaviorConfiguration * _storageBehaviorConfiguration;
std::atomic<chip::FabricIndex> _storedFabricIndex;
std::atomic<std::optional<uint64_t>> _storedCompressedFabricID;
MTRP256KeypairBridge _signingKeypairBridge;
MTRP256KeypairBridge _operationalKeypairBridge;
}

- (instancetype)initForSubclasses
{
if (self = [super init]) {
// nothing, as superclass of MTRDeviceController is NSObject
}

return self;
}

- (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters error:(NSError * __autoreleasing *)error
- (nullable MTRDeviceController *)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters error:(NSError * __autoreleasing *)error
{
if (![parameters isKindOfClass:MTRDeviceControllerParameters.class]) {
MTR_LOG_ERROR("Unsupported type of MTRDeviceControllerAbstractParameters: %@", parameters);
Expand Down Expand Up @@ -1575,15 +1582,6 @@ + (void)forceLocalhostAdvertisingOnly

@end

/**
* Shim to allow us to treat an MTRDevicePairingDelegate as an
* MTRDeviceControllerDelegate.
*/
@interface MTRDevicePairingDelegateShim : NSObject <MTRDeviceControllerDelegate>
@property (nonatomic, readonly) id<MTRDevicePairingDelegate> delegate;
- (instancetype)initWithDelegate:(id<MTRDevicePairingDelegate>)delegate;
@end

@implementation MTRDevicePairingDelegateShim
- (instancetype)initWithDelegate:(id<MTRDevicePairingDelegate>)delegate
{
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import <Foundation/Foundation.h>
#import <Matter/MTRCertificates.h>
#import <Matter/MTRDefines.h>
#import <Matter/MTRDeviceController.h>

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -31,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN
@protocol MTROTAProviderDelegate;
@protocol MTRKeypair;

@class MTRDeviceController;
@class MTRDeviceControllerStartupParams;
@class MTRFabricInfo;

Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,9 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
}
}

- (MTRDeviceController * _Nullable)initializeController:(MTRDeviceController *)controller
withParameters:(MTRDeviceControllerParameters *)parameters
error:(NSError * __autoreleasing *)error
- (nullable MTRDeviceController *)initializeController:(MTRDeviceController *)controller
withParameters:(MTRDeviceControllerParameters *)parameters
error:(NSError * __autoreleasing *)error
{
[self _assertCurrentQueueIsNotMatterQueue];

Expand Down
17 changes: 5 additions & 12 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#import <Matter/MTRCommissionableBrowserDelegate.h>
#import <Matter/MTRDefines.h>
#import <Matter/MTRDeviceController.h>
#import <Matter/MTROperationalCertificateIssuer.h>

@class MTRBaseDevice;
Expand All @@ -37,15 +38,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
@protocol MTRDevicePairingDelegate;
@protocol MTRDeviceControllerDelegate;

MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
@interface MTRDeviceController : NSObject

/**
* Controllers are created via the MTRDeviceControllerFactory object or
* initialized via initWithParameters:error:.
*/
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@interface MTRDeviceController_Concrete : MTRDeviceController

/**
* Initialize a device controller with the provided parameters. This will:
Expand All @@ -57,8 +50,8 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
* Once this returns non-nil, it's the caller's responsibility to call shutdown
* on the controller to avoid leaking it.
*/
- (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
error:(NSError * __autoreleasing *)error MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6));
- (nullable MTRDeviceController *)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
error:(NSError * __autoreleasing *)error MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6));

/**
* If true, the controller has not been shut down yet.
Expand Down Expand Up @@ -262,7 +255,7 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))

@end

@interface MTRDeviceController (Deprecated)
@interface MTRDeviceController_Concrete (Deprecated)

@property (readonly, nonatomic, nullable) NSNumber * controllerNodeId MTR_DEPRECATED(
"Please use controllerNodeID", ios(16.1, 16.4), macos(13.0, 13.3), watchos(9.1, 9.4), tvos(16.1, 16.4));
Expand Down
Loading

0 comments on commit 78ce5b0

Please sign in to comment.