Skip to content

Commit

Permalink
[ICD-server] Replace the event/queue based logic with a notifier (#29546
Browse files Browse the repository at this point in the history
)

* Replace ICDEventManager and its event queue logic by the ICDNotifier  (Subject/observer pattern). Tweak some ICDManager logic to accound for SIT with active interval and active threshold of 0 ms

* Use a pointer array instead of vector for the notifier subscribers

* Restyled by clang-format

* Restyled by gn

* Gate the check for chiplock with CHIP_STACK_LOCK_TRACKING_ENABLED

* Rename a class,functions of the ICDNotifier for clarity. Remove taking the chip stack lock. We will assert if we don't have it (caller responsability). Add briefs and comments. move ICDNotifier implementation to a cpp file

* Restyled by whitespace

* Fix returned error for ICDNotifier subscribe

* Rename ICDSubscriber class to ICDListener, Update comment with Boris's suggestion

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Nov 19, 2023
1 parent 71f0cbc commit 1756386
Show file tree
Hide file tree
Showing 21 changed files with 349 additions and 389 deletions.
14 changes: 7 additions & 7 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#endif // DISPLAY_ENABLED

#include "SilabsDeviceDataProvider.h"
#include <app/icd/ICDNotifier.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand Down Expand Up @@ -505,13 +506,12 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
else
{
SILABS_LOG("Network is already provisioned, Ble advertissement not enabled");
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kAppWakeUpEvent;
CHIP_ERROR err = DeviceLayer::PlatformMgr().PostEvent(&event);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to post App wake up Event event %" CHIP_ERROR_FORMAT, err.Format());
}
#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();
PlatformMgr().UnlockChipStack();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
}
}
else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset)
Expand Down
4 changes: 3 additions & 1 deletion src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ buildconfig_header("app_buildconfig") {
"CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}",
"CHIP_CONFIG_ENABLE_READ_CLIENT=${chip_enable_read_client}",
"ICD_REPORT_ON_ENTER_ACTIVE_MODE=${chip_report_on_active_mode}",
"ICD_MAX_NOTIFICATION_SUBSCRIBERS=${icd_max_notification_subscribers}",
]
}

Expand Down Expand Up @@ -236,6 +237,7 @@ static_library("app") {
public_deps = [
":app_config",
"${chip_root}/src/access",
"${chip_root}/src/app/icd:notifier",
"${chip_root}/src/app/icd:observer-srcs",
"${chip_root}/src/lib/address_resolve",
"${chip_root}/src/lib/support",
Expand All @@ -246,7 +248,7 @@ static_library("app") {
]

if (chip_enable_icd_server) {
public_deps += [ "${chip_root}/src/app/icd:server-srcs" ]
public_deps += [ "${chip_root}/src/app/icd:manager-srcs" ]
}

cflags = [ "-Wconversion" ]
Expand Down
12 changes: 4 additions & 8 deletions src/app/FailSafeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Provides the implementation of the FailSafeContext object.
*/

#include <app/icd/ICDNotifier.h>
#include <lib/support/SafeInt.h>
#include <platform/CHIPDeviceConfig.h>
#include <platform/ConnectivityManager.h>
Expand Down Expand Up @@ -55,14 +56,9 @@ void FailSafeContext::SetFailSafeArmed(bool armed)
#if CHIP_CONFIG_ENABLE_ICD_SERVER
if (IsFailSafeArmed() != armed)
{
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kFailSafeStateChanged;
event.FailSafeState.armed = armed;
CHIP_ERROR err = DeviceLayer::PlatformMgr().PostEvent(&event);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to post kFailSafeStateChanged event %" CHIP_ERROR_FORMAT, err.Format());
}
ICDListener::KeepActiveFlags activeRequest = ICDListener::KeepActiveFlags::kFailSafeArmed;
armed ? ICDNotifier::GetInstance().BroadcastActiveRequestNotification(activeRequest)
: ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(activeRequest);
}
#endif
mFailSafeArmed = armed;
Expand Down
25 changes: 11 additions & 14 deletions src/app/icd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ import("//build_overrides/chip.gni")
import("icd.gni")

# ICD Server sources and configurations

source_set("observer-srcs") {
sources = [ "ICDStateObserver.h" ]
}

source_set("notifier") {
sources = [
"ICDNotifier.cpp",
"ICDNotifier.h",
]

deps = [ "${chip_root}/src/lib/core" ]
public_deps = [ "${chip_root}/src/app:app_config" ]
}

# ICD Manager source-set is broken out of the main source-set to enable unit tests
# All sources and configurations used by the ICDManager need to go in this source-set
source_set("manager-srcs") {
Expand All @@ -31,6 +40,7 @@ source_set("manager-srcs") {

public_deps = [
":cluster-srcs",
":notifier",
":observer-srcs",
"${chip_root}/src/credentials:credentials",
]
Expand All @@ -52,16 +62,3 @@ source_set("cluster-srcs") {
"${chip_root}/src/protocols:im_status",
]
}

# servers-srcs source-set contains all the sources and configurations necessary to build the ICD Server functionality
# All sources, configurations and dependencies necessary for the ICD Server featureset need to go in this source-set
#
# The ICD Server featureset is enabled with the chip_enable_icd_server in the src/app/BUILD.gn file
source_set("server-srcs") {
sources = [
"ICDEventManager.cpp",
"ICDEventManager.h",
]

public_deps = [ ":manager-srcs" ]
}
123 changes: 0 additions & 123 deletions src/app/icd/ICDEventManager.cpp

This file was deleted.

56 changes: 0 additions & 56 deletions src/app/icd/ICDEventManager.h

This file was deleted.

Loading

0 comments on commit 1756386

Please sign in to comment.