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

[Fabric-Bridge] Replace ScheduleWork with ScheduleLambda #35949

Merged
merged 4 commits into from
Oct 8, 2024
Merged
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
109 changes: 38 additions & 71 deletions examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,78 +24,31 @@
#include <app/reporting/reporting.h>
#include <platform/CHIPDeviceLayer.h>

namespace {

struct ActiveChangeEventWorkData
{
chip::EndpointId mEndpointId;
uint32_t mPromisedActiveDuration;
};

struct ReportAttributeChangedWorkData
{
chip::EndpointId mEndpointId;
bool mWindowChanged = false;
bool mFabricIndexChanged = false;
bool mVendorChanged = false;
};

void ActiveChangeEventWork(intptr_t arg)
{
ActiveChangeEventWorkData * data = reinterpret_cast<ActiveChangeEventWorkData *>(arg);

chip::app::Clusters::BridgedDeviceBasicInformation::Events::ActiveChanged::Type event{};
event.promisedActiveDuration = data->mPromisedActiveDuration;
chip::EventNumber eventNumber = 0;

CHIP_ERROR err = chip::app::LogEvent(event, data->mEndpointId, eventNumber);
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "LogEvent for ActiveChanged failed %s", err.AsString());
}
chip::Platform::Delete(data);
}

void ReportAttributeChangedWork(intptr_t arg)
{
ReportAttributeChangedWorkData * data = reinterpret_cast<ReportAttributeChangedWorkData *>(arg);

if (data->mWindowChanged)
{
MatterReportingAttributeChangeCallback(data->mEndpointId, chip::app::Clusters::AdministratorCommissioning::Id,
chip::app::Clusters::AdministratorCommissioning::Attributes::WindowStatus::Id);
}
if (data->mFabricIndexChanged)
{
MatterReportingAttributeChangeCallback(data->mEndpointId, chip::app::Clusters::AdministratorCommissioning::Id,
chip::app::Clusters::AdministratorCommissioning::Attributes::AdminFabricIndex::Id);
}
if (data->mVendorChanged)
{
MatterReportingAttributeChangeCallback(data->mEndpointId, chip::app::Clusters::AdministratorCommissioning::Id,
chip::app::Clusters::AdministratorCommissioning::Attributes::AdminVendorId::Id);
}
chip::Platform::Delete(data);
}

} // namespace

using namespace chip;
using namespace chip::app::Clusters::Actions;

BridgedDevice::BridgedDevice(chip::ScopedNodeId scopedNodeId)
BridgedDevice::BridgedDevice(ScopedNodeId scopedNodeId)
{
mReachable = false;
mScopedNodeId = scopedNodeId;
mEndpointId = chip::kInvalidEndpointId;
mEndpointId = kInvalidEndpointId;
}

void BridgedDevice::LogActiveChangeEvent(uint32_t promisedActiveDurationMs)
{
ActiveChangeEventWorkData * workdata = chip::Platform::New<ActiveChangeEventWorkData>();
workdata->mEndpointId = mEndpointId;
workdata->mPromisedActiveDuration = promisedActiveDurationMs;

chip::DeviceLayer::PlatformMgr().ScheduleWork(ActiveChangeEventWork, reinterpret_cast<intptr_t>(workdata));
EndpointId endpointId = mEndpointId;

DeviceLayer::SystemLayer().ScheduleLambda([endpointId, promisedActiveDurationMs]() {
app::Clusters::BridgedDeviceBasicInformation::Events::ActiveChanged::Type event{};
event.promisedActiveDuration = promisedActiveDurationMs;
EventNumber eventNumber = 0;

CHIP_ERROR err = app::LogEvent(event, endpointId, eventNumber);
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "LogEvent for ActiveChanged failed %s", err.AsString());
}
});
}

void BridgedDevice::SetReachable(bool reachable)
Expand All @@ -114,15 +67,29 @@ void BridgedDevice::SetReachable(bool reachable)

void BridgedDevice::SetAdminCommissioningAttributes(const AdminCommissioningAttributes & aAdminCommissioningAttributes)
{
ReportAttributeChangedWorkData * workdata = chip::Platform::New<ReportAttributeChangedWorkData>();

workdata->mEndpointId = mEndpointId;
workdata->mWindowChanged =
EndpointId endpointId = mEndpointId;
bool windowChanged =
(aAdminCommissioningAttributes.commissioningWindowStatus != mAdminCommissioningAttributes.commissioningWindowStatus);
workdata->mFabricIndexChanged =
(aAdminCommissioningAttributes.openerFabricIndex != mAdminCommissioningAttributes.openerFabricIndex);
workdata->mVendorChanged = (aAdminCommissioningAttributes.openerVendorId != mAdminCommissioningAttributes.openerVendorId);
bool fabricIndexChanged = (aAdminCommissioningAttributes.openerFabricIndex != mAdminCommissioningAttributes.openerFabricIndex);
bool vendorChanged = (aAdminCommissioningAttributes.openerVendorId != mAdminCommissioningAttributes.openerVendorId);

mAdminCommissioningAttributes = aAdminCommissioningAttributes;
chip::DeviceLayer::PlatformMgr().ScheduleWork(ReportAttributeChangedWork, reinterpret_cast<intptr_t>(workdata));

DeviceLayer::SystemLayer().ScheduleLambda([endpointId, windowChanged, fabricIndexChanged, vendorChanged]() {
if (windowChanged)
{
MatterReportingAttributeChangeCallback(endpointId, app::Clusters::AdministratorCommissioning::Id,
app::Clusters::AdministratorCommissioning::Attributes::WindowStatus::Id);
}
if (fabricIndexChanged)
{
MatterReportingAttributeChangeCallback(endpointId, app::Clusters::AdministratorCommissioning::Id,
app::Clusters::AdministratorCommissioning::Attributes::AdminFabricIndex::Id);
}
if (vendorChanged)
{
MatterReportingAttributeChangeCallback(endpointId, app::Clusters::AdministratorCommissioning::Id,
app::Clusters::AdministratorCommissioning::Attributes::AdminVendorId::Id);
}
});
}
Loading