Skip to content

Commit 882b55c

Browse files
committed
Add factory reset event
Add `kFactoryReset` event and post it at the beginning of `ScheduleFactoryReset`. This event may be useful to application as it provides clean way to perform additional cleanup steps during factory reset. Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
1 parent c0e580c commit 882b55c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/app/server/Server.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,22 @@ void Server::GenerateShutDownEvent()
616616
PlatformMgr().ScheduleWork([](intptr_t) { PlatformMgr().HandleServerShuttingDown(); });
617617
}
618618

619+
void Server::PostFactoryResetEvent()
620+
{
621+
DeviceLayer::ChipDeviceEvent event;
622+
event.Type = DeviceLayer::DeviceEventType::kFactoryReset;
623+
624+
CHIP_ERROR error = DeviceLayer::PlatformMgr().PostEvent(&event);
625+
if (error != CHIP_NO_ERROR)
626+
{
627+
ChipLogError(AppServer, "Posting kFactoryReset event failed with %" CHIP_ERROR_FORMAT, error.Format());
628+
}
629+
}
630+
619631
void Server::ScheduleFactoryReset()
620632
{
633+
PostFactoryResetEvent();
634+
621635
PlatformMgr().ScheduleWork([](intptr_t) {
622636
// Delete all fabrics and emit Leave event.
623637
GetInstance().GetFabricTable().DeleteAllFabrics();

src/app/server/Server.h

+2
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ class Server
458458
void OnPlatformEvent(const DeviceLayer::ChipDeviceEvent & event);
459459
void CheckServerReadyEvent();
460460

461+
void PostFactoryResetEvent();
462+
461463
static void OnPlatformEventWrapper(const DeviceLayer::ChipDeviceEvent * event, intptr_t);
462464

463465
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS

src/include/platform/CHIPDeviceEvent.h

+5
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ enum PublicEventTypes
255255
* Signals that secure session is established.
256256
*/
257257
kSecureSessionEstablished,
258+
259+
/**
260+
* Signals that factory reset has started.
261+
*/
262+
kFactoryReset,
258263
};
259264

260265
/**

0 commit comments

Comments
 (0)