Skip to content

Commit 1bd336a

Browse files
committed
Move Actions cluster to be code driven
1 parent ae4c1e9 commit 1bd336a

19 files changed

Lines changed: 1222 additions & 390 deletions

File tree

scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/CodeDrivenCallback.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void MatterAccessControlClusterInitCallback(chip::EndpointId endpointId);
4444

4545
void MatterAccessControlClusterShutdownCallback(chip::EndpointId endpointId, MatterClusterShutdownType shutdownType);
4646

47+
void MatterActionsClusterInitCallback(chip::EndpointId endpointId);
48+
49+
void MatterActionsClusterShutdownCallback(chip::EndpointId endpointId, MatterClusterShutdownType shutdownType);
50+
4751
void MatterBasicInformationClusterInitCallback(chip::EndpointId endpointId);
4852

4953
void MatterBasicInformationClusterShutdownCallback(chip::EndpointId endpointId, MatterClusterShutdownType shutdownType);

scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/CodeDrivenInitShutdown.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void MatterClusterServerInitCallback(EndpointId endpoint, ClusterId clusterId)
4343
case app::Clusters::AccessControl::Id:
4444
MatterAccessControlClusterInitCallback(endpoint);
4545
break;
46+
case app::Clusters::Actions::Id:
47+
MatterActionsClusterInitCallback(endpoint);
48+
break;
4649
case app::Clusters::BasicInformation::Id:
4750
MatterBasicInformationClusterInitCallback(endpoint);
4851
break;
@@ -170,6 +173,9 @@ void MatterClusterServerShutdownCallback(EndpointId endpoint, ClusterId clusterI
170173
case app::Clusters::AccessControl::Id:
171174
MatterAccessControlClusterShutdownCallback(endpoint, shutdownType);
172175
break;
176+
case app::Clusters::Actions::Id:
177+
MatterActionsClusterShutdownCallback(endpoint, shutdownType);
178+
break;
173179
case app::Clusters::BasicInformation::Id:
174180
MatterBasicInformationClusterShutdownCallback(endpoint, shutdownType);
175181
break;

src/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if (chip_build_tests) {
5656
"${chip_root}/src/app/clusters/access-control-server/tests",
5757
"${chip_root}/src/app/clusters/administrator-commissioning-server/tests",
5858
"${chip_root}/src/app/clusters/basic-information/tests",
59+
"${chip_root}/src/app/clusters/actions-server/tests",
5960
"${chip_root}/src/app/clusters/bindings/tests",
6061
"${chip_root}/src/app/clusters/boolean-state-configuration-server/tests",
6162
"${chip_root}/src/app/clusters/boolean-state-server/tests",

src/app/clusters/actions-server/ActionsCluster.cpp

Lines changed: 456 additions & 168 deletions
Large diffs are not rendered by default.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <app-common/zap-generated/cluster-objects.h>
21+
#include <app/CommandHandler.h>
22+
#include <app/ConcreteCommandPath.h>
23+
#include <app/data-model/Encode.h>
24+
#include <app/server-cluster/DefaultServerCluster.h>
25+
#include <lib/core/DataModelTypes.h>
26+
27+
#include "ActionsDelegate.h"
28+
#include "ActionsStructs.h"
29+
30+
namespace chip {
31+
namespace app {
32+
namespace Clusters {
33+
namespace Actions {
34+
35+
static constexpr size_t kMaxEndpointListLength = 256u;
36+
static constexpr size_t kMaxActionListLength = 256u;
37+
38+
class ActionsCluster : public DefaultServerCluster
39+
{
40+
public:
41+
ActionsCluster(EndpointId endpointId, Delegate & delegate) :
42+
DefaultServerCluster({ endpointId, Actions::Id }), mDelegate(delegate)
43+
{}
44+
45+
~ActionsCluster() override = default;
46+
47+
CHIP_ERROR Startup(ServerClusterContext & context) override;
48+
49+
void Shutdown(ClusterShutdownType type) override;
50+
51+
void ActionListModified();
52+
53+
void EndpointListsModified();
54+
55+
void OnStateChanged(uint16_t aActionId, uint32_t aInvokeId, ActionStateEnum aActionState);
56+
57+
void OnActionFailed(uint16_t aActionId, uint32_t aInvokeId, ActionStateEnum aActionState, ActionErrorEnum aActionError);
58+
59+
DataModel::ActionReturnStatus ReadAttribute(const DataModel::ReadAttributeRequest & request,
60+
AttributeValueEncoder & encoder) override;
61+
62+
std::optional<DataModel::ActionReturnStatus> InvokeCommand(const DataModel::InvokeRequest & request,
63+
chip::TLV::TLVReader & input_arguments,
64+
CommandHandler * handler) override;
65+
66+
CHIP_ERROR Attributes(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<DataModel::AttributeEntry> & builder) override;
67+
68+
CHIP_ERROR AcceptedCommands(const ConcreteClusterPath & path,
69+
ReadOnlyBufferBuilder<DataModel::AcceptedCommandEntry> & builder) override;
70+
71+
private:
72+
Delegate & mDelegate;
73+
ServerClusterContext * mContext = nullptr;
74+
75+
CHIP_ERROR ReadActionListAttribute(const DataModel::ReadAttributeRequest & request,
76+
const AttributeValueEncoder::ListEncodeHelper & aEncoder);
77+
78+
CHIP_ERROR ReadEndpointListAttribute(const DataModel::ReadAttributeRequest & request,
79+
const AttributeValueEncoder::ListEncodeHelper & aEncoder);
80+
81+
bool HaveActionWithId(uint16_t aActionId, uint16_t & aActionIndex);
82+
83+
void HandleInstantAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
84+
const Commands::InstantAction::DecodableType & commandData);
85+
86+
void HandleInstantActionWithTransition(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
87+
const Commands::InstantActionWithTransition::DecodableType & commandData);
88+
89+
void HandleStartAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
90+
const Commands::StartAction::DecodableType & commandData);
91+
92+
void HandleStartActionWithDuration(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
93+
const Commands::StartActionWithDuration::DecodableType & commandData);
94+
95+
void HandleStopAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
96+
const Commands::StopAction::DecodableType & commandData);
97+
98+
void HandlePauseAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
99+
const Commands::PauseAction::DecodableType & commandData);
100+
101+
void HandlePauseActionWithDuration(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
102+
const Commands::PauseActionWithDuration::DecodableType & commandData);
103+
104+
void HandleResumeAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
105+
const Commands::ResumeAction::DecodableType & commandData);
106+
107+
void HandleEnableAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
108+
const Commands::EnableAction::DecodableType & commandData);
109+
110+
void HandleEnableActionWithDuration(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
111+
const Commands::EnableActionWithDuration::DecodableType & commandData);
112+
113+
void HandleDisableAction(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
114+
const Commands::DisableAction::DecodableType & commandData);
115+
116+
void HandleDisableActionWithDuration(const DataModel::InvokeRequest & request, CommandHandler * commandHandler,
117+
const Commands::DisableActionWithDuration::DecodableType & commandData);
118+
119+
/**
120+
* @brief Unified helper for attribute change notifications.
121+
* @param attributeId The ID of the attribute that changed.
122+
*
123+
* This method replaces direct calls to MatterReportingAttributeChangeCallback
124+
* and uses the DefaultServerCluster's NotifyAttributeChanged mechanism.
125+
*/
126+
void OnClusterAttributeChanged(AttributeId attributeId);
127+
};
128+
129+
} // namespace Actions
130+
} // namespace Clusters
131+
} // namespace app
132+
} // namespace chip

