-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathBasicInformationCluster.h
More file actions
110 lines (95 loc) · 5.07 KB
/
BasicInformationCluster.h
File metadata and controls
110 lines (95 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <app/clusters/basic-information/BasicInformationDelegate.h>
#include <app/persistence/String.h>
#include <app/server-cluster/DefaultServerCluster.h>
#include <app/server-cluster/OptionalAttributeSet.h>
#include <clusters/BasicInformation/AttributeIds.h>
#include <clusters/BasicInformation/ClusterId.h>
#include <lib/core/DataModelTypes.h>
#include <platform/PlatformManager.h>
namespace chip {
namespace app {
namespace Clusters {
/// This class provides a code-driven implementation for the Basic Information cluster,
/// centralizing its logic and state.
/// As a PlatformManagerDelegate, it automatically hooks into the node's lifecycle to
/// emit the mandatory StartUp and optional ShutDown events, ensuring spec compliance.
class BasicInformationCluster : public DefaultServerCluster, public DeviceLayer::PlatformManagerDelegate
{
public:
using OptionalAttributesSet = chip::app::OptionalAttributeSet< //
BasicInformation::Attributes::ManufacturingDate::Id, //
BasicInformation::Attributes::PartNumber::Id, //
BasicInformation::Attributes::ProductURL::Id, //
BasicInformation::Attributes::ProductLabel::Id, //
BasicInformation::Attributes::SerialNumber::Id, //
BasicInformation::Attributes::LocalConfigDisabled::Id, //
BasicInformation::Attributes::Reachable::Id, //
BasicInformation::Attributes::ProductAppearance::Id, //
// Old specification versions had UniqueID as optional, so this
// appears here even though MANDATORY in the latest spec. We
// default it enabled (to decrease chances of error)
BasicInformation::Attributes::UniqueID::Id //
>;
BasicInformationCluster(OptionalAttributesSet optionalAttributeSet, BasicInformation::BasicInformationDelegate * delegate,
DeviceLayer::PlatformManager & platformManager) :
DefaultServerCluster({ kRootEndpointId, BasicInformation::Id }),
mEnabledOptionalAttributes(optionalAttributeSet), mDelegate(delegate), mPlatformManager(platformManager)
{
mEnabledOptionalAttributes
.Set<BasicInformation::Attributes::UniqueID::Id>(); // Unless told otherwise, unique id is mandatory
}
OptionalAttributesSet & OptionalAttributes() { return mEnabledOptionalAttributes; }
// Server cluster implementation
CHIP_ERROR Startup(ServerClusterContext & context) override;
void Shutdown(ClusterShutdownType type) override;
DataModel::ActionReturnStatus ReadAttribute(const DataModel::ReadAttributeRequest & request,
AttributeValueEncoder & encoder) override;
DataModel::ActionReturnStatus WriteAttribute(const DataModel::WriteAttributeRequest & request,
AttributeValueDecoder & decoder) override;
CHIP_ERROR Attributes(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<DataModel::AttributeEntry> & builder) override;
// PlatformManagerDelegate
/**
* @brief Initialize the cluster
*
* This method attempts to register the cluster as the DeviceLayer::PlatformManagerDelegate
* to receive system shutdown events (OnShutDown).
* * NOTE: Registration is conditional. It will ONLY register this cluster as the delegate
* if the PlatformManager does not currently have a delegate set. If the application
* has already registered a delegate, this cluster will respect that configuration
* and will NOT overwrite it.
*/
void OnStartUp(uint32_t softwareVersion) override;
void OnShutDown() override;
// ConfigurationVersionDelegate, however NOT overridable to save
// some flash in case this feature is never used. This means applications that may
// change configurations at runtime pay a bit more flash, however those are probably more
// dynamic (i.e. larger) systems like bridges or more complex systems.
CHIP_ERROR IncreaseConfigurationVersion();
private:
// write without notification
DataModel::ActionReturnStatus WriteImpl(const DataModel::WriteAttributeRequest & request, AttributeValueDecoder & decoder);
OptionalAttributesSet mEnabledOptionalAttributes;
Storage::String<32> mNodeLabel;
BasicInformation::BasicInformationDelegate * mDelegate;
DeviceLayer::PlatformManager & mPlatformManager;
};
} // namespace Clusters
} // namespace app
} // namespace chip