From 107279121290fcf8db53b79a4cd1ca1811c43dff Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com> Date: Fri, 17 Nov 2023 15:44:51 -0500 Subject: [PATCH] [Scenes] Default Scene Handler Config (#30517) * Added a config allowing to choose if we want to enable the default scenes handler, it is enabled by default * Modified the comment so it makes more sense * Apply suggestions from code review Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> * Fixed endif comments * Restyled by clang-format --------- Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Co-authored-by: Restyled.io --- .../color-control-server/color-control-server.cpp | 12 ++++++------ src/app/clusters/level-control/level-control.cpp | 12 ++++++------ src/app/clusters/on-off-server/on-off-server.cpp | 12 ++++++------ src/lib/core/CHIPConfig.h | 13 ++++++++++++- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index e3645681cb5c4a..3dbba76be8491a 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -59,7 +59,7 @@ constexpr uint8_t kExecuteIfOff = 1; } // namespace app } // namespace chip -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl { public: @@ -380,7 +380,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl } }; static DefaultColorControlSceneHandler sColorControlSceneHandler; -#endif // EMBER_AF_PLUGIN_SCENES +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS /********************************************************** * Matter timer scheduling glue logic @@ -434,11 +434,11 @@ ColorControlServer & ColorControlServer::Instance() chip::scenes::SceneHandler * ColorControlServer::GetSceneHandler() { -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS return &sColorControlSceneHandler; #else return nullptr; -#endif // EMBER_AF_PLUGIN_SCENES +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS } bool ColorControlServer::HasFeature(chip::EndpointId endpoint, Feature feature) @@ -3084,11 +3084,11 @@ void emberAfColorControlClusterServerInitCallback(EndpointId endpoint) #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP ColorControlServer::Instance().startUpColorTempCommand(endpoint); #endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS // Registers Scene handlers for the color control cluster on the server app::Clusters::Scenes::ScenesServer::Instance().RegisterSceneHandler(endpoint, ColorControlServer::Instance().GetSceneHandler()); -#endif +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS } void MatterColorControlClusterServerShutdownCallback(EndpointId endpoint) diff --git a/src/app/clusters/level-control/level-control.cpp b/src/app/clusters/level-control/level-control.cpp index a2bfc1a58b794e..f12b20684f7b6d 100644 --- a/src/app/clusters/level-control/level-control.cpp +++ b/src/app/clusters/level-control/level-control.cpp @@ -120,7 +120,7 @@ static void writeRemainingTime(EndpointId endpoint, uint16_t remainingTimeMs); static bool shouldExecuteIfOff(EndpointId endpoint, CommandId commandId, chip::Optional> optionsMask, chip::Optional> optionsOverride); -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS class DefaultLevelControlSceneHandler : public scenes::DefaultSceneHandlerImpl { public: @@ -256,7 +256,7 @@ class DefaultLevelControlSceneHandler : public scenes::DefaultSceneHandlerImpl }; static DefaultLevelControlSceneHandler sLevelControlSceneHandler; -#endif // EMBER_AF_PLUGIN_SCENES +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS #if !defined(IGNORE_LEVEL_CONTROL_CLUSTER_OPTIONS) && defined(EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP) static void reallyUpdateCoupledColorTemp(EndpointId endpoint); @@ -610,11 +610,11 @@ Status MoveToLevel(EndpointId endpointId, const Commands::MoveToLevel::Decodable chip::scenes::SceneHandler * GetSceneHandler() { -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS return &sLevelControlSceneHandler; #else return nullptr; -#endif // EMBER_AF_PLUGIN_SCENES +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS } } // namespace LevelControlServer @@ -1446,10 +1446,10 @@ void emberAfLevelControlClusterServerInitCallback(EndpointId endpoint) } } -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS // Registers Scene handlers for the level control cluster on the server app::Clusters::Scenes::ScenesServer::Instance().RegisterSceneHandler(endpoint, LevelControlServer::GetSceneHandler()); -#endif +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS emberAfPluginLevelControlClusterServerPostInitCallback(endpoint); } diff --git a/src/app/clusters/on-off-server/on-off-server.cpp b/src/app/clusters/on-off-server/on-off-server.cpp index a9f13a1b7ba4cc..0350c61c5b07d2 100644 --- a/src/app/clusters/on-off-server/on-off-server.cpp +++ b/src/app/clusters/on-off-server/on-off-server.cpp @@ -103,7 +103,7 @@ static bool LevelControlWithOnOffFeaturePresent(EndpointId endpoint) static constexpr size_t kOnOffMaxEnpointCount = EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS static void sceneOnOffCallback(EndpointId endpoint); using OnOffEndPointPair = scenes::DefaultSceneHandlerImpl::EndpointStatePair; using OnOffTransitionTimeInterface = @@ -232,7 +232,7 @@ static void sceneOnOffCallback(EndpointId endpoint) OnOffServer::Instance().setOnOffValue(endpoint, command, false); ReturnOnFailure(sOnOffSceneHandler.mSceneEndpointStatePairs.RemovePair(endpoint)); } -#endif // EMBER_AF_PLUGIN_SCENES +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS /********************************************************** * Attributes Definition @@ -300,11 +300,11 @@ OnOffServer & OnOffServer::Instance() chip::scenes::SceneHandler * OnOffServer::GetSceneHandler() { -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS return &sOnOffSceneHandler; #else return nullptr; -#endif // EMBER_AF_PLUGIN_SCENES +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS } bool OnOffServer::HasFeature(chip::EndpointId endpoint, Feature feature) @@ -499,10 +499,10 @@ void OnOffServer::initOnOffServer(chip::EndpointId endpoint) status = setOnOffValue(endpoint, onOffValueForStartUp, true); } -#ifdef EMBER_AF_PLUGIN_SCENES +#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS // Registers Scene handlers for the On/Off cluster on the server app::Clusters::Scenes::ScenesServer::Instance().RegisterSceneHandler(endpoint, OnOffServer::Instance().GetSceneHandler()); -#endif +#endif // defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS #ifdef EMBER_AF_PLUGIN_MODE_SELECT // If OnMode is not a null value, then change the current mode to it. diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index fb04f9bbefd943..8e8856d34be78e 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -1444,7 +1444,7 @@ extern const char CHIP_NON_PRODUCTION_MARKER[]; #endif /** - * @ def CHIP_CONFIG_MAX_SCENES_TABLE_SIZE + * @def CHIP_CONFIG_MAX_SCENES_TABLE_SIZE * * @brief This defines how many scenes a single endpoint is allowed to allocate in flash memory. This value MUST at least 16 * per spec and MUST be increased to allow for configuring a greater scene table size from Zap. @@ -1457,6 +1457,17 @@ extern const char CHIP_NON_PRODUCTION_MARKER[]; #endif // CHIP_CONFIG_TEST #endif // CHIP_CONFIG_MAX_SCENES_TABLE_SIZE +/** + * @def CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS + * + * @brief This define enables the automatic registration of the default scene handlers in the scene table for each sceneable + * cluster. If a user wants to use their own scene handlers, they can disable this flag and implement their own handlers. They can + * use ScenesServer::Instance().RegisterSceneHandler() to have their handlers called when a scene is recalled or stored. + */ +#ifndef CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS +#define CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS 1 +#endif // CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS + /** * @def CHIP_CONFIG_TIME_ZONE_LIST_MAX_SIZE *