-
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.
Modifying ReplacementProductListManager to be generic (#28185)
* Modifying ReplacementProductListManager to be generic Addressing feedback from PR #28095 and also addressing #28148 This change simplifies the implementation of the ReplacementProductList and also introduces a DynamicReplacementProductList example which better represents devices fetching this product list from flash. It includes some simplifications to the structure of the code and a few additional unit tests to exercise the behavior. Tested to ensure functionality still works as expected using the all-clusters-app as well as the resource-monitoring-app
- Loading branch information
Showing
22 changed files
with
1,108 additions
and
171 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
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
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
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
63 changes: 63 additions & 0 deletions
63
examples/placeholder/linux/include/resource-monitoring-instances.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,63 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <app-common/zap-generated/ids/Attributes.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h> | ||
#include <app/clusters/resource-monitoring-server/resource-monitoring-server.h> | ||
|
||
/// This is an application level Instance to handle ActivatedCarbonfilterMonitoringInstance commands according to the specific | ||
/// business logic. | ||
class ActivatedCarbonFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance | ||
{ | ||
private: | ||
CHIP_ERROR AppInit() override; | ||
chip::Protocols::InteractionModel::Status PreResetCondition() override; | ||
chip::Protocols::InteractionModel::Status PostResetCondition() override; | ||
|
||
public: | ||
ActivatedCarbonFilterMonitoringInstance( | ||
chip::EndpointId aEndpointId, uint32_t aFeature, | ||
chip::app::Clusters::ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, | ||
bool aResetConditionCommandSupported) : | ||
Instance(aEndpointId, chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id, aFeature, aDegradationDirection, | ||
aResetConditionCommandSupported){}; | ||
}; | ||
|
||
/// This is an application level instance to handle HepaFilterMonitoringInstance commands according to the specific business logic. | ||
class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance | ||
{ | ||
private: | ||
CHIP_ERROR AppInit() override; | ||
chip::Protocols::InteractionModel::Status PreResetCondition() override; | ||
chip::Protocols::InteractionModel::Status PostResetCondition() override; | ||
|
||
public: | ||
HepaFilterMonitoringInstance( | ||
chip::EndpointId aEndpointId, uint32_t aFeature, | ||
chip::app::Clusters::ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, | ||
bool aResetConditionCommandSupported) : | ||
Instance(aEndpointId, chip::app::Clusters::HepaFilterMonitoring::Id, aFeature, aDegradationDirection, | ||
aResetConditionCommandSupported){}; | ||
}; | ||
|
||
class ImmutableReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager | ||
{ | ||
public: | ||
CHIP_ERROR | ||
Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; | ||
}; |
133 changes: 133 additions & 0 deletions
133
examples/placeholder/linux/resource-monitoring-instances.cpp
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,133 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <app-common/zap-generated/ids/Attributes.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h> | ||
#include <app/clusters/resource-monitoring-server/resource-monitoring-server.h> | ||
#include <resource-monitoring-instances.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters; | ||
using namespace chip::app::Clusters::ResourceMonitoring; | ||
using chip::Protocols::InteractionModel::Status; | ||
|
||
constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast<uint32_t>(Feature::kCondition) | | ||
static_cast<uint32_t>(Feature::kWarning) | | ||
static_cast<uint32_t>(Feature::kReplacementProductList) }; | ||
constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Feature::kCondition) | | ||
static_cast<uint32_t>(Feature::kWarning) | | ||
static_cast<uint32_t>(Feature::kReplacementProductList) }; | ||
|
||
static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; | ||
static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; | ||
|
||
static ImmutableReplacementProductListManager sReplacementProductListManager; | ||
|
||
//-- Activated Carbon Filter Monitoring Instance methods | ||
CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() | ||
{ | ||
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()"); | ||
SetReplacementProductListManagerInstance(&sReplacementProductListManager); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
Status ActivatedCarbonFilterMonitoringInstance::PreResetCondition() | ||
{ | ||
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PreResetCondition()"); | ||
return Status::Success; | ||
} | ||
|
||
Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition() | ||
{ | ||
ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PostResetCondition()"); | ||
return Status::Success; | ||
} | ||
|
||
//-- Hepa Filter Monitoring instance methods | ||
CHIP_ERROR HepaFilterMonitoringInstance::AppInit() | ||
{ | ||
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); | ||
SetReplacementProductListManagerInstance(&sReplacementProductListManager); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
Status HepaFilterMonitoringInstance::PreResetCondition() | ||
{ | ||
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PreResetCondition()"); | ||
return Status::Success; | ||
} | ||
|
||
Status HepaFilterMonitoringInstance::PostResetCondition() | ||
{ | ||
ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PostResetCondition()"); | ||
return Status::Success; | ||
} | ||
|
||
void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) | ||
{ | ||
VerifyOrDie(gActivatedCarbonFilterInstance == nullptr); | ||
gActivatedCarbonFilterInstance = new ActivatedCarbonFilterMonitoringInstance( | ||
endpoint, static_cast<uint32_t>(gActivatedCarbonFeatureMap.to_ulong()), DegradationDirectionEnum::kDown, true); | ||
gActivatedCarbonFilterInstance->Init(); | ||
} | ||
void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) | ||
{ | ||
VerifyOrDie(gHepaFilterInstance == nullptr); | ||
gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast<uint32_t>(gHepaFilterFeatureMap.to_ulong()), | ||
DegradationDirectionEnum::kDown, true); | ||
gHepaFilterInstance->Init(); | ||
} | ||
|
||
CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct & item) | ||
{ | ||
if (mIndex >= kReplacementProductListMaxSize) | ||
{ | ||
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; | ||
} | ||
|
||
switch (mIndex) | ||
{ | ||
case 0: { | ||
item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); | ||
item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); | ||
break; | ||
case 1: | ||
item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); | ||
item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); | ||
break; | ||
case 2: | ||
item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); | ||
item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); | ||
break; | ||
case 3: | ||
item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); | ||
item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); | ||
break; | ||
case 4: | ||
item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); | ||
item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); | ||
break; | ||
default: | ||
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; | ||
break; | ||
} | ||
} | ||
mIndex++; | ||
return CHIP_NO_ERROR; | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...onitoring-app/resource-monitoring-common/include/ImmutableReplacementProductListManager.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,44 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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/clusters/resource-monitoring-server/replacement-product-list-manager.h> | ||
#include <app/util/af.h> | ||
#include <app/util/config.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace ResourceMonitoring { | ||
|
||
/** | ||
* This implementation returns an immutable list of replacement products. | ||
* It holds ReplacementProductListManager::kReplacementProductListMaxSize products in the list. | ||
*/ | ||
|
||
class ImmutableReplacementProductListManager : public ReplacementProductListManager | ||
{ | ||
public: | ||
CHIP_ERROR Next(ReplacementProductStruct & item) override; | ||
}; | ||
|
||
} // namespace ResourceMonitoring | ||
} // 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.