Skip to content

Commit

Permalink
app: Fix clusters delegates table check
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed May 30, 2023
1 parent cfb9994 commit 3cfd9e5
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/channel-server/channel-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
14 changes: 8 additions & 6 deletions src/app/clusters/color-control-server/color-control-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <app/ConcreteCommandPath.h>
#include <app/util/af.h>
#include <app/util/config.h>
#include <platform/CHIPDeviceConfig.h>
#include <protocols/interaction_model/StatusCode.h>

#ifndef DOOR_LOCK_SERVER_ENDPOINT
Expand Down Expand Up @@ -553,7 +554,10 @@ class DoorLockServer
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData);

std::array<EmberAfDoorLockEndpointContext, EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT> mEndpointCtx;
static constexpr size_t kDoorLockClusterServerMaxEndpointCount =
EMBER_AF_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;

std::array<EmberAfDoorLockEndpointContext, kDoorLockClusterServerMaxEndpointCount> mEndpointCtx;

static DoorLockServer instance;
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/keypad-input-server/keypad-input-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/*
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3cfd9e5

Please sign in to comment.