Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the storage delegate's queue from the storage bridge #6519

Merged
merged 3 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ void CHIPSetNextAvailableDeviceID(uint64_t id)

CHIPDeviceController * InitializeCHIP(void)
{
static dispatch_queue_t callbackQueue;
static CHIPToolPersistentStorageDelegate * storage = nil;
static dispatch_once_t onceToken;
CHIPDeviceController * controller = [CHIPDeviceController sharedController];
dispatch_once(&onceToken, ^{
storage = [[CHIPToolPersistentStorageDelegate alloc] init];
callbackQueue = dispatch_queue_create("com.chip.persistentstorage.callback", DISPATCH_QUEUE_SERIAL);
[controller startup:storage queue:callbackQueue];
[controller startup:storage];
});

return controller;
Expand Down
4 changes: 1 addition & 3 deletions src/darwin/Framework/CHIP/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ NS_ASSUME_NONNULL_BEGIN
* check if the stack needs to be started up.
*
* @param[in] storageDelegate The delegate for persistent storage
*
* @param[in] queue The queue on which the storage callbacks will be delivered
*/
- (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate queue:(_Nullable dispatch_queue_t)queue;
- (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate;

/**
* Shutdown the CHIP Stack. Repeated calls to shutdown without calls to startup in between are NO-OPs.
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/CHIPDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ - (BOOL)shutdown
return YES;
}

- (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate queue:(_Nullable dispatch_queue_t)queue
- (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate
{
__block BOOL commissionerInitialized = NO;
dispatch_sync(_chipWorkQueue, ^{
Expand All @@ -133,7 +133,7 @@ - (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate que

CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE;

_persistentStorageDelegateBridge->setFrameworkDelegate(storageDelegate, queue);
_persistentStorageDelegateBridge->setFrameworkDelegate(storageDelegate);
// initialize NodeID if needed
[self _getControllerNodeId];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CHIPPersistentStorageDelegateBridge : public chip::PersistentStorageDelega
CHIPPersistentStorageDelegateBridge();
~CHIPPersistentStorageDelegateBridge();

void setFrameworkDelegate(_Nullable id<CHIPPersistentStorageDelegate> delegate, _Nullable dispatch_queue_t queue);
void setFrameworkDelegate(_Nullable id<CHIPPersistentStorageDelegate> delegate);

CHIP_ERROR SyncGetKeyValue(const char * key, void * buffer, uint16_t & size) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,13 @@

CHIPPersistentStorageDelegateBridge::~CHIPPersistentStorageDelegateBridge(void) {}

void CHIPPersistentStorageDelegateBridge::setFrameworkDelegate(
_Nullable id<CHIPPersistentStorageDelegate> delegate, _Nullable dispatch_queue_t queue)
void CHIPPersistentStorageDelegateBridge::setFrameworkDelegate(_Nullable id<CHIPPersistentStorageDelegate> delegate)
{
dispatch_async(mWorkQueue, ^{
if (delegate && queue) {
if (delegate) {
mDelegate = delegate;
mQueue = queue;
} else {
mDelegate = nil;
mQueue = nil;
}
});
}
Expand Down Expand Up @@ -125,10 +122,8 @@
NSLog(@"PersistentStorageDelegate Set Key %@", keyString);

id<CHIPPersistentStorageDelegate> strongDelegate = mDelegate;
if (strongDelegate && mQueue) {
dispatch_sync(mQueue, ^{
[strongDelegate CHIPSetKeyValue:keyString value:valueString];
});
if (strongDelegate) {
[strongDelegate CHIPSetKeyValue:keyString value:valueString];
} else {
[mDefaultPersistentStorage setObject:valueString forKey:keyString];
}
Expand All @@ -148,10 +143,8 @@
NSLog(@"PersistentStorageDelegate Delete Key: %@", keyString);

id<CHIPPersistentStorageDelegate> strongDelegate = mDelegate;
if (strongDelegate && mQueue) {
dispatch_sync(mQueue, ^{
[strongDelegate CHIPDeleteKeyValue:keyString];
});
if (strongDelegate) {
[strongDelegate CHIPDeleteKeyValue:keyString];
} else {
[mDefaultPersistentStorage removeObjectForKey:keyString];
}
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIPTests/CHIPClustersTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (void)testInitStack
[controller setListenPort:kLocalPort];
[controller setPairingDelegate:pairing queue:callbackQueue];

BOOL started = [controller startup:nil queue:nil];
BOOL started = [controller startup:nil];
XCTAssertTrue(started);

NSError * error;
Expand Down