Use ScheduleLambda in several places in the app to schedule work on Matter stack (#26177)
diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp
index ba75fa7..a1b8db6 100644
--- a/examples/lighting-app/qpg/src/AppTask.cpp
+++ b/examples/lighting-app/qpg/src/AppTask.cpp
@@ -120,16 +120,21 @@
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK:
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE:
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY:
- (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
- identify);
+ SystemLayer().ScheduleLambda([identify] {
+ (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
+ identify);
+ });
break;
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT:
- (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
- (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted,
- identify);
+ SystemLayer().ScheduleLambda([identify] {
+ (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
+ (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted,
+ identify);
+ });
break;
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT:
- (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
+ SystemLayer().ScheduleLambda(
+ [identify] { (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify); });
sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
break;
default:
@@ -438,7 +443,7 @@
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
- chip::Server::GetInstance().ScheduleFactoryReset();
+ SystemLayer().ScheduleLambda([] { chip::Server::GetInstance().ScheduleFactoryReset(); });
}
}
@@ -515,24 +520,28 @@
void AppTask::CancelTimer()
{
- chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
- mFunctionTimerActive = false;
+ SystemLayer().ScheduleLambda([this] {
+ chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
+ this->mFunctionTimerActive = false;
+ });
}
void AppTask::StartTimer(uint32_t aTimeoutInMs)
{
- CHIP_ERROR err;
+ SystemLayer().ScheduleLambda([aTimeoutInMs, this] {
+ CHIP_ERROR err;
+ chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
+ err =
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(aTimeoutInMs), TimerEventHandler, this);
+ SuccessOrExit(err);
- chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
- err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(aTimeoutInMs), TimerEventHandler, this);
- SuccessOrExit(err);
-
- mFunctionTimerActive = true;
-exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "StartTimer failed %s: ", chip::ErrorStr(err));
- }
+ this->mFunctionTimerActive = true;
+ exit:
+ if (err != CHIP_NO_ERROR)
+ {
+ ChipLogError(NotSpecified, "StartTimer failed %s: ", chip::ErrorStr(err));
+ }
+ });
}
void AppTask::ActionInitiated(LightingManager::Action_t aAction)
@@ -599,22 +608,24 @@
*/
void AppTask::UpdateClusterState(void)
{
- ChipLogProgress(NotSpecified, "UpdateClusterState");
+ SystemLayer().ScheduleLambda([] {
+ ChipLogProgress(NotSpecified, "UpdateClusterState");
- // Write the new on/off value
- EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().IsTurnedOn());
+ // Write the new on/off value
+ EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().IsTurnedOn());
- if (status != EMBER_ZCL_STATUS_SUCCESS)
- {
- ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
- }
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
+ }
- // Write new level value
- status = Clusters::LevelControl::Attributes::CurrentLevel::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().GetLevel());
- if (status != EMBER_ZCL_STATUS_SUCCESS)
- {
- ChipLogError(NotSpecified, "ERR: updating level %x", status);
- }
+ // Write new level value
+ status = Clusters::LevelControl::Attributes::CurrentLevel::Set(QPG_LIGHT_ENDPOINT_ID, LightingMgr().GetLevel());
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ ChipLogError(NotSpecified, "ERR: updating level %x", status);
+ }
+ });
}
void AppTask::UpdateLEDs(void)
@@ -697,7 +708,7 @@
}
else
{
- ConfigurationMgr().InitiateFactoryReset();
+ SystemLayer().ScheduleLambda([] { ConfigurationMgr().InitiateFactoryReset(); });
}
}
diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp
index dc00f67..7ffd23a 100644
--- a/examples/lock-app/qpg/src/AppTask.cpp
+++ b/examples/lock-app/qpg/src/AppTask.cpp
@@ -427,10 +427,14 @@
if (!ConnectivityMgr().IsThreadProvisioned())
{
// Enable BLE advertisements and pairing window
- if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() == CHIP_NO_ERROR)
- {
- ChipLogProgress(NotSpecified, "BLE advertising started. Waiting for Pairing.");
- }
+ SystemLayer().ScheduleLambda([] {
+ CHIP_ERROR err;
+ if ((err = chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow()) ==
+ CHIP_NO_ERROR)
+ {
+ ChipLogProgress(NotSpecified, "BLE advertising started. Waiting for Pairing.");
+ }
+ });
}
else
{
@@ -466,24 +470,28 @@
void AppTask::CancelTimer()
{
- chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
- mFunctionTimerActive = false;
+ SystemLayer().ScheduleLambda([this] {
+ chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
+ this->mFunctionTimerActive = false;
+ });
}
void AppTask::StartTimer(uint32_t aTimeoutInMs)
{
- CHIP_ERROR err;
+ SystemLayer().ScheduleLambda([aTimeoutInMs, this] {
+ CHIP_ERROR err;
+ chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
+ err =
+ chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(aTimeoutInMs), TimerEventHandler, this);
+ SuccessOrExit(err);
- chip::DeviceLayer::SystemLayer().CancelTimer(TimerEventHandler, this);
- err = chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(aTimeoutInMs), TimerEventHandler, this);
- SuccessOrExit(err);
-
- mFunctionTimerActive = true;
-exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(NotSpecified, "StartTimer failed %s: ", chip::ErrorStr(err));
- }
+ this->mFunctionTimerActive = true;
+ exit:
+ if (err != CHIP_NO_ERROR)
+ {
+ ChipLogError(NotSpecified, "StartTimer failed %s: ", chip::ErrorStr(err));
+ }
+ });
}
void AppTask::ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor)
@@ -577,14 +585,16 @@
using namespace chip::app::Clusters;
auto newValue = BoltLockMgr().IsUnlocked() ? DoorLock::DlLockState::kUnlocked : DoorLock::DlLockState::kLocked;
- ChipLogProgress(NotSpecified, "UpdateClusterState");
+ SystemLayer().ScheduleLambda([newValue] {
+ ChipLogProgress(NotSpecified, "UpdateClusterState");
- EmberAfStatus status = DoorLock::Attributes::LockState::Set(QPG_LOCK_ENDPOINT_ID, newValue);
+ EmberAfStatus status = DoorLock::Attributes::LockState::Set(QPG_LOCK_ENDPOINT_ID, newValue);
- if (status != EMBER_ZCL_STATUS_SUCCESS)
- {
- ChipLogError(NotSpecified, "ERR: updating DoorLock %x", status);
- }
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ ChipLogError(NotSpecified, "ERR: updating DoorLock %x", status);
+ }
+ });
}
void AppTask::UpdateLEDs(void)