|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2026 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/CommandHandler.h> |
| 21 | +#include <app/ConcreteCommandPath.h> |
| 22 | +#include <app/clusters/actions-server/ActionsDelegate.h> |
| 23 | +#include <app/server-cluster/DefaultServerCluster.h> |
| 24 | +#include <app/server-cluster/OptionalAttributeSet.h> |
| 25 | +#include <clusters/Actions/Attributes.h> |
| 26 | +#include <clusters/Actions/Events.h> |
| 27 | + |
| 28 | +namespace chip::app::Clusters { |
| 29 | + |
| 30 | +class ActionsCluster : public DefaultServerCluster |
| 31 | +{ |
| 32 | +public: |
| 33 | + using OptionalAttributesSet = OptionalAttributeSet<Actions::Attributes::SetupURL::Id>; |
| 34 | + |
| 35 | + ActionsCluster(EndpointId endpointId, Actions::Delegate & delegate, OptionalAttributesSet optionalAttributes = {}, |
| 36 | + std::optional<CharSpan> setupURL = std::nullopt) : |
| 37 | + DefaultServerCluster({ endpointId, Actions::Id }), |
| 38 | + mDelegate(delegate), mOptionalAttributes(optionalAttributes), mSetupURL(setupURL) |
| 39 | + {} |
| 40 | + |
| 41 | + ~ActionsCluster() = default; |
| 42 | + |
| 43 | + void ActionListModified(); |
| 44 | + |
| 45 | + void EndpointListsModified(); |
| 46 | + |
| 47 | + /** |
| 48 | + * Public helper API for the Application/Delegate to call asynchronously to emit a Matter event to the fabric. |
| 49 | + * Use these when an action's state changes or an action fails. |
| 50 | + */ |
| 51 | + void GenerateEvent(const Actions::Events::StateChanged::Type & event); |
| 52 | + void GenerateEvent(const Actions::Events::ActionFailed::Type & event); |
| 53 | + |
| 54 | + DataModel::ActionReturnStatus ReadAttribute(const DataModel::ReadAttributeRequest & request, |
| 55 | + AttributeValueEncoder & encoder) override; |
| 56 | + |
| 57 | + std::optional<DataModel::ActionReturnStatus> InvokeCommand(const DataModel::InvokeRequest & request, |
| 58 | + chip::TLV::TLVReader & input_arguments, |
| 59 | + CommandHandler * handler) override; |
| 60 | + |
| 61 | + CHIP_ERROR Attributes(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<DataModel::AttributeEntry> & builder) override; |
| 62 | + |
| 63 | + CHIP_ERROR AcceptedCommands(const ConcreteClusterPath & path, |
| 64 | + ReadOnlyBufferBuilder<DataModel::AcceptedCommandEntry> & builder) override; |
| 65 | + |
| 66 | +private: |
| 67 | + Actions::Delegate & mDelegate; |
| 68 | + const OptionalAttributesSet mOptionalAttributes; |
| 69 | + const std::optional<CharSpan> mSetupURL; |
| 70 | + |
| 71 | + CHIP_ERROR ReadActionListAttribute(const DataModel::ReadAttributeRequest & request, |
| 72 | + const AttributeValueEncoder::ListEncodeHelper & aEncoder); |
| 73 | + |
| 74 | + CHIP_ERROR ReadEndpointListAttribute(const DataModel::ReadAttributeRequest & request, |
| 75 | + const AttributeValueEncoder::ListEncodeHelper & aEncoder); |
| 76 | + |
| 77 | + Protocols::InteractionModel::Status ValidateActionExists(uint16_t actionID, uint16_t & outActionIndex); |
| 78 | + |
| 79 | + Protocols::InteractionModel::Status ValidateCommandSupported(uint16_t actionIndex, CommandId commandId); |
| 80 | +}; |
| 81 | + |
| 82 | +} // namespace chip::app::Clusters |
0 commit comments