Skip to content

Commit

Permalink
Allow MTRDeviceControllerFactory to store a more generic storage dele…
Browse files Browse the repository at this point in the history
…gate.

We might not always use MTRPersistentStorageDelegateBridge.
  • Loading branch information
bzbarsky-apple committed Jul 28, 2023
1 parent 0be73c8 commit ef02cae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ @interface MTRDeviceControllerFactory ()

@property (atomic, readonly) dispatch_queue_t chipWorkQueue;
@property (readonly) DeviceControllerFactory * controllerFactory;
@property (readonly) MTRPersistentStorageDelegateBridge * persistentStorageDelegateBridge;
@property (readonly) PersistentStorageDelegate * persistentStorageDelegate;
@property (readonly) MTRAttestationTrustStoreBridge * attestationTrustStoreBridge;
@property (readonly) MTROTAProviderDelegateBridge * otaProviderDelegateBridge;
@property (readonly) Crypto::RawKeySessionKeystore * sessionKeystore;
Expand Down Expand Up @@ -273,9 +273,9 @@ - (void)cleanupStartupObjects
_opCertStore = nullptr;
}

if (_persistentStorageDelegateBridge) {
delete _persistentStorageDelegateBridge;
_persistentStorageDelegateBridge = nullptr;
if (_persistentStorageDelegate) {
delete _persistentStorageDelegate;
_persistentStorageDelegate = nullptr;
}
}

Expand All @@ -291,7 +291,7 @@ - (void)cleanupStartupObjects
__block BOOL listFilled = NO;
auto fillListBlock = ^{
FabricTable fabricTable;
CHIP_ERROR err = fabricTable.Init({ .storage = self->_persistentStorageDelegateBridge,
CHIP_ERROR err = fabricTable.Init({ .storage = self->_persistentStorageDelegate,
.operationalKeystore = self->_keystore,
.opCertStore = self->_opCertStore });
if (err != CHIP_NO_ERROR) {
Expand Down Expand Up @@ -348,8 +348,8 @@ - (BOOL)startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParams

[MTRControllerAccessControl init];

_persistentStorageDelegateBridge = new MTRPersistentStorageDelegateBridge(startupParams.storage);
if (_persistentStorageDelegateBridge == nil) {
_persistentStorageDelegate = new MTRPersistentStorageDelegateBridge(startupParams.storage);
if (_persistentStorageDelegate == nil) {
MTR_LOG_ERROR("Error: %@", kErrorPersistentStorageInit);
errorCode = CHIP_ERROR_NO_MEMORY;
return;
Expand Down Expand Up @@ -415,7 +415,7 @@ - (BOOL)startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParams
return;
}

errorCode = _keystore->Init(_persistentStorageDelegateBridge);
errorCode = _keystore->Init(_persistentStorageDelegate);
if (errorCode != CHIP_NO_ERROR) {
MTR_LOG_ERROR("Error: %@", kErrorKeystoreInit);
return;
Expand All @@ -429,7 +429,7 @@ - (BOOL)startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParams
return;
}

errorCode = _opCertStore->Init(_persistentStorageDelegateBridge);
errorCode = _opCertStore->Init(_persistentStorageDelegate);
if (errorCode != CHIP_NO_ERROR) {
MTR_LOG_ERROR("Error: %@", kErrorCertStoreInit);
return;
Expand Down Expand Up @@ -482,7 +482,7 @@ - (BOOL)startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParams

params.groupDataProvider = _groupDataProvider;
params.sessionKeystore = _sessionKeystore;
params.fabricIndependentStorage = _persistentStorageDelegateBridge;
params.fabricIndependentStorage = _persistentStorageDelegate;
params.operationalKeystore = _keystore;
params.opCertStore = _opCertStore;
params.certificateValidityPolicy = _certificateValidityPolicy;
Expand Down Expand Up @@ -788,7 +788,7 @@ - (BOOL)findMatchingFabric:(FabricTable &)fabricTable
assertChipStackLockedByCurrentThread();

CHIP_ERROR err = fabricTable.Init(
{ .storage = _persistentStorageDelegateBridge, .operationalKeystore = _keystore, .opCertStore = _opCertStore });
{ .storage = _persistentStorageDelegate, .operationalKeystore = _keystore, .opCertStore = _opCertStore });
if (err != CHIP_NO_ERROR) {
MTR_LOG_ERROR("Can't initialize fabric table: %s", ErrorStr(err));
return NO;
Expand Down Expand Up @@ -937,9 +937,9 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
}
}

- (MTRPersistentStorageDelegateBridge *)storageDelegateBridge
- (PersistentStorageDelegate *)storageDelegate
{
return _persistentStorageDelegateBridge;
return _persistentStorageDelegate;
}

- (Credentials::GroupDataProvider *)groupData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

#import "MTRDeviceControllerFactory.h"

#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/core/DataModelTypes.h>
#include <lib/core/PeerId.h>

class MTRPersistentStorageDelegateBridge;

namespace chip {
namespace Credentials {
class GroupDataProvider;
Expand All @@ -54,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)operationalInstanceAdded:(chip::PeerId &)operationalID;

@property (readonly) MTRPersistentStorageDelegateBridge * storageDelegateBridge;
@property (readonly) chip::PersistentStorageDelegate * storageDelegate;
@property (readonly) chip::Credentials::GroupDataProvider * groupData;
@property (readonly) chip::Credentials::DeviceAttestationVerifier * deviceAttestationVerifier;
@end
Expand Down

0 comments on commit ef02cae

Please sign in to comment.