Coverage Report

Created: 2026-05-16 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/connectedhomeip/examples/providers/DeviceInfoProviderImpl.h
Line
Count
Source
1
/*
2
 *
3
 *    Copyright (c) 2022 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
19
#include <lib/support/EnforceFormat.h>
20
#include <platform/DeviceInfoProvider.h>
21
22
namespace chip {
23
namespace DeviceLayer {
24
25
// !!!!!!!!!!!!!!!!!!!!!!!! WARNING WARNING WARNING !!!!!!!!!!!!!!!!!!!!
26
// WARNING: DO NOT USE THESE DEFAULT IMPLEMENTATIONS WITH DEFAULT VALUES
27
// IN PRODUCTION PRODUCTS WITHOUT AUDITING THEM! See
28
// `AllClustersExampleDeviceInforProviderImpl.h` for an example provider
29
// that has constant values. Here, all providers have empty implementations
30
// to force empty lists which prevent bad values from leaking into products
31
// like happened before Matter 1.5. If you really are using these clusters,
32
// then please re-implement the provider as needed.
33
//
34
// The FixedLabel, LocalizationConfigurationand and Time Format localization
35
// clusters, if used, should have values that have been vetted
36
// for correctness in the product !!! DO NOT USE SAMPLE DEFAULTS IN PRODUCTS.
37
// !!!!!!!!!!!!!!!!!!!!!!!! WARNING WARNING WARNING !!!!!!!!!!!!!!!!!!!!
38
39
class DeviceInfoProviderImpl : public DeviceInfoProvider
40
{
41
public:
42
    DeviceInfoProviderImpl() = default;
43
0
    ~DeviceInfoProviderImpl() override {}
44
45
    // Iterators
46
    FixedLabelIterator * IterateFixedLabel(EndpointId endpoint) override;
47
    UserLabelIterator * IterateUserLabel(EndpointId endpoint) override;
48
    SupportedLocalesIterator * IterateSupportedLocales() override;
49
    SupportedCalendarTypesIterator * IterateSupportedCalendarTypes() override;
50
51
    static DeviceInfoProviderImpl & GetDefaultInstance();
52
53
protected:
54
    class UserLabelIteratorImpl : public UserLabelIterator
55
    {
56
    public:
57
        UserLabelIteratorImpl(DeviceInfoProviderImpl & provider, EndpointId endpoint);
58
0
        size_t Count() override { return mTotal; }
59
        bool Next(UserLabelType & output) override;
60
0
        void Release() override { chip::Platform::Delete(this); }
61
62
    private:
63
        DeviceInfoProviderImpl & mProvider;
64
        EndpointId mEndpoint = 0;
65
        size_t mIndex        = 0;
66
        size_t mTotal        = 0;
67
        char mUserLabelNameBuf[kMaxLabelNameLength + 1];
68
        char mUserLabelValueBuf[kMaxLabelValueLength + 1];
69
    };
70
71
    class SupportedLocalesIteratorImpl : public SupportedLocalesIterator
72
    {
73
    public:
74
0
        SupportedLocalesIteratorImpl() = default;
75
        size_t Count() override;
76
        bool Next(CharSpan & output) override;
77
0
        void Release() override { chip::Platform::Delete(this); }
78
79
    private:
80
        static constexpr size_t kNumSupportedLocales = 1;
81
        size_t mIndex                                = 0;
82
    };
83
84
    class SupportedCalendarTypesIteratorImpl : public SupportedCalendarTypesIterator
85
    {
86
    public:
87
0
        SupportedCalendarTypesIteratorImpl() = default;
88
        size_t Count() override;
89
        bool Next(CalendarType & output) override;
90
0
        void Release() override { chip::Platform::Delete(this); }
91
92
    private:
93
        static constexpr size_t kNumSupportedCalendarTypes = 1;
94
        size_t mIndex                                      = 0;
95
    };
96
97
    CHIP_ERROR SetUserLabelLength(EndpointId endpoint, size_t val) override;
98
    CHIP_ERROR GetUserLabelLength(EndpointId endpoint, size_t & val) override;
99
    CHIP_ERROR SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) override;
100
    CHIP_ERROR DeleteUserLabelAt(EndpointId endpoint, size_t index) override;
101
102
private:
103
0
    static constexpr size_t UserLabelTLVMaxSize() { return TLV::EstimateStructOverhead(kMaxLabelNameLength, kMaxLabelValueLength); }
104
};
105
106
} // namespace DeviceLayer
107
} // namespace chip