/src/connectedhomeip/src/app/clusters/alarm-base-server/AlarmBaseCluster.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (c) 2026 Project CHIP Authors |
4 | | * All rights reserved. |
5 | | * |
6 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | | * you may not use this file except in compliance with the License. |
8 | | * You may obtain a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, software |
13 | | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | | * See the License for the specific language governing permissions and |
16 | | * limitations under the License. |
17 | | */ |
18 | | |
19 | | #pragma once |
20 | | |
21 | | #include <app/clusters/alarm-base-server/Delegate.h> |
22 | | #include <app/clusters/alarm-base-server/alarm-base-cluster-objects.h> |
23 | | #include <app/server-cluster/DefaultServerCluster.h> |
24 | | |
25 | | namespace chip::app::Clusters { |
26 | | |
27 | | /** |
28 | | * AlarmBaseCluster is the code-driven implementation of the Alarm Base cluster. |
29 | | * |
30 | | * It provides a base implementation for any derivation (e.g. DishwasherAlarm, RefrigeratorAlarm). |
31 | | */ |
32 | | class AlarmBaseCluster : public DefaultServerCluster |
33 | | { |
34 | | public: |
35 | | struct Config |
36 | | { |
37 | | AlarmBase::Delegate & delegate; |
38 | | BitMask<AlarmBase::Feature> feature{}; |
39 | | AlarmBase::AlarmMap supported{}; |
40 | | AlarmBase::AlarmMap latch{}; |
41 | | bool supportsModifyEnabledAlarms = false; |
42 | | }; |
43 | | |
44 | | AlarmBaseCluster(EndpointId endpointId, AlarmBase::ClusterEntry cluster, const Config & config); |
45 | | |
46 | | DataModel::ActionReturnStatus ReadAttribute(const DataModel::ReadAttributeRequest & request, |
47 | | AttributeValueEncoder & encoder) override; |
48 | | |
49 | | CHIP_ERROR Attributes(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<DataModel::AttributeEntry> & builder) override; |
50 | | |
51 | | std::optional<DataModel::ActionReturnStatus> InvokeCommand(const DataModel::InvokeRequest & request, |
52 | | TLV::TLVReader & input_arguments, CommandHandler * handler) override; |
53 | | |
54 | | CHIP_ERROR AcceptedCommands(const ConcreteClusterPath & path, |
55 | | ReadOnlyBufferBuilder<DataModel::AcceptedCommandEntry> & builder) override; |
56 | | |
57 | | // Application-facing API |
58 | 0 | AlarmBase::AlarmMap GetMask() const { return mMask; } |
59 | 0 | AlarmBase::AlarmMap GetState() const { return mState; } |
60 | 0 | AlarmBase::AlarmMap GetSupported() const { return mSupported; } |
61 | 0 | AlarmBase::AlarmMap GetLatch() const { return mLatch; } |
62 | 0 | BitMask<AlarmBase::Feature> GetFeatures() const { return mFeature; } |
63 | | |
64 | | Protocols::InteractionModel::Status SetMask(const AlarmBase::AlarmMap & mask); |
65 | | Protocols::InteractionModel::Status SetState(const AlarmBase::AlarmMap & newState); |
66 | | Protocols::InteractionModel::Status ResetLatchedAlarms(const AlarmBase::AlarmMap & alarms); |
67 | | |
68 | | protected: |
69 | | virtual void SendNotifyEvent(AlarmBase::AlarmMap becameActive, AlarmBase::AlarmMap becameInactive, AlarmBase::AlarmMap newState, |
70 | | AlarmBase::AlarmMap mask) = 0; |
71 | | |
72 | | /// Used when the Latch attribute must not prevent state updates (mask adjustment, reset, integration init). |
73 | | /// Applications should use SetState() or ResetLatchedAlarms() instead. |
74 | | Protocols::InteractionModel::Status SetStateIgnoringLatch(const AlarmBase::AlarmMap & newState); |
75 | | |
76 | | private: |
77 | | const BitMask<AlarmBase::Feature> mFeature; |
78 | | const uint32_t mClusterRevision; |
79 | | const bool mSupportsModifyEnabledAlarms; |
80 | | AlarmBase::Delegate & mDelegate; |
81 | | |
82 | | AlarmBase::AlarmMap mMask{}; |
83 | | const AlarmBase::AlarmMap mLatch; |
84 | | AlarmBase::AlarmMap mState{}; |
85 | | const AlarmBase::AlarmMap mSupported; |
86 | | |
87 | | Protocols::InteractionModel::Status SetStateInternal(const AlarmBase::AlarmMap & newState, bool ignoreLatchState); |
88 | | |
89 | | DataModel::ActionReturnStatus HandleReset(const AlarmBase::AlarmMap & alarms); |
90 | | |
91 | | DataModel::ActionReturnStatus HandleModifyEnabledAlarms(const AlarmBase::AlarmMap & mask); |
92 | | }; |
93 | | |
94 | | } // namespace chip::app::Clusters |