Skip to content

Commit

Permalink
[Scenes] Default Scene Handler Config (#30517)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Fixed endif comments

* Restyled by clang-format

---------

Co-authored-by: mkardous-silabs <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Dec 15, 2023
1 parent 6fca141 commit 1072791
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/app/clusters/color-control-server/color-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void writeRemainingTime(EndpointId endpoint, uint16_t remainingTimeMs);
static bool shouldExecuteIfOff(EndpointId endpoint, CommandId commandId, chip::Optional<chip::BitMask<OptionsBitmap>> optionsMask,
chip::Optional<chip::BitMask<OptionsBitmap>> optionsOverride);

#ifdef EMBER_AF_PLUGIN_SCENES
#if defined(EMBER_AF_PLUGIN_SCENES) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS
class DefaultLevelControlSceneHandler : public scenes::DefaultSceneHandlerImpl
{
public:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>;
using OnOffTransitionTimeInterface =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
*
Expand Down

0 comments on commit 1072791

Please sign in to comment.