Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying ReplacementProductListManager to be generic #28185

Merged
merged 36 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
58f7a50
Modifying ReplacementProductListManager to be generic
cliffamzn Jul 21, 2023
53c50eb
Restyled by whitespace
restyled-commits Jul 21, 2023
f9ed8b9
Restyled by clang-format
restyled-commits Jul 21, 2023
3bbb797
Passing error back up
cliffamzn Jul 22, 2023
138de15
Merge branch 'master' into replacement-product-fix
cliffamzn Jul 22, 2023
3e0a655
Apply @bzbarsky-apple's suggestions from code review
cliffamzn Jul 25, 2023
f131838
Merge branch 'project-chip:master' into replacement-product-fix
cliffamzn Jul 25, 2023
60586e3
Integrating Borris' comments into ReplacementProductStruct
cliffamzn Jul 25, 2023
debbe5e
Restyled by whitespace
restyled-commits Jul 25, 2023
42d0d18
Restyled by clang-format
restyled-commits Jul 25, 2023
72a588a
Restyled by prettier-yaml
restyled-commits Jul 25, 2023
9de8518
Adding Tests for ResourceMonitor to ci tests list
cliffamzn Jul 25, 2023
623b42c
Restyled by prettier-yaml
restyled-commits Jul 25, 2023
399ff30
Adding newly generated zap files
cliffamzn Jul 25, 2023
73e8a95
Replaced the use of std::set with IntrusiveList in ModeBase. (#28163)
hicklin Jul 25, 2023
1c2f26d
Remove unwanted "\" at line 156 from DA-1.4 test (#28252)
manjunath-grl Jul 25, 2023
baa4eb0
Remove zap development install. (#28223)
mikaelhm Jul 25, 2023
b598ad6
[feature]Add dishwasher-app example for ASR platform (#28207)
mideayanghui Jul 25, 2023
0c25d18
[ Java] Decouple generated API in build option (#27624)
joonhaengHeo Jul 25, 2023
37f7188
Revert "[ Java] Decouple generated API in build option (#27624)" (#28…
andy31415 Jul 25, 2023
9a6feb4
[ASR] update device manager (#28251)
tx2rx Jul 25, 2023
aef213a
Add RVC device type to XML + fix RVC Clean/Run XML issue (#28239)
plauric Jul 25, 2023
a55fbb4
Make C++17 the default everywhere (#28269)
andy31415 Jul 25, 2023
4963c26
Add ipv6only build for rpc target, to not run out of ram when linking…
andy31415 Jul 25, 2023
ae10124
Attempting to fix error ` error: 'ReplacementProductStruct' was not
cliffamzn Jul 25, 2023
a20f485
Merge branch 'project-chip:master' into replacement-product-fix
cliffamzn Jul 25, 2023
f6d1305
Modifying the placeholder app to have example output
cliffamzn Jul 26, 2023
11802f7
Moved around the ReplacementProductStruct to the ResourceMonitoring
cliffamzn Jul 26, 2023
aa6e303
Restyled by whitespace
restyled-commits Jul 26, 2023
8e91c35
Restyled by clang-format
restyled-commits Jul 26, 2023
84ccb8e
Removing commented out code
cliffamzn Jul 26, 2023
64b5316
Changing DynamicReplacementProductListManager to an
cliffamzn Jul 26, 2023
cc9622a
Overriding the = operation to always do a copy
cliffamzn Jul 26, 2023
021040a
Restyled by whitespace
restyled-commits Jul 26, 2023
4c34b66
Restyled by clang-format
restyled-commits Jul 26, 2023
26ef1aa
Adding back the instance of the ReplacementProductList so that it can be
cliffamzn Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,9 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor
aResetConditionCommandSupported){};
};

class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager
class ImmutableReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager
{
public:
uint8_t Size() override { return mReplacementProductListSize; };

CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type & item) override;

~StaticReplacementProductListManager() {}
StaticReplacementProductListManager(
chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * aReplacementProductsList,
uint8_t aReplacementProductListSize)
{
mReplacementProductsList = aReplacementProductsList;
mReplacementProductListSize = aReplacementProductListSize;
}

private:
chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * mReplacementProductsList;
uint8_t mReplacementProductListSize;
CHIP_ERROR
Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,7 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast<uint32_t>(Featu

static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr;
static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr;

static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sReplacementProductsList[] = {
{ .productIdentifierType = ProductIdentifierTypeEnum::kUpc,
.productIdentifierValue = CharSpan::fromCharString("111112222233") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kGtin8, .productIdentifierValue = CharSpan::fromCharString("gtin8xxx") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kEan,
.productIdentifierValue = CharSpan::fromCharString("4444455555666") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kGtin14,
.productIdentifierValue = CharSpan::fromCharString("gtin14xxxxxxxx") },
{ .productIdentifierType = ProductIdentifierTypeEnum::kOem,
.productIdentifierValue = CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") },
};
StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0],
ArraySize(sReplacementProductsList));
static ImmutableReplacementProductListManager sReplacementProductListManager;

//-- Activated Carbon Filter Monitoring Instance methods
CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit()
Expand Down Expand Up @@ -106,14 +93,40 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint)
gHepaFilterInstance->Init();
}

CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::ReplacementProductStruct::Type & item)
CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct & item)
{
if (mIndex < mReplacementProductListSize)
if (mIndex >= kReplacementProductListMaxSize)
{
item = mReplacementProductsList[mIndex];
mIndex++;
return CHIP_NO_ERROR;
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}

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;
}
1 change: 1 addition & 0 deletions examples/placeholder/linux/apps/app1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source_set("app1") {
]

sources = [
"../../resource-monitoring-instances.cpp",
"../../src/bridged-actions-stub.cpp",
"../../static-supported-modes-manager.cpp",
]
Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/apps/app2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source_set("app2") {
]

sources = [
"../../resource-monitoring-instances.cpp",
"../../src/bridged-actions-stub.cpp",
"../../static-supported-modes-manager.cpp",
]
Expand Down
63 changes: 63 additions & 0 deletions examples/placeholder/linux/include/resource-monitoring-instances.h
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 examples/placeholder/linux/resource-monitoring-instances.cpp
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;
}
2 changes: 1 addition & 1 deletion examples/resource-monitoring-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ config("includes") {

executable("chip-resource-monitoring-app") {
sources = [
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp",
"${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepaFilterMonitoring.cpp",
"include/CHIPProjectAppConfig.h",
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,17 @@ namespace ResourceMonitoring {
class StaticReplacementProductListManager : public ReplacementProductListManager
{
public:
uint8_t Size() override { return mReplacementProductListSize; };

CHIP_ERROR Next(Attributes::ReplacementProductStruct::Type & item) override;
CHIP_ERROR Next(ReplacementProductStruct & item) override;

~StaticReplacementProductListManager() {}
StaticReplacementProductListManager(Attributes::ReplacementProductStruct::Type * aReplacementProductsList,
uint8_t aReplacementProductListSize)
StaticReplacementProductListManager(ReplacementProductStruct * aReplacementProductsList, uint8_t aReplacementProductListSize)
{
mReplacementProductsList = aReplacementProductsList;
mReplacementProductListSize = aReplacementProductListSize;
}

private:
Attributes::ReplacementProductStruct::Type * mReplacementProductsList;
ReplacementProductStruct * mReplacementProductsList;
uint8_t mReplacementProductListSize;
};

Expand Down
Loading