From e7c9d2692ca0b60235b6657fbe1a955cd923866e Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Mon, 29 May 2023 18:57:18 +0800 Subject: [PATCH] app: Fix clusters delegates table check --- .../account-login-server/account-login-server.cpp | 4 ++-- .../application-basic-server.cpp | 4 ++-- .../application-launcher-server.cpp | 4 ++-- src/app/clusters/channel-server/channel-server.cpp | 4 ++-- .../color-control-server/color-control-server.h | 14 ++++++++------ .../content-launch-server.cpp | 4 ++-- .../clusters/door-lock-server/door-lock-server.h | 5 ++++- .../keypad-input-server/keypad-input-server.cpp | 4 ++-- .../media-playback-server.cpp | 4 ++-- .../target-navigator-server.cpp | 4 ++-- .../window-covering-server.cpp | 5 ++--- 11 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/app/clusters/account-login-server/account-login-server.cpp b/src/app/clusters/account-login-server/account-login-server.cpp index da1cafacbd51ad..c3bd3093f92073 100644 --- a/src/app/clusters/account-login-server/account-login-server.cpp +++ b/src/app/clusters/account-login-server/account-login-server.cpp @@ -67,7 +67,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "AccountLogin NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, AccountLogin::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kAccountLoginDeletageTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -90,7 +90,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, AccountLogin::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kAccountLoginDeletageTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/application-basic-server/application-basic-server.cpp b/src/app/clusters/application-basic-server/application-basic-server.cpp index c71282933e3646..d00d028a583527 100644 --- a/src/app/clusters/application-basic-server/application-basic-server.cpp +++ b/src/app/clusters/application-basic-server/application-basic-server.cpp @@ -68,7 +68,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "ApplicationBasic NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, chip::app::Clusters::ApplicationBasic::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kApplicationBasicDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -91,7 +91,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationBasic::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_APPLICATION_BASIC_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kApplicationBasicDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.cpp b/src/app/clusters/application-launcher-server/application-launcher-server.cpp index e3ed24e0ad39ea..bea77f5dd087cd 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.cpp +++ b/src/app/clusters/application-launcher-server/application-launcher-server.cpp @@ -75,7 +75,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "ApplicationLauncher NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kApplicationLauncherDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -98,7 +98,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ApplicationLauncher::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_APPLICATION_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kApplicationLauncherDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/channel-server/channel-server.cpp b/src/app/clusters/channel-server/channel-server.cpp index 72c0f59b06a66d..9aa79272cafd8e 100644 --- a/src/app/clusters/channel-server/channel-server.cpp +++ b/src/app/clusters/channel-server/channel-server.cpp @@ -62,7 +62,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "Channel NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, Channel::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kChannelDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -85,7 +85,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, Channel::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_CHANNEL_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kChannelDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/color-control-server/color-control-server.h b/src/app/clusters/color-control-server/color-control-server.h index e9a87182770fb8..3de1cd22418c00 100644 --- a/src/app/clusters/color-control-server/color-control-server.h +++ b/src/app/clusters/color-control-server/color-control-server.h @@ -237,22 +237,24 @@ class ColorControlServer * Attributes Declaration *********************************************************/ static ColorControlServer instance; + static constexpr size_t kColorControlClusterServerMaxEndpointCount = + EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV - ColorHueTransitionState colorHueTransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; - Color16uTransitionState colorSatTransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + ColorHueTransitionState colorHueTransitionStates[kColorControlClusterServerMaxEndpointCount]; + Color16uTransitionState colorSatTransitionStates[kColorControlClusterServerMaxEndpointCount]; #endif #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_XY - Color16uTransitionState colorXtransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; - Color16uTransitionState colorYtransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + Color16uTransitionState colorXtransitionStates[kColorControlClusterServerMaxEndpointCount]; + Color16uTransitionState colorYtransitionStates[kColorControlClusterServerMaxEndpointCount]; #endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_XY #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP - Color16uTransitionState colorTempTransitionStates[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + Color16uTransitionState colorTempTransitionStates[kColorControlClusterServerMaxEndpointCount]; #endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP - EmberEventControl eventControls[EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT]; + EmberEventControl eventControls[kColorControlClusterServerMaxEndpointCount]; }; /********************************************************** diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index f5a700ff8a972d..d9b4eab150d4a4 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -67,7 +67,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "Content Launcher NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ContentLauncher::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kContentLaunchDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -90,7 +90,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ContentLauncher::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_CONTENT_LAUNCHER_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kContentLaunchDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index 5728a4a891c559..c0a8ecd086e045 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -553,7 +553,10 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData); - std::array mEndpointCtx; + static constexpr size_t kDoorLockClusterServerMaxEndpointCount = + EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + + std::array mEndpointCtx; static DoorLockServer instance; }; diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.cpp b/src/app/clusters/keypad-input-server/keypad-input-server.cpp index 9790e2f5a6b6ab..b7e90d32e03ce2 100644 --- a/src/app/clusters/keypad-input-server/keypad-input-server.cpp +++ b/src/app/clusters/keypad-input-server/keypad-input-server.cpp @@ -70,7 +70,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "KeypadInput NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, KeypadInput::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kKeypadInputDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -93,7 +93,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, KeypadInput::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_KEYPAD_INPUT_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kKeypadInputDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/media-playback-server/media-playback-server.cpp b/src/app/clusters/media-playback-server/media-playback-server.cpp index 979bf49116b34b..a158b72154f613 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.cpp +++ b/src/app/clusters/media-playback-server/media-playback-server.cpp @@ -70,7 +70,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogError(Zcl, "MediaPlayback NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, MediaPlayback::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kMediaPlaybackDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -93,7 +93,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, MediaPlayback::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_MEDIA_PLAYBACK_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kMediaPlaybackDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.cpp b/src/app/clusters/target-navigator-server/target-navigator-server.cpp index 0d71e6665006d3..b4083e69e41a15 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.cpp +++ b/src/app/clusters/target-navigator-server/target-navigator-server.cpp @@ -69,7 +69,7 @@ Delegate * GetDelegate(EndpointId endpoint) ChipLogProgress(Zcl, "TargetNavigator NOT returning ContentApp delegate for endpoint:%u", endpoint); uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, TargetNavigator::Id); - return ((ep == 0xFFFF || ep >= EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr : gDelegateTable[ep]); + return ((ep == 0xFFFF || ep >= kTargetNavigatorDelegateTableSize) ? nullptr : gDelegateTable[ep]); } bool isDelegateNull(Delegate * delegate, EndpointId endpoint) @@ -92,7 +92,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, TargetNavigator::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_TARGET_NAVIGATOR_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kTargetNavigatorDelegateTableSize) { gDelegateTable[ep] = delegate; } diff --git a/src/app/clusters/window-covering-server/window-covering-server.cpp b/src/app/clusters/window-covering-server/window-covering-server.cpp index d01f2fac668746..d008adcf4983fb 100644 --- a/src/app/clusters/window-covering-server/window-covering-server.cpp +++ b/src/app/clusters/window-covering-server/window-covering-server.cpp @@ -54,8 +54,7 @@ Delegate * gDelegateTable[kWindowCoveringDelegateTableSize] = { nullptr }; Delegate * GetDelegate(EndpointId endpoint) { uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, WindowCovering::Id); - return ((ep == kInvalidEndpointId || ep >= EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT) ? nullptr - : gDelegateTable[ep]); + return ((ep == kInvalidEndpointId || ep >= kWindowCoveringDelegateTableSize) ? nullptr : gDelegateTable[ep]); } /* @@ -598,7 +597,7 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, WindowCovering::Id); // if endpoint is found and is not a dynamic endpoint - if (ep != 0xFFFF && ep < EMBER_AF_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT) + if (ep != 0xFFFF && ep < kWindowCoveringDelegateTableSize) { gDelegateTable[ep] = delegate; }