Skip to content

Commit

Permalink
Broadcast* function to Notify*
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Jan 19, 2024
1 parent b582fab commit 89bdff0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
#if CHIP_CONFIG_ENABLE_ICD_SERVER
// Temporarily claim network activity, until we implement a "user trigger" reason for ICD wakeups.
PlatformMgr().LockChipStack();
ICDNotifier::GetInstance().BroadcastNetworkActivityNotification();
ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
PlatformMgr().UnlockChipStack();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class IcdManagementFabricDelegate : public FabricTable::Delegate
uint16_t supported_clients = mICDConfigurationData->GetClientsSupportedPerFabric();
ICDMonitoringTable table(*mStorage, fabricIndex, supported_clients, mSymmetricKeystore);
table.RemoveAll();
ICDNotifier::GetInstance().BroadcastICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
}

private:
Expand Down Expand Up @@ -337,13 +337,13 @@ Status ICDManagementServer::StayActiveRequest(FabricIndex fabricIndex)
{
// TODO: Implementent stay awake logic for end device
// https://github.com/project-chip/connectedhomeip/issues/24259
ICDNotifier::GetInstance().BroadcastICDManagementEvent(ICDListener::ICDManagementEvents::kStayActiveRequestReceived);
ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kStayActiveRequestReceived);
return InteractionModel::Status::UnsupportedCommand;
}

void ICDManagementServer::TriggerICDMTableUpdatedEvent()
{
ICDNotifier::GetInstance().BroadcastICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
}

void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore,
Expand Down
6 changes: 3 additions & 3 deletions src/app/icd/ICDCheckInSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ void ICDCheckInSender::OnNodeAddressResolved(const PeerId & peerId, const Addres
ChipLogError(AppServer, "Failed to send the ICD Check-In message");
}

ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(ICDListener::KeepActiveFlag::kCheckInInProgress);
ICDNotifier::GetInstance().NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlag::kCheckInInProgress);
}

void ICDCheckInSender::OnNodeAddressResolutionFailed(const PeerId & peerId, CHIP_ERROR reason)
{
ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(ICDListener::KeepActiveFlag::kCheckInInProgress);
ICDNotifier::GetInstance().NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlag::kCheckInInProgress);
ChipLogProgress(AppServer, "Node Address resolution failed for ICD Check-In with Node ID " ChipLogFormatX64,
ChipLogValueX64(peerId.GetNodeId()));
}
Expand Down Expand Up @@ -110,7 +110,7 @@ CHIP_ERROR ICDCheckInSender::RequestResolve(ICDMonitoringEntry & entry, FabricTa

if (err == CHIP_NO_ERROR)
{
ICDNotifier::GetInstance().BroadcastActiveRequestNotification(ICDListener::KeepActiveFlag::kCheckInInProgress);
ICDNotifier::GetInstance().NotifyActiveRequestNotification(ICDListener::KeepActiveFlag::kCheckInInProgress);
}

return err;
Expand Down
10 changes: 5 additions & 5 deletions src/app/icd/ICDNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ICDNotifier::Unsubscribe(ICDListener * subscriber)
}
}

void ICDNotifier::BroadcastNetworkActivityNotification()
void ICDNotifier::NotifyNetworkActivityNotification()
{
for (auto subscriber : mSubscribers)
{
Expand All @@ -67,7 +67,7 @@ void ICDNotifier::BroadcastNetworkActivityNotification()
}
}

