|
| 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 | +#pragma once |
| 18 | +#include <app-common/zap-generated/cluster-objects.h> |
| 19 | +#include <app-common/zap-generated/ids/Attributes.h> |
| 20 | +#include <app-common/zap-generated/ids/Clusters.h> |
| 21 | +#include <app/AttributeAccessInterface.h> |
| 22 | +#include <app/AttributeAccessInterfaceRegistry.h> |
| 23 | +#include <app/clusters/actions-server/actions-server.h> |
| 24 | +#include <app/util/attribute-storage.h> |
| 25 | +#include <lib/support/CodeUtils.h> |
| 26 | +#include <lib/support/logging/CHIPLogging.h> |
| 27 | +#include <vector> |
| 28 | + |
| 29 | +namespace chip { |
| 30 | +namespace app { |
| 31 | +namespace Clusters { |
| 32 | +namespace Actions { |
| 33 | +class ActionsDelegateImpl : public Delegate |
| 34 | +{ |
| 35 | +private: |
| 36 | + std::vector<ActionStructStorage> kActionList = { |
| 37 | + ActionStructStorage(0, CharSpan::fromCharString("TurnOnLight"), ActionTypeEnum::kScene, 0, 0, ActionStateEnum::kInactive), |
| 38 | + ActionStructStorage(1, CharSpan::fromCharString("TurnOffLight"), ActionTypeEnum::kScene, 1, 0, ActionStateEnum::kInactive), |
| 39 | + ActionStructStorage(2, CharSpan::fromCharString("ToggleLight"), ActionTypeEnum::kScene, 2, 0, ActionStateEnum::kInactive) |
| 40 | + }; |
| 41 | + |
| 42 | + std::vector<EndpointId> firstEpList = { 0 }; |
| 43 | + std::vector<EndpointId> secondEpList = { 0, 1 }; |
| 44 | + std::vector<EndpointId> thirdEpList = { 1, 2, 3 }; |
| 45 | + |
| 46 | + std::vector<EndpointListStorage> kEndpointList = { |
| 47 | + EndpointListStorage(0, CharSpan::fromCharString("On"), EndpointListTypeEnum::kOther, |
| 48 | + DataModel::List<const EndpointId>(firstEpList.data(), firstEpList.size())), |
| 49 | + EndpointListStorage(1, CharSpan::fromCharString("Off"), EndpointListTypeEnum::kOther, |
| 50 | + DataModel::List<const EndpointId>(secondEpList.data(), secondEpList.size())), |
| 51 | + EndpointListStorage(2, CharSpan::fromCharString("Toggle"), EndpointListTypeEnum::kOther, |
| 52 | + DataModel::List<const EndpointId>(thirdEpList.data(), thirdEpList.size())) |
| 53 | + }; |
| 54 | + |
| 55 | + CHIP_ERROR ReadActionAtIndex(uint16_t index, ActionStructStorage & action) override; |
| 56 | + CHIP_ERROR ReadEndpointListAtIndex(uint16_t index, EndpointListStorage & epList) override; |
| 57 | + bool HaveActionWithId(uint16_t actionId, uint16_t & actionIndex) override; |
| 58 | + |
| 59 | + Protocols::InteractionModel::Status HandleInstantAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 60 | + Protocols::InteractionModel::Status HandleInstantActionWithTransition(uint16_t actionId, uint16_t transitionTime, |
| 61 | + Optional<uint32_t> invokeId) override; |
| 62 | + Protocols::InteractionModel::Status HandleStartAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 63 | + Protocols::InteractionModel::Status HandleStartActionWithDuration(uint16_t actionId, uint32_t duration, |
| 64 | + Optional<uint32_t> invokeId) override; |
| 65 | + Protocols::InteractionModel::Status HandleStopAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 66 | + Protocols::InteractionModel::Status HandlePauseAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 67 | + Protocols::InteractionModel::Status HandlePauseActionWithDuration(uint16_t actionId, uint32_t duration, |
| 68 | + Optional<uint32_t> invokeId) override; |
| 69 | + Protocols::InteractionModel::Status HandleResumeAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 70 | + Protocols::InteractionModel::Status HandleEnableAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 71 | + Protocols::InteractionModel::Status HandleEnableActionWithDuration(uint16_t actionId, uint32_t duration, |
| 72 | + Optional<uint32_t> invokeId) override; |
| 73 | + Protocols::InteractionModel::Status HandleDisableAction(uint16_t actionId, Optional<uint32_t> invokeId) override; |
| 74 | + Protocols::InteractionModel::Status HandleDisableActionWithDuration(uint16_t actionId, uint32_t duration, |
| 75 | + Optional<uint32_t> invokeId) override; |
| 76 | +}; |
| 77 | +} // namespace Actions |
| 78 | +} // namespace Clusters |
| 79 | +} // namespace app |
| 80 | +} // namespace chip |
0 commit comments