|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2024 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 | +#include <app/clusters/power-topology-server/power-topology-server.h> |
| 20 | + |
| 21 | +using namespace chip; |
| 22 | +using namespace chip::app::Clusters; |
| 23 | +using namespace chip::app::Clusters::PowerTopology; |
| 24 | + |
| 25 | +namespace chip { |
| 26 | +namespace app { |
| 27 | +namespace Clusters { |
| 28 | +namespace PowerTopology { |
| 29 | + |
| 30 | +class PowerTopologyDelegate : public Delegate |
| 31 | +{ |
| 32 | +public: |
| 33 | + ~PowerTopologyDelegate() = default; |
| 34 | + |
| 35 | + CHIP_ERROR GetAvailableEndpointAtIndex(size_t index, EndpointId & endpointId) override; |
| 36 | + CHIP_ERROR GetActiveEndpointAtIndex(size_t index, EndpointId & endpointId) override; |
| 37 | +}; |
| 38 | + |
| 39 | +CHIP_ERROR PowerTopologyDelegate::GetAvailableEndpointAtIndex(size_t index, EndpointId & endpointId) |
| 40 | +{ |
| 41 | + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; |
| 42 | +} |
| 43 | + |
| 44 | +CHIP_ERROR PowerTopologyDelegate::GetActiveEndpointAtIndex(size_t index, EndpointId & endpointId) |
| 45 | +{ |
| 46 | + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; |
| 47 | +} |
| 48 | + |
| 49 | +} // namespace PowerTopology |
| 50 | +} // namespace Clusters |
| 51 | +} // namespace app |
| 52 | +} // namespace chip |
| 53 | + |
| 54 | +static std::unique_ptr<PowerTopology::Delegate> gDelegate; |
| 55 | +static std::unique_ptr<PowerTopology::Instance> gInstance; |
| 56 | + |
| 57 | +void emberAfPowerTopologyClusterInitCallback(chip::EndpointId endpointId) |
| 58 | +{ |
| 59 | + VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. |
| 60 | + VerifyOrDie(!gInstance); |
| 61 | + |
| 62 | + gDelegate = std::make_unique<PowerTopologyDelegate>(); |
| 63 | + if (gDelegate) |
| 64 | + { |
| 65 | + gInstance = std::make_unique<Instance>( |
| 66 | + endpointId, *gDelegate, BitMask<Feature, uint32_t>(Feature::kSetTopology, Feature::kDynamicPowerFlow), |
| 67 | + BitMask<OptionalAttributes, uint32_t>(OptionalAttributes::kOptionalAttributeAvailableEndpoints, |
| 68 | + OptionalAttributes::kOptionalAttributeActiveEndpoints)); |
| 69 | + |
| 70 | + gInstance->Init(); |
| 71 | + } |
| 72 | +} |
0 commit comments