void ICDNotifier::BroadcastActiveRequestNotification(ICDListener::KeepActiveFlags request)
void ICDNotifier::NotifyActiveRequestNotification(ICDListener::KeepActiveFlags request)
{
for (auto subscriber : mSubscribers)
{
Expand All @@ -78,7 +78,7 @@ void ICDNotifier::BroadcastActiveRequestNotification(ICDListener::KeepActiveFlag
}
}

void ICDNotifier::BroadcastActiveRequestWithdrawal(ICDListener::KeepActiveFlags request)
void ICDNotifier::NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlags request)
{
for (auto subscriber : mSubscribers)
{
Expand All @@ -89,7 +89,7 @@ void ICDNotifier::BroadcastActiveRequestWithdrawal(ICDListener::KeepActiveFlags
}
}

void ICDNotifier::BroadcastICDManagementEvent(ICDListener::ICDManagementEvents event)
void ICDNotifier::NotifyICDManagementEvent(ICDListener::ICDManagementEvents event)
{
for (auto subscriber : mSubscribers)
{
Expand All @@ -100,7 +100,7 @@ void ICDNotifier::BroadcastICDManagementEvent(ICDListener::ICDManagementEvents e
}
}

void ICDNotifier::BroadcastSubscriptionReport()
void ICDNotifier::NotifySubscriptionReport()
{
for (auto subscriber : mSubscribers)
{
Expand Down
22 changes: 11 additions & 11 deletions src/app/icd/ICDNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,37 @@ class ICDListener
virtual ~ICDListener() {}

/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls BroadcastNetworkActivityNotification.
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifyNetworkActivityNotification.
* It notifies the subscriber that a NetworkActivity occurred. For example, a message sent or received.
*/
virtual void OnNetworkActivity() = 0;

/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls BroadcastActiveRequestNotification.
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifyActiveRequestNotification.
* It informs the subscriber that there is a need to place and keep the ICD in its Active Mode.
*
* @param request : Identity the request source
*/
virtual void OnKeepActiveRequest(KeepActiveFlags request) = 0;

/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls BroadcastActiveRequestWithdrawal.
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifyActiveRequestWithdrawal.
* It informs the subscriber that a previous request no longer needs ICD to maintain its Active Mode.
*
* @param request : The request source
*/
virtual void OnActiveRequestWithdrawal(KeepActiveFlags request) = 0;

/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls BroadcastICDManagementEvent.
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifyICDManagementEvent.
* It informs the subscriber that an ICD Management action has happened and needs to be processed
*
* @param event : The event type
*/
virtual void OnICDManagementServerEvent(ICDManagementEvents event) = 0;

/**
* @brief This function is called for all subscribers of the ICDNoitifier when it calls BroadcastSubscriptionReport.
* @brief This function is called for all subscribers of the ICDNoitifier when it calls NotifySubscriptionReport.
* It informs the subscriber that a subscription report data is being sent.
*/
virtual void OnSubscriptionReport() = 0;
Expand All @@ -106,15 +106,15 @@ class ICDNotifier
* For thread-safety reason (mostly of the ICDManager, which is a full time subscriber),
* Those functions require to be called from the Chip Task Context, or by holding the chip stack lock.
*/
void BroadcastNetworkActivityNotification();
void BroadcastActiveRequestNotification(ICDListener::KeepActiveFlags request);
void BroadcastActiveRequestWithdrawal(ICDListener::KeepActiveFlags request);
void BroadcastICDManagementEvent(ICDListener::ICDManagementEvents event);
void BroadcastSubscriptionReport();
void NotifyNetworkActivityNotification();
void NotifyActiveRequestNotification(ICDListener::KeepActiveFlags request);
void NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlags request);
void NotifyICDManagementEvent(ICDListener::ICDManagementEvents event);
void NotifySubscriptionReport();

inline void BroadcastActiveRequest(ICDListener::KeepActiveFlags request, bool notify)
{
(notify) ? BroadcastActiveRequestNotification(request) : BroadcastActiveRequestWithdrawal(request);
(notify) ? NotifyActiveRequestNotification(request) : NotifyActiveRequestWithdrawal(request);
}

static ICDNotifier & GetInstance() { return sICDNotifier; }
Expand Down
2 changes: 1 addition & 1 deletion src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
#if CHIP_CONFIG_ENABLE_ICD_SERVER
// Notify the ICDManager that we are about to send a subscription report before we prepare the Report payload.
// This allows the ICDManager to trigger any necessary updates and have the information in the report about to be sent.
app::ICDNotifier::GetInstance().BroadcastSubscriptionReport();
app::ICDNotifier::GetInstance().NotifySubscriptionReport();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

SubscriptionId subscriptionId = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ void CommissioningWindowManager::UpdateWindowStatus(CommissioningWindowStatusEnu
app::ICDListener::KeepActiveFlags request = app::ICDListener::KeepActiveFlag::kCommissioningWindowOpen;
if (mWindowStatus != CommissioningWindowStatusEnum::kWindowNotOpen)
{
app::ICDNotifier::GetInstance().BroadcastActiveRequestNotification(request);
app::ICDNotifier::GetInstance().NotifyActiveRequestNotification(request);
}
else
{
app::ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(request);
app::ICDNotifier::GetInstance().NotifyActiveRequestWithdrawal(request);
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
}
Expand Down
36 changes: 18 additions & 18 deletions src/app/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class TestICDManager
// Events updating the Operation to Active mode can extend the current active mode time by 1 Active mode threshold.
// Kick an active Threshold just before the end of the Active interval and validate that the active mode is extended.
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() - 1);
ICDNotifier::GetInstance().BroadcastNetworkActivityNotification();
ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeThresholdMs() / 2);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeThresholdMs());
Expand All @@ -168,45 +168,45 @@ class TestICDManager
ICDNotifier notifier = ICDNotifier::GetInstance();

// Setting a requirement will transition the ICD to active mode.
notifier.BroadcastActiveRequestNotification(ActiveFlag::kCommissioningWindowOpen);
notifier.NotifyActiveRequestNotification(ActiveFlag::kCommissioningWindowOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Advance time so active mode interval expires.
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
// Requirement flag still set. We stay in active mode
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Remove requirement. we should directly transition to idle mode.
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kCommissioningWindowOpen);
notifier.NotifyActiveRequestWithdrawal(ActiveFlag::kCommissioningWindowOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

notifier.BroadcastActiveRequestNotification(ActiveFlag::kFailSafeArmed);
notifier.NotifyActiveRequestNotification(ActiveFlag::kFailSafeArmed);
// Requirement will transition us to active mode.
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time, but by less than the active mode interval and remove the requirement.
// We should stay in active mode.
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() / 2);
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
notifier.NotifyActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time again, The activemode interval is completed.
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

// Set two requirements
notifier.BroadcastActiveRequestNotification(ActiveFlag::kFailSafeArmed);
notifier.BroadcastActiveRequestNotification(ActiveFlag::kExchangeContextOpen);
notifier.NotifyActiveRequestNotification(ActiveFlag::kFailSafeArmed);
notifier.NotifyActiveRequestNotification(ActiveFlag::kExchangeContextOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// advance time so the active mode interval expires.
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
// A requirement flag is still set. We stay in active mode.
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// remove 1 requirement. Active mode is maintained
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
notifier.NotifyActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// remove the last requirement
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kExchangeContextOpen);
notifier.NotifyActiveRequestWithdrawal(ActiveFlag::kExchangeContextOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
}

Expand All @@ -228,7 +228,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::SIT);

