Coverage Report

Created: 2026-05-16 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/connectedhomeip/src/app/clusters/actions-server/ActionsStructs.h
Line
Count
Source
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 <clusters/Actions/Structs.h>
21
#include <lib/support/CodeUtils.h>
22
23
namespace chip {
24
namespace app {
25
namespace Clusters {
26
namespace Actions {
27
28
static constexpr size_t kActionNameMaxSize       = 128u;
29
static constexpr size_t kEndpointListNameMaxSize = 128u;
30
static constexpr size_t kEndpointListMaxSize     = 256u;
31
32
struct ActionStructStorage : public Structs::ActionStruct::Type
33
{
34
0
    ActionStructStorage(){};
35
36
    ActionStructStorage(uint16_t aAction, const CharSpan & aActionName, ActionTypeEnum aActionType, uint16_t aEpListID,
37
                        BitMask<CommandBits> aCommands, ActionStateEnum aActionState)
38
0
    {
39
0
        Set(aAction, aActionName, aActionType, aEpListID, aCommands, aActionState);
40
0
    }
41
42
0
    ActionStructStorage(const ActionStructStorage & aAction) { *this = aAction; }
43
44
    ActionStructStorage & operator=(const ActionStructStorage & aAction)
45
0
    {
46
0
        Set(aAction.actionID, aAction.name, aAction.type, aAction.endpointListID, aAction.supportedCommands, aAction.state);
47
0
        return *this;
48
0
    }
49
50
    void Set(uint16_t aAction, const CharSpan & aActionName, ActionTypeEnum aActionType, uint16_t aEpListID,
51
             BitMask<CommandBits> aCommands, ActionStateEnum aActionState)
52
0
    {
53
0
        actionID          = aAction;
54
0
        type              = aActionType;
55
0
        endpointListID    = aEpListID;
56
0
        supportedCommands = aCommands;
57
0
        state             = aActionState;
58
0
        MutableCharSpan actionName(mBuffer);
59
0
        CopyCharSpanToMutableCharSpanWithTruncation(aActionName, actionName);
60
0
        name = actionName;
61
0
    }
62
63
private:
64
    char mBuffer[kActionNameMaxSize];
65
};
66
67
struct EndpointListStorage : public Structs::EndpointListStruct::Type
68
{
69
0
    EndpointListStorage(){};
70
71
    EndpointListStorage(uint16_t aEpListId, const CharSpan & aEpListName, EndpointListTypeEnum aEpListType,
72
                        const DataModel::List<const EndpointId> & aEndpointList)
73
0
    {
74
0
        Set(aEpListId, aEpListName, aEpListType, aEndpointList);
75
0
    }
76
77
0
    EndpointListStorage(const EndpointListStorage & aEpList) { *this = aEpList; }
78
79
    EndpointListStorage & operator=(const EndpointListStorage & aEpList)
80
0
    {
81
0
        Set(aEpList.endpointListID, aEpList.name, aEpList.type, aEpList.endpoints);
82
0
        return *this;
83
0
    }
84
85
    void Set(uint16_t aEpListId, const CharSpan & aEpListName, EndpointListTypeEnum aEpListType,
86
             const DataModel::List<const EndpointId> & aEndpointList)
87
0
    {
88
0
        endpointListID    = aEpListId;
89
0
        type              = aEpListType;
90
0
        size_t epListSize = std::min(aEndpointList.size(), MATTER_ARRAY_SIZE(mEpList));
91
92
0
        for (size_t index = 0; index < epListSize; index++)
93
0
        {
94
0
            mEpList[index] = aEndpointList[index];
95
0
        }
96
0
        endpoints = DataModel::List<const EndpointId>(Span(mEpList, epListSize));
97
0
        MutableCharSpan epListName(mBuffer);
98
0
        CopyCharSpanToMutableCharSpanWithTruncation(aEpListName, epListName);
99
0
        name = epListName;
100
0
    }
101
102
private:
103
    char mBuffer[kEndpointListNameMaxSize];
104
    EndpointId mEpList[kEndpointListMaxSize];
105
};
106
107
} // namespace Actions
108
} // namespace Clusters
109
} // namespace app
110
} // namespace chip