-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Power source: Implementation of dynamic endpoint list setter (#28110)
* Implementation of dynamic endpoint list setter Test: tested by adding a call to set endpoint list in all clusters with chip-tool. Also see TestPowerSourceCluster.cpp * Restyled by whitespace * Restyled by gn * Remove the define Some platforms run these tests, but don't have that define defined. Instead, just change the function name to test only. * Address review comments * free is being called, man, where's the leak? * Restyled by clang-format * Address some review comments. * Fix leak. * Deal with zero-length arrays. * shutdown -> clear * Use EncodeList for list * test fix. * types need to match --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
27c3ff4
commit 45e9715
Showing
4 changed files
with
583 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/app/clusters/power-source-server/power-source-server.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* | ||
* 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-common/zap-generated/ids/Clusters.h> | ||
#include <app/AttributeAccessInterface.h> | ||
#include <app/util/af-types.h> | ||
#include <app/util/basic-types.h> | ||
#include <lib/support/Span.h> | ||
#include <platform/CHIPDeviceConfig.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
|
||
class PowerSourceServer | ||
{ | ||
public: | ||
static PowerSourceServer & Instance(); | ||
|
||
// Caller does not need to retain the span past the call point as these are copied into an internal storage | ||
CHIP_ERROR SetEndpointList(EndpointId powerSourceClusterEndpoint, Span<EndpointId> endpointList); | ||
CHIP_ERROR ClearEndpointList(EndpointId powerSourceClusterEndpoint) | ||
{ | ||
return SetEndpointList(powerSourceClusterEndpoint, Span<EndpointId>()); | ||
} | ||
// returns nullptr if there's not endpoint list set for this power source cluster endpoint id. | ||
const Span<EndpointId> * GetEndpointList(EndpointId powerSourceClusterEndpoint) const; | ||
void Shutdown(); | ||
size_t GetNumSupportedEndpointLists() const; | ||
|
||
private: | ||
// Both return std::numeric_limits<size_t>::max() for not found | ||
size_t PowerSourceClusterEndpointIndex(EndpointId endpointId) const; | ||
size_t NextEmptyIndex() const; | ||
}; | ||
|
||
class PowerSourceAttrAccess : public AttributeAccessInterface | ||
{ | ||
public: | ||
// Register on all endpoints. | ||
PowerSourceAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), PowerSource::Id) {} | ||
|
||
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; | ||
}; | ||
|
||
PowerSourceAttrAccess & TestOnlyGetPowerSourceAttrAccess(); | ||
|
||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.