Skip to content

Commit

Permalink
Global Event List Support: All Manually Updated Files
Browse files Browse the repository at this point in the history
  • Loading branch information
emargolis committed Feb 7, 2023
1 parent 8d801e8 commit 19392e8
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/app/GlobalAttributes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -31,6 +31,7 @@ namespace app {
constexpr AttributeId GlobalAttributesNotInMetadata[] = {
Clusters::Globals::Attributes::GeneratedCommandList::Id,
Clusters::Globals::Attributes::AcceptedCommandList::Id,
Clusters::Globals::Attributes::EventList::Id,
Clusters::Globals::Attributes::AttributeList::Id,
};

Expand Down
11 changes: 11 additions & 0 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ typedef struct
* is a response to client command request. Can be nullptr or terminated by 0xFFFF_FFFF.
*/
const chip::CommandId * generatedCommandList;

/**
* Pointer to an array of event IDs of the events supported by the cluster instance.
* Can be nullptr.
*/
const chip::EventId * eventList;

/**
* Total number of events supported by the cluster instance (in eventList array).
*/
uint16_t eventCount;
} EmberAfCluster;

/**
Expand Down
6 changes: 5 additions & 1 deletion src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2020-2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -82,6 +82,10 @@ GENERATED_FUNCTION_ARRAYS
constexpr const chip::CommandId generatedCommands[] = GENERATED_COMMANDS;
#endif // GENERATED_COMMANDS

#ifdef GENERATED_EVENTS
constexpr const chip::EventId generatedEvents[] = GENERATED_EVENTS;
#endif // GENERATED_EVENTS

constexpr const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES;
constexpr const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS;
constexpr const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES;
Expand Down
18 changes: 12 additions & 6 deletions src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2021-2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -383,11 +383,8 @@ CHIP_ERROR GlobalAttributeReader::Read(const ConcreteReadAttributePath & aPath,
AttributeId id = mCluster->attributes[i].attributeId;
constexpr auto lastGlobalId = GlobalAttributesNotInMetadata[ArraySize(GlobalAttributesNotInMetadata) - 1];
// We are relying on GlobalAttributesNotInMetadata not having
// any gaps in their ids here, but for now they do because we
// have no EventList support. So this assert is not quite
// right. There should be a "- 1" on the right-hand side of the
// equals sign.
static_assert(lastGlobalId - GlobalAttributesNotInMetadata[0] == ArraySize(GlobalAttributesNotInMetadata),
// any gaps in their ids here.
static_assert(lastGlobalId - GlobalAttributesNotInMetadata[0] == ArraySize(GlobalAttributesNotInMetadata) - 1,
"Ids in GlobalAttributesNotInMetadata not consecutive (except EventList)");
if (!addedExtraGlobals && id > lastGlobalId)
{
Expand All @@ -408,6 +405,15 @@ CHIP_ERROR GlobalAttributeReader::Read(const ConcreteReadAttributePath & aPath,
}
return CHIP_NO_ERROR;
});
case EventList::Id:
return aEncoder.EncodeList([this](const auto & encoder) {
for (size_t i = 0; i < mCluster->eventCount; ++i)
{
ReturnErrorOnFailure(encoder.Encode(mCluster->eventList[i]));
}
return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
case AcceptedCommandList::Id:
return EncodeCommandList(aPath, aEncoder, &CommandHandlerInterface::EnumerateAcceptedCommands,
mCluster->acceptedCommandList);
Expand Down
7 changes: 7 additions & 0 deletions src/app/zap-templates/templates/app/endpoint_config.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@

#define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index])

// clang-format off
#define GENERATED_EVENT_COUNT {{ chip_endpoint_generated_event_count }}
#define GENERATED_EVENTS {{ chip_endpoint_generated_event_list }}
// clang-format on

#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index])

// Cluster function static arrays
#define GENERATED_FUNCTION_ARRAYS {{chip_endpoint_generated_functions}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2021 Project CHIP Authors
Copyright (c) 2021-2023 Project CHIP Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,8 +21,8 @@ limitations under the License.
<attribute side="client" code="0xFFFC" define="FEATURE_MAP_CLIENT" type="bitmap32" default="0">FeatureMap</attribute>
<attribute side="server" code="0xFFFC" define="FEATURE_MAP_SERVER" type="bitmap32" default="0">FeatureMap</attribute>
<attribute side="server" code="0xFFFB" define="ATTRIBUTE_LIST_SERVER" type="array" entryType="attrib_id">AttributeList</attribute>
<attribute side="server" code="0xFFFA" define="EVENT_LIST" type="array" entryType="event_id">EventList</attribute>
<attribute side="server" code="0xFFF9" define="ACCEPTED_COMMAND_LIST" type="array" entryType="command_id">AcceptedCommandList</attribute>
<attribute side="server" code="0xFFF8" define="GENERATED_COMMAND_LIST" type="array" entryType="command_id">GeneratedCommandList</attribute>

<attribute side="server" code="0xFFF8" define="GENERATED_COMMAND_LIST" type="array" entryType="command_id">GeneratedCommandList</attribute>
</global>
</configurator>
8 changes: 6 additions & 2 deletions src/controller/tests/TestEventChunking.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -196,6 +196,10 @@ void TestReadCallback::OnAttributeData(const app::ConcreteDataAttributePath & aP
NL_TEST_ASSERT(gSuite, v.ComputeSize(&arraySize) == CHIP_NO_ERROR);
NL_TEST_ASSERT(gSuite, arraySize == 0);
}
else if (aPath.mAttributeId == Globals::Attributes::EventList::Id)
{
// Nothing to check for this one; depends on the endpoint.
}
else if (aPath.mAttributeId == Globals::Attributes::AttributeList::Id)
{
// Nothing to check for this one; depends on the endpoint.
Expand Down Expand Up @@ -429,7 +433,7 @@ void TestReadEvents::TestMixedEventsAndAttributesChunking(nlTestSuite * apSuite,
// ServerGeneratedCommandList = 9).
//
NL_TEST_ASSERT(apSuite, readCallback.mOnReportEnd);
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == 9);
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == 10);
NL_TEST_ASSERT(apSuite, readCallback.mEventCount == static_cast<uint32_t>(lastEventNumber - firstEventNumber + 1));

NL_TEST_ASSERT(apSuite, ctx.GetExchangeManager().GetNumActiveExchanges() == 0);
Expand Down
20 changes: 12 additions & 8 deletions src/controller/tests/TestReadChunking.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2021-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -174,6 +174,10 @@ void TestReadCallback::OnAttributeData(const app::ConcreteDataAttributePath & aP
NL_TEST_ASSERT(gSuite, v.ComputeSize(&arraySize) == CHIP_NO_ERROR);
NL_TEST_ASSERT(gSuite, arraySize == 0);
}
else if (aPath.mAttributeId == Globals::Attributes::EventList::Id)
{
// Nothing to check for this one; depends on the endpoint.
}
else if (aPath.mAttributeId == Globals::Attributes::AttributeList::Id)
{
// Nothing to check for this one; depends on the endpoint.
Expand Down Expand Up @@ -404,10 +408,10 @@ void TestReadChunking::TestChunking(nlTestSuite * apSuite, void * apContext)

//
// Always returns the same number of attributes read (5 + revision +
// AttributeList + AcceptedCommandList +
// GeneratedCommandList = 9).
// AttributeList + EventList + AcceptedCommandList +
// GeneratedCommandList = 10).
//
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == 9);
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == 10);
readCallback.mAttributeCount = 0;

NL_TEST_ASSERT(apSuite, ctx.GetExchangeManager().GetNumActiveExchanges() == 0);
Expand Down Expand Up @@ -581,9 +585,9 @@ void TestReadChunking::TestDynamicEndpoint(nlTestSuite * apSuite, void * apConte
ctx.DrainAndServiceIO();

// Ensure we have received the report, we do not care about the initial report here.
// AcceptedCommandList / GeneratedCommandList / AttributeList attribute are not included in
// AcceptedCommandList / GeneratedCommandList / EventList / AttributeList attribute are not included in
// testClusterAttrsOnEndpoint4.
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == ArraySize(testClusterAttrsOnEndpoint4) + 3);
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == ArraySize(testClusterAttrsOnEndpoint4) + 4);

// We have received all report data.
NL_TEST_ASSERT(apSuite, readCallback.mOnReportEnd);
Expand All @@ -607,9 +611,9 @@ void TestReadChunking::TestDynamicEndpoint(nlTestSuite * apSuite, void * apConte
ctx.DrainAndServiceIO();

// Ensure we have received the report, we do not care about the initial report here.
// AcceptedCommandList / GeneratedCommandList / AttributeList attribute are not include in
// AcceptedCommandList / GeneratedCommandList / EventList / AttributeList attribute are not included in
// testClusterAttrsOnEndpoint4.
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == ArraySize(testClusterAttrsOnEndpoint4) + 3);
NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == ArraySize(testClusterAttrsOnEndpoint4) + 4);

// We have received all report data.
NL_TEST_ASSERT(apSuite, readCallback.mOnReportEnd);
Expand Down

0 comments on commit 19392e8

Please sign in to comment.