src/app/clusters/actions-server/BUILD.gn

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,21 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
group("actions-server") {
14+
import("//build_overrides/build.gni")
15+
import("//build_overrides/chip.gni")
16+
17+
static_library("actions-server") {
18+
sources = [
19+
"ActionsCluster.cpp",
20+
"ActionsCluster.h",
21+
]
22+
23+
public_deps = [
24+
"${chip_root}/src/app:constants",
25+
"${chip_root}/src/app:interaction-model",
26+
"${chip_root}/src/app/server",
27+
"${chip_root}/src/app/server-cluster",
28+
"${chip_root}/src/lib/core",
29+
"${chip_root}/src/lib/support",
30+
]
1531
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2025 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "CodegenIntegration.h"
19+
#include <data-model-providers/codegen/CodegenDataModelProvider.h>
20+
#include <lib/support/CodeUtils.h>
21+
22+
using namespace chip;
23+
using namespace chip::app;
24+
using namespace chip::app::Clusters;
25+
using namespace chip::app::Clusters::Actions;
26+
// The constructor wires the application's real delegate directly into the new ActionsCluster
27+
ActionsServer::ActionsServer(EndpointId endpointId, Actions::Delegate & delegate) : mCluster(endpointId, delegate) {}
28+
29+
ActionsServer::~ActionsServer()
30+
{
31+
Shutdown();
32+
}
33+
34+
CHIP_ERROR ActionsServer::Init()
35+
{
36+
// Registers the code-driven cluster with the new framework
37+
return CodegenDataModelProvider::Instance().Registry().Register(mCluster.Registration());
38+
}
39+
40+
void ActionsServer::Shutdown()
41+
{
42+
// Unregisters the code-driven cluster
43+
RETURN_SAFELY_IGNORED CodegenDataModelProvider::Instance().Registry().Unregister(&(mCluster.Cluster()));
44+
}
45+
46+
void ActionsServer::ActionListModified(EndpointId aEndpoint)
47+
{
48+
// Proxy the legacy call to the new cluster's centralized notification helper
49+
mCluster.Cluster().ActionListModified();
50+
}
51+
52+
void ActionsServer::EndpointListModified(EndpointId aEndpoint)
53+
{
54+
// Proxy the legacy call to the new cluster's centralized notification helper
55+
mCluster.Cluster().EndpointListsModified();
56+
}
57+
58+
// Stub callbacks: Since we are using the RegisteredServerCluster instantiation pattern
59+
// in the applications themselves, these ZAP-generated callbacks can remain empty stubs.
60+
void MatterActionsClusterInitCallback(EndpointId endpointId) {}
61+
void MatterActionsClusterShutdownCallback(chip::EndpointId endpointId, MatterClusterShutdownType type) {}
62+
void MatterActionsPluginServerInitCallback() {}
63+
void MatterActionsPluginServerShutdownCallback() {}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2025-2026 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
#include <app/clusters/actions-server/ActionsCluster.h>
20+
#include <app/server-cluster/ServerClusterInterfaceRegistry.h>
21+
22+
namespace chip {
23+
namespace app {
24+
namespace Clusters {
25+
namespace Actions {
26+
27+
// Legacy wrapper for backwards compatibility with existing applications.
28+
class ActionsServer
29+
{
30+
public:
31+
/**
32+
* Creates an actions server instance. This is a backwards compatibility wrapper around ActionsCluster.
33+
* @param endpointId The endpoint on which this cluster exists.
34+
* @param delegate A reference to the delegate to be used by this server.
35+
*/
36+
ActionsServer(EndpointId endpointId, Actions::Delegate & delegate);
37+
~ActionsServer();
38+
39+
/**
40+
* Register the actions cluster instance with the codegen data model provider.
41+
* @return Returns an error if registration fails.
42+
*/
43+
CHIP_ERROR Init();
44+
45+
/**
46+
* Unregister the actions cluster instance from the data model provider.
47+
*/
48+
void Shutdown();
49+
50+
// Legacy Notifiers - these proxy directly to the new cluster
51+
void ActionListModified(EndpointId aEndpoint);
52+
void EndpointListModified(EndpointId aEndpoint);
53+
54+
/**
55+
* @return The endpoint ID.
56+
*/
57+
EndpointId GetEndpointId() { return mCluster.Cluster().GetPaths()[0].mEndpointId; }
58+
59+
// The Code Driven ActionsCluster instance
60+
chip::app::RegisteredServerCluster<Actions::ActionsCluster> mCluster;
61+
};
62+
63+
} // namespace Actions
64+
} // namespace Clusters
65+
} // namespace app
66+
} // namespace chip

0 commit comments

Comments
 (0)