Coverage Report

Created: 2025-08-28 06:31

/src/connectedhomeip/src/app/clusters/low-power-server/low-power-server.cpp
Line
Count
Source (jump to first uncovered line)
1
/**
2
 *
3
 *    Copyright (c) 2021 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
/****************************************************************************
19
 * @file
20
 * @brief Routines for the Low Power plugin, the
21
 *server implementation of the Low Power cluster.
22
 *******************************************************************************
23
 ******************************************************************************/
24
25
#include <app/clusters/low-power-server/low-power-delegate.h>
26
#include <app/clusters/low-power-server/low-power-server.h>
27
28
#include <app/CommandHandler.h>
29
#include <app/ConcreteCommandPath.h>
30
#include <app/util/attribute-storage.h>
31
#include <app/util/config.h>
32
#include <platform/CHIPDeviceConfig.h>
33
#include <protocols/interaction_model/StatusCode.h>
34
#include <tracing/macros.h>
35
36
using namespace chip;
37
using namespace chip::app::Clusters;
38
using namespace chip::app::Clusters::LowPower;
39
40
static constexpr size_t kLowPowerDelegateTableSize =
41
    MATTER_DM_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
42
static_assert(kLowPowerDelegateTableSize <= kEmberInvalidEndpointIndex, "LowPower Delegate table size error");
43
44
// -----------------------------------------------------------------------------
45
// Delegate Implementation
46
47
using chip::app::Clusters::LowPower::Delegate;
48
49
namespace {
50
51
Delegate * gDelegateTable[kLowPowerDelegateTableSize] = { nullptr };
52
53
Delegate * GetDelegate(EndpointId endpoint)
54
0
{
55
0
    uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id,
56
0
                                                       MATTER_DM_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT);
57
0
    return (ep >= kLowPowerDelegateTableSize ? nullptr : gDelegateTable[ep]);
58
0
}
59
60
bool isDelegateNull(Delegate * delegate, EndpointId endpoint)
61
0
{
62
0
    if (delegate == nullptr)
63
0
    {
64
0
        ChipLogProgress(Zcl, "LowPower has no delegate set for endpoint:%u", endpoint);
65
0
        return true;
66
0
    }
67
0
    return false;
68
0
}
69
} // namespace
70
71
namespace chip {
72
namespace app {
73
namespace Clusters {
74
namespace LowPower {
75
76
void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate)
77
1
{
78
1
    uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, chip::app::Clusters::LowPower::Id,
79
1
                                                       MATTER_DM_LOW_POWER_CLUSTER_SERVER_ENDPOINT_COUNT);
80
1
    if (ep < kLowPowerDelegateTableSize)
81
1
    {
82
1
        gDelegateTable[ep] = delegate;
83
1
    }
84
0
    else
85
0
    {
86
0
    }
87
1
}
88
89
} // namespace LowPower
90
} // namespace Clusters
91
} // namespace app
92
} // namespace chip
93
94
bool emberAfLowPowerClusterSleepCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath,
95
                                         const Commands::Sleep::DecodableType & commandData)
96
0
{
97
0
    MATTER_TRACE_SCOPE("Sleep", "LowPower");
98
0
    using Protocols::InteractionModel::Status;
99
100
0
    EndpointId endpoint = commandPath.mEndpointId;
101
102
0
    Delegate * delegate = GetDelegate(endpoint);
103
0
    Status status;
104
0
    if (isDelegateNull(delegate, endpoint))
105
0
    {
106
0
        ChipLogError(Zcl, "emberAfLowPowerClusterSleepCallback: no delegate");
107
0
        status = Status::Failure;
108
0
    }
109
0
    else
110
0
    {
111
0
        bool success = delegate->HandleSleep();
112
0
        status       = success ? Status::Success : Status::Failure;
113
0
    }
114
0
    command->AddStatus(commandPath, status);
115
0
    return true;
116
0
}
117
118
1
void MatterLowPowerPluginServerInitCallback() {}
119
0
void MatterLowPowerPluginServerShutdownCallback() {}