Skip to content

Commit

Permalink
Move some APIs that are only used on MTRDeviceController_Concrete to …
Browse files Browse the repository at this point in the history
…that interface. (project-chip#35728)

Now that MTRDeviceControllerFactory only works with
MTRDeviceController_Concrete, we can move some APIs from
MTRDeviceController_Internal to MTRDeviceController_Concrete.
  • Loading branch information
bzbarsky-apple authored and yyzhong-g committed Dec 11, 2024
1 parent 6f91cf2 commit 9d801d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 69 deletions.
44 changes: 0 additions & 44 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,6 @@ - (void)_controllerResumed
// Subclass hook; nothing to do.
}

- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
{
// TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
// declaration moved to MTRDeviceController_Concrete.
return NO;
}

- (void)clearPendingShutdown
{
// TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
// declaration moved to MTRDeviceController_Concrete.
MTR_ABSTRACT_METHOD();
}

- (void)shutdown
{
MTR_ABSTRACT_METHOD();
Expand Down Expand Up @@ -1085,36 +1071,6 @@ - (nullable NSNumber *)compressedFabricID
return storedValue.has_value() ? @(storedValue.value()) : nil;
}

- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
fabricIndex:(chip::FabricIndex)fabricIndex
isRunning:(BOOL *)isRunning
{
assertChipStackLockedByCurrentThread();

if (![self isRunning]) {
*isRunning = NO;
return CHIP_NO_ERROR;
}

const chip::FabricInfo * otherFabric = fabricTable->FindFabricWithIndex(fabricIndex);
if (!otherFabric) {
// Should not happen...
return CHIP_ERROR_INCORRECT_STATE;
}

if (_cppCommissioner->GetFabricId() != otherFabric->GetFabricId()) {
*isRunning = NO;
return CHIP_NO_ERROR;
}

chip::Crypto::P256PublicKey ourRootPublicKey, otherRootPublicKey;
ReturnErrorOnFailure(_cppCommissioner->GetRootPublicKey(ourRootPublicKey));
ReturnErrorOnFailure(fabricTable->FetchRootPubkey(otherFabric->GetFabricIndex(), otherRootPublicKey));

*isRunning = (ourRootPublicKey.Matches(otherRootPublicKey));
return CHIP_NO_ERROR;
}

- (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
{
auto block = ^{
Expand Down
25 changes: 25 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)deinitFromFactory;

/**
* Check whether this controller is running on the given fabric, as represented
* by the provided FabricTable and fabric index. The provided fabric table may
* not be the same as the fabric table this controller is using. This method
* MUST be called from the Matter work queue.
*
* Might return failure, in which case we don't know whether it's running on the
* given fabric. Otherwise it will set *isRunning to the right boolean value.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
fabricIndex:(chip::FabricIndex)fabricIndex
isRunning:(BOOL *)isRunning;

/**
* 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 All @@ -84,6 +99,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)removeRunAssertion;

/**
* This method returns TRUE if this controller matches the fabric reference and node ID as listed in the parameters.
*/
- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate;

/**
* Clear any pending shutdown request.
*/
- (void)clearPendingShutdown;

@end

NS_ASSUME_NONNULL_END
25 changes: 0 additions & 25 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, retain, nullable) NSData * rootPublicKey;

/**
* Check whether this controller is running on the given fabric, as represented
* by the provided FabricTable and fabric index. The provided fabric table may
* not be the same as the fabric table this controller is using. This method
* MUST be called from the Matter work queue.
*
* Might return failure, in which case we don't know whether it's running on the
* given fabric. Otherwise it will set *isRunning to the right boolean value.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
fabricIndex:(chip::FabricIndex)fabricIndex
isRunning:(BOOL *)isRunning;

/**
* Ensure we have a CASE session to the given node ID and then call the provided
* connection callback. This may be called on any queue (including the Matter
Expand Down Expand Up @@ -265,16 +250,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)directlyGetSessionForNode:(chip::NodeId)nodeID completion:(MTRInternalDeviceConnectionCallback)completion;

/**
* This method returns TRUE if this controller matches the fabric reference and node ID as listed in the parameters.
*/
- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate;

/**
* Clear any pending shutdown request.
*/
- (void)clearPendingShutdown;

@end

/**
Expand Down

0 comments on commit 9d801d8

Please sign in to comment.