Skip to content

Commit

Permalink
Move initWithFactory: and startup: declarations to MTRDeviceControlle…
Browse files Browse the repository at this point in the history
…r_Concrete.

initWithFactory: and startup: are only called from _startDeviceController:,
which was only being called with MTRDeviceController_Concrete instances.

Also fixes the argument type declarations for _startDeviceController: and
initializeController: to make the types compile-time enforced.

The MTRDeviceController implementations of initWithFactory: and startup: are now
obviously unreachable and can be removed.

Some static variables that are now unused have to be removed so the compiler
doesn't complain about them.

Further cleanup of now-unused things will follow in separate PRs.
  • Loading branch information
bzbarsky-apple committed Sep 19, 2024
1 parent 8318df9 commit a911812
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 455 deletions.
410 changes: 0 additions & 410 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ - (void)stopControllerFactory
* The provided controller is expected to have just been allocated and to not be
* initialized yet.
*/
- (MTRDeviceController * _Nullable)_startDeviceController:(MTRDeviceController *)controller
- (MTRDeviceController * _Nullable)_startDeviceController:(MTRDeviceController_Concrete *)controller
startupParams:(id)startupParams
fabricChecker:(MTRDeviceControllerStartupParamsInternal * (^)(FabricTable * fabricTable,
MTRDeviceController * controller,
Expand Down Expand Up @@ -834,7 +834,7 @@ - (BOOL)findMatchingFabric:(FabricTable &)fabricTable
// Returns nil on failure, the input controller on success.
// If the provider has been initialized already, it is not considered as a failure.
//
- (MTRDeviceController * _Nullable)maybeInitializeOTAProvider:(MTRDeviceController * _Nonnull)controller
- (MTRDeviceController_Concrete * _Nullable)maybeInitializeOTAProvider:(MTRDeviceController_Concrete * _Nonnull)controller
{
[self _assertCurrentQueueIsNotMatterQueue];

Expand Down Expand Up @@ -1156,7 +1156,7 @@ - (nullable MTRDeviceController *)_findPendingShutdownControllerWithOperationalC
return nil;
}

- (nullable MTRDeviceController *)initializeController:(MTRDeviceController *)controller
- (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Concrete *)controller
withParameters:(MTRDeviceControllerParameters *)parameters
error:(NSError * __autoreleasing *)error
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#import "MTRDefines_Internal.h"
#import "MTRDeviceControllerFactory.h"
#import "MTRDeviceController_Concrete.h"
#import "MTROperationalBrowser.h"

#include <credentials/FabricTable.h>
Expand Down Expand Up @@ -89,9 +90,9 @@ MTR_DIRECT_MEMBERS
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion;

/**
* Initialize an MTRDeviceController with the given parameters.
* Initialize an MTRDeviceController_Concrete with the given parameters.
*/
- (nullable MTRDeviceController *)initializeController:(MTRDeviceController *)controller
- (nullable MTRDeviceController *)initializeController:(MTRDeviceController_Concrete *)controller
withParameters:(MTRDeviceControllerParameters *)parameters
error:(NSError * __autoreleasing *)error;

Expand Down
30 changes: 30 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,40 @@
#import <Matter/MTRDefines.h>
#import <Matter/MTRDeviceController.h>

#import "MTRDeviceControllerStartupParams_Internal.h"

NS_ASSUME_NONNULL_BEGIN

@interface MTRDeviceController_Concrete : MTRDeviceController

/**
* Init a newly created controller.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (nullable instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
queue:(dispatch_queue_t)queue
storageDelegate:(id<MTRDeviceControllerStorageDelegate> _Nullable)storageDelegate
storageDelegateQueue:(dispatch_queue_t _Nullable)storageDelegateQueue
otaProviderDelegate:(id<MTROTAProviderDelegate> _Nullable)otaProviderDelegate
otaProviderDelegateQueue:(dispatch_queue_t _Nullable)otaProviderDelegateQueue
uniqueIdentifier:(NSUUID *)uniqueIdentifier
concurrentSubscriptionPoolSize:(NSUInteger)concurrentSubscriptionPoolSize
storageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
startSuspended:(BOOL)startSuspended;

/**
* Start a new controller. Returns whether startup succeeded. If this fails,
* it guarantees that it has called controllerShuttingDown on the
* MTRDeviceControllerFactory.
*
* The return value will always match [controller isRunning] for this
* controller.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams;

/**
* Takes an assertion to keep the controller running. If `-[MTRDeviceController shutdown]` is called while an assertion
* is held, the shutdown will be honored only after all assertions are released. Invoking this method multiple times increases
Expand Down
20 changes: 10 additions & 10 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete
return controller;
}

- (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
queue:(dispatch_queue_t)queue
storageDelegate:(id<MTRDeviceControllerStorageDelegate> _Nullable)storageDelegate
storageDelegateQueue:(dispatch_queue_t _Nullable)storageDelegateQueue
otaProviderDelegate:(id<MTROTAProviderDelegate> _Nullable)otaProviderDelegate
otaProviderDelegateQueue:(dispatch_queue_t _Nullable)otaProviderDelegateQueue
uniqueIdentifier:(NSUUID *)uniqueIdentifier
concurrentSubscriptionPoolSize:(NSUInteger)concurrentSubscriptionPoolSize
storageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
startSuspended:(BOOL)startSuspended
- (nullable instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
queue:(dispatch_queue_t)queue
storageDelegate:(id<MTRDeviceControllerStorageDelegate> _Nullable)storageDelegate
storageDelegateQueue:(dispatch_queue_t _Nullable)storageDelegateQueue
otaProviderDelegate:(id<MTROTAProviderDelegate> _Nullable)otaProviderDelegate
otaProviderDelegateQueue:(dispatch_queue_t _Nullable)otaProviderDelegateQueue
uniqueIdentifier:(NSUUID *)uniqueIdentifier
concurrentSubscriptionPoolSize:(NSUInteger)concurrentSubscriptionPoolSize
storageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
startSuspended:(BOOL)startSuspended
{
if (self = [super initForSubclasses:startSuspended]) {
// Make sure our storage is all set up to work as early as possible,
Expand Down
30 changes: 0 additions & 30 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
#import <Matter/MTRP256KeypairBridge.h>

#import <Matter/MTRDefines.h>
#import <Matter/MTRDeviceControllerStartupParams.h>
#import <Matter/MTRDeviceControllerStorageDelegate.h>
#import <Matter/MTRDiagnosticLogsType.h>
#import <Matter/MTROTAProviderDelegate.h>

@class MTRDeviceControllerParameters;
@class MTRDeviceControllerStartupParamsInternal;
@class MTRDeviceControllerFactory;
@class MTRDevice;
@class MTRAsyncWorkQueue;
Expand Down Expand Up @@ -79,18 +77,6 @@ NS_ASSUME_NONNULL_BEGIN

#pragma mark - MTRDeviceControllerFactory methods

/**
* Start a new controller. Returns whether startup succeeded. If this fails,
* it guarantees that it has called controllerShuttingDown on the
* MTRDeviceControllerFactory.
*
* The return value will always match [controller isRunning] for this
* controller.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams;

/**
* Will return chip::kUndefinedFabricIndex if we do not have a fabric index.
*/
Expand Down Expand Up @@ -135,22 +121,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, retain, nullable) NSData * rootPublicKey;

/**
* Init a newly created controller.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
queue:(dispatch_queue_t)queue
storageDelegate:(id<MTRDeviceControllerStorageDelegate> _Nullable)storageDelegate
storageDelegateQueue:(dispatch_queue_t _Nullable)storageDelegateQueue
otaProviderDelegate:(id<MTROTAProviderDelegate> _Nullable)otaProviderDelegate
otaProviderDelegateQueue:(dispatch_queue_t _Nullable)otaProviderDelegateQueue
uniqueIdentifier:(NSUUID *)uniqueIdentifier
concurrentSubscriptionPoolSize:(NSUInteger)concurrentSubscriptionPoolSize
storageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
startSuspended:(BOOL)startSuspended;

/**
* Check whether this controller is running on the given fabric, as represented
* by the provided FabricTable and fabric index. The provided fabric table may
Expand Down

0 comments on commit a911812

Please sign in to comment.