// Trigger a "fake" register, ICDManager shoudl remain in SIT mode
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager stayed in SIT mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::SIT);
Expand All @@ -245,7 +245,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == table1.Set(0, entry1));

// Trigger register event after first entry was added
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is now in the LIT operating mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::LIT);
Expand All @@ -258,7 +258,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == table1.Set(1, entry2));

// Trigger register event after first entry was added
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is now in the LIT operating mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::LIT);
Expand All @@ -271,7 +271,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == table2.Set(0, entry3));

// Trigger register event after first entry was added
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is now in the LIT operating mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::LIT);
Expand All @@ -287,7 +287,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == table2.RemoveAll());

// Trigger register event after fabric was cleared
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is still in the LIT operating mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::LIT);
Expand All @@ -296,7 +296,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == table1.Remove(1));

// Trigger register event after fabric was cleared
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is still in the LIT operating mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::LIT);
Expand All @@ -307,7 +307,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, table2.IsEmpty());

// Trigger register event after fabric was cleared
notifier.BroadcastICDManagementEvent(ICDMEvent::kTableUpdated);
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is still in the LIT operating mode
NL_TEST_ASSERT(aSuite, ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::SIT);
Expand All @@ -331,11 +331,11 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

// Trigger a subscription report
notifier.BroadcastSubscriptionReport();
notifier.NotifySubscriptionReport();
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Trigger another subscription report - active time should not be increased
notifier.BroadcastSubscriptionReport();
notifier.NotifySubscriptionReport();

// Advance time so active mode interval expires.
AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
Expand Down
Loading

0 comments on commit 89bdff0

Please sign in to comment.