|
| 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 |
0 commit comments