diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-delegates.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-delegates.h new file mode 100644 index 00000000000000..ea7aecd59b736f --- /dev/null +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-delegates.h @@ -0,0 +1,71 @@ +/* + * + * 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 +#include +#include +#include + +namespace chip { +namespace app { +namespace Clusters { + +namespace ActivatedCarbonFilterMonitoring { +/// This is an application level Delegate to handle ActivatedCarbonfilterMonitoringDelegate commands according to the specific +/// business logic. +class ActivatedCarbonFilterMonitoringDelegate : public ResourceMonitoring::Delegate +{ +private: + CHIP_ERROR Init() override; + chip::Protocols::InteractionModel::Status PreResetCondition() override; + chip::Protocols::InteractionModel::Status PostResetCondition() override; + +public: + ~ActivatedCarbonFilterMonitoringDelegate() override = default; +}; + +void Shutdown(); + +} // namespace ActivatedCarbonFilterMonitoring + +namespace HepaFilterMonitoring { +/// This is an application level Delegate to handle HepaFilterMonitoringDelegate commands according to the specific business logic. +class HepaFilterMonitoringDelegate : public ResourceMonitoring::Delegate +{ +private: + CHIP_ERROR Init() override; + chip::Protocols::InteractionModel::Status PreResetCondition() override; + chip::Protocols::InteractionModel::Status PostResetCondition() override; + +public: + ~HepaFilterMonitoringDelegate() override = default; +}; + +class ImmutableReplacementProductListManager : public ResourceMonitoring::ReplacementProductListManager +{ +public: + CHIP_ERROR + Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; +}; + +void Shutdown(); + +} // namespace HepaFilterMonitoring + +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp similarity index 50% rename from examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp rename to examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp index dc4283539b437b..e0924b8b5c0a30 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp @@ -19,77 +19,117 @@ #include #include #include -#include +#include using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; +using namespace chip::app::Clusters::ActivatedCarbonFilterMonitoring; +using namespace chip::app::Clusters::HepaFilterMonitoring; using chip::Protocols::InteractionModel::Status; -constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(Feature::kCondition) | - static_cast(Feature::kWarning) | - static_cast(Feature::kReplacementProductList) }; -constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Feature::kCondition) | - static_cast(Feature::kWarning) | - static_cast(Feature::kReplacementProductList) }; +constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(ResourceMonitoring::Feature::kCondition) | + static_cast(ResourceMonitoring::Feature::kWarning) | + static_cast(ResourceMonitoring::Feature::kReplacementProductList) }; +constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(ResourceMonitoring::Feature::kCondition) | + static_cast(ResourceMonitoring::Feature::kWarning) | + static_cast(ResourceMonitoring::Feature::kReplacementProductList) }; + +static ActivatedCarbonFilterMonitoringDelegate * gActivatedCarbonFilterDelegate = nullptr; +static ResourceMonitoring::Instance * gActivatedCarbonFilterInstance = nullptr; + +static HepaFilterMonitoringDelegate * gHepaFilterDelegate = nullptr; +static ResourceMonitoring::Instance * gHepaFilterInstance = nullptr; -static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; -static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; static ImmutableReplacementProductListManager sReplacementProductListManager; -//-- Activated Carbon Filter Monitoring Instance methods -CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() +//-- Activated Carbon Filter Monitoring delegate methods +CHIP_ERROR ActivatedCarbonFilterMonitoringDelegate::Init() { ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()"); - SetReplacementProductListManagerInstance(&sReplacementProductListManager); + GetInstance()->SetReplacementProductListManagerInstance(&sReplacementProductListManager); return CHIP_NO_ERROR; } -Status ActivatedCarbonFilterMonitoringInstance::PreResetCondition() +Status ActivatedCarbonFilterMonitoringDelegate::PreResetCondition() { - ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PreResetCondition()"); + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::PreResetCondition()"); return Status::Success; } -Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition() +Status ActivatedCarbonFilterMonitoringDelegate::PostResetCondition() { - ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PostResetCondition()"); + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::PostResetCondition()"); return Status::Success; } -//-- Hepa Filter Monitoring instance methods -CHIP_ERROR HepaFilterMonitoringInstance::AppInit() +void ActivatedCarbonFilterMonitoring::Shutdown() +{ + if (gActivatedCarbonFilterInstance != nullptr) + { + delete gActivatedCarbonFilterInstance; + gActivatedCarbonFilterInstance = nullptr; + } + if (gActivatedCarbonFilterDelegate != nullptr) + { + delete gActivatedCarbonFilterDelegate; + gActivatedCarbonFilterDelegate = nullptr; + } +} + +//-- Hepa Filter Monitoring delegate methods +CHIP_ERROR HepaFilterMonitoringDelegate::Init() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - SetReplacementProductListManagerInstance(&sReplacementProductListManager); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::Init()"); + GetInstance()->SetReplacementProductListManagerInstance(&sReplacementProductListManager); return CHIP_NO_ERROR; } -Status HepaFilterMonitoringInstance::PreResetCondition() +Status HepaFilterMonitoringDelegate::PreResetCondition() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PreResetCondition()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::PreResetCondition()"); return Status::Success; } -Status HepaFilterMonitoringInstance::PostResetCondition() +Status HepaFilterMonitoringDelegate::PostResetCondition() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PostResetCondition()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::PostResetCondition()"); return Status::Success; } +void HepaFilterMonitoring::Shutdown() +{ + if (gHepaFilterInstance != nullptr) + { + delete gHepaFilterInstance; + gHepaFilterInstance = nullptr; + } + if (gHepaFilterDelegate != nullptr) + { + delete gHepaFilterDelegate; + gHepaFilterDelegate = nullptr; + } +} + void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) { - VerifyOrDie(gActivatedCarbonFilterInstance == nullptr); - gActivatedCarbonFilterInstance = new ActivatedCarbonFilterMonitoringInstance( - endpoint, static_cast(gActivatedCarbonFeatureMap.to_ulong()), DegradationDirectionEnum::kDown, true); + VerifyOrDie(gActivatedCarbonFilterInstance == nullptr && gActivatedCarbonFilterDelegate == nullptr); + gActivatedCarbonFilterDelegate = new ActivatedCarbonFilterMonitoringDelegate; + gActivatedCarbonFilterInstance = new ResourceMonitoring::Instance( + gActivatedCarbonFilterDelegate, endpoint, ActivatedCarbonFilterMonitoring::Id, + static_cast(gActivatedCarbonFeatureMap.to_ulong()), ResourceMonitoring::DegradationDirectionEnum::kDown, true); gActivatedCarbonFilterInstance->Init(); } + void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) { - VerifyOrDie(gHepaFilterInstance == nullptr); - gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast(gHepaFilterFeatureMap.to_ulong()), - DegradationDirectionEnum::kDown, true); + VerifyOrDie(gHepaFilterInstance == nullptr && gHepaFilterDelegate == nullptr); + + gHepaFilterDelegate = new HepaFilterMonitoringDelegate; + gHepaFilterInstance = new ResourceMonitoring::Instance(gHepaFilterDelegate, endpoint, HepaFilterMonitoring::Id, + static_cast(gHepaFilterFeatureMap.to_ulong()), + ResourceMonitoring::DegradationDirectionEnum::kDown, true); gHepaFilterInstance->Init(); } diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index 82423baf24f607..d635c806c42375 100755 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -156,7 +156,7 @@ list( ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp - ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp + ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn index aa67f8cd72042f..e023a48cb3643e 100755 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -74,7 +74,7 @@ asr_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", diff --git a/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn b/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn index 34ba1c1d3e72c9..5c166468dffea2 100644 --- a/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/all-clusters-app/cc13x2x7_26x2x7/BUILD.gn @@ -79,7 +79,7 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index c8d6f5a21acd5d..ff5f7815168486 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -79,7 +79,7 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index 61ce1a58961802..aa0acaf2bee415 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -110,7 +110,7 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index a3ecb76807fa3e..6321a838f2c689 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -31,7 +31,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/operational-state-delegate-impl.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", diff --git a/examples/all-clusters-app/linux/main-common.cpp b/examples/all-clusters-app/linux/main-common.cpp index b3c942dfe09da3..3315f6c84297fe 100644 --- a/examples/all-clusters-app/linux/main-common.cpp +++ b/examples/all-clusters-app/linux/main-common.cpp @@ -24,6 +24,7 @@ #include "laundry-washer-controls-delegate-impl.h" #include "laundry-washer-mode.h" #include "operational-state-delegate-impl.h" +#include "resource-monitoring-delegates.h" #include "rvc-modes.h" #include "tcc-mode.h" #include @@ -227,6 +228,8 @@ void ApplicationShutdown() Clusters::RvcCleanMode::Shutdown(); Clusters::RvcRunMode::Shutdown(); Clusters::RefrigeratorAndTemperatureControlledCabinetMode::Shutdown(); + Clusters::HepaFilterMonitoring::Shutdown(); + Clusters::ActivatedCarbonFilterMonitoring::Shutdown(); Clusters::AirQuality::Shutdown(); Clusters::OperationalState::Shutdown(); diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index 0424e3a6484e38..b784bc0c32e163 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -62,7 +62,7 @@ target_sources(${APP_TARGET} PRIVATE ${ALL_CLUSTERS_COMMON}/src/bridged-actions-stub.cpp ${ALL_CLUSTERS_COMMON}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON}/src/fan-stub.cpp - ${ALL_CLUSTERS_COMMON}/src/resource-monitoring-instances.cpp + ${ALL_CLUSTERS_COMMON}/src/resource-monitoring-delegates.cpp ${ALL_CLUSTERS_COMMON}/src/smco-stub.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-modes-manager.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-temperature-levels.cpp diff --git a/examples/all-clusters-app/nrfconnect/CMakeLists.txt b/examples/all-clusters-app/nrfconnect/CMakeLists.txt index 9593bb7232c9a2..69521548530d47 100644 --- a/examples/all-clusters-app/nrfconnect/CMakeLists.txt +++ b/examples/all-clusters-app/nrfconnect/CMakeLists.txt @@ -64,7 +64,7 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/fan-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/concentration-measurement-instances.cpp - ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-instances.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp ${NRFCONNECT_COMMON}/util/LEDWidget.cpp) chip_configure_data_model(app diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index f00d4d597c6087..2a227860192d7c 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -77,7 +77,7 @@ mw320_executable("shell_mw320") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", diff --git a/examples/all-clusters-app/openiotsdk/CMakeLists.txt b/examples/all-clusters-app/openiotsdk/CMakeLists.txt index eb9e3faa8688c3..ea02c19c076ad0 100644 --- a/examples/all-clusters-app/openiotsdk/CMakeLists.txt +++ b/examples/all-clusters-app/openiotsdk/CMakeLists.txt @@ -56,7 +56,7 @@ target_sources(${APP_TARGET} ${ALL_CLUSTERS_COMMON}/src/bridged-actions-stub.cpp ${ALL_CLUSTERS_COMMON}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON}/src/fan-stub.cpp - ${ALL_CLUSTERS_COMMON}/src/resource-monitoring-instances.cpp + ${ALL_CLUSTERS_COMMON}/src/resource-monitoring-delegates.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-modes-manager.cpp ${ALL_CLUSTERS_COMMON}/src/binding-handler.cpp ) diff --git a/examples/all-clusters-app/telink/CMakeLists.txt b/examples/all-clusters-app/telink/CMakeLists.txt index d3165fb7500d3d..25b0d1ec279e5b 100644 --- a/examples/all-clusters-app/telink/CMakeLists.txt +++ b/examples/all-clusters-app/telink/CMakeLists.txt @@ -78,7 +78,7 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/fan-stub.cpp - ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-instances.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDWidget.cpp diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index 5b4d63336949b7..e755bcaef060ea 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -27,7 +27,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp", + "${chip_root}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", diff --git a/examples/placeholder/linux/apps/app1/BUILD.gn b/examples/placeholder/linux/apps/app1/BUILD.gn index 99b3547b81e7c8..ef7c277ec7f663 100644 --- a/examples/placeholder/linux/apps/app1/BUILD.gn +++ b/examples/placeholder/linux/apps/app1/BUILD.gn @@ -30,7 +30,7 @@ source_set("app1") { ] sources = [ - "../../resource-monitoring-instances.cpp", + "../../resource-monitoring-delegates.cpp", "../../src/bridged-actions-stub.cpp", "../../static-supported-modes-manager.cpp", ] diff --git a/examples/placeholder/linux/apps/app2/BUILD.gn b/examples/placeholder/linux/apps/app2/BUILD.gn index 91777971875d15..5c18b7d2dc0914 100644 --- a/examples/placeholder/linux/apps/app2/BUILD.gn +++ b/examples/placeholder/linux/apps/app2/BUILD.gn @@ -30,7 +30,7 @@ source_set("app2") { ] sources = [ - "../../resource-monitoring-instances.cpp", + "../../resource-monitoring-delegates.cpp", "../../src/bridged-actions-stub.cpp", "../../static-supported-modes-manager.cpp", ] diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/placeholder/linux/include/resource-monitoring-delegates.h similarity index 52% rename from examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h rename to examples/placeholder/linux/include/resource-monitoring-delegates.h index 276e423626c1d7..00bdb02091cddb 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/placeholder/linux/include/resource-monitoring-delegates.h @@ -20,39 +20,39 @@ #include #include -/// This is an application level Instance to handle ActivatedCarbonfilterMonitoringInstance commands according to the specific +namespace chip { +namespace app { +namespace Clusters { + +namespace ActivatedCarbonFilterMonitoring { + +/// This is an application level Delegate to handle ActivatedCarbonFilterMonitoringDelegate commands according to the specific /// business logic. -class ActivatedCarbonFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance +class ActivatedCarbonFilterMonitoringDelegate : public ResourceMonitoring::Delegate { private: - CHIP_ERROR AppInit() override; + CHIP_ERROR Init() 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){}; + ~ActivatedCarbonFilterMonitoringDelegate() override = default; }; -/// This is an application level instance to handle HepaFilterMonitoringInstance commands according to the specific business logic. -class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance +} // namespace ActivatedCarbonFilterMonitoring + +namespace HepaFilterMonitoring { + +/// This is an application level delegate to handle HepaFilterMonitoringDelegate commands according to the specific business logic. +class HepaFilterMonitoringDelegate : public ResourceMonitoring::Delegate { private: - CHIP_ERROR AppInit() override; + CHIP_ERROR Init() 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){}; + ~HepaFilterMonitoringDelegate() override = default; }; class ImmutableReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager @@ -61,3 +61,9 @@ class ImmutableReplacementProductListManager : public chip::app::Clusters::Resou CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; }; + +} // namespace HepaFilterMonitoring + +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/placeholder/linux/include/resource-monitoring-instances.h b/examples/placeholder/linux/include/resource-monitoring-instances.h deleted file mode 100644 index 276e423626c1d7..00000000000000 --- a/examples/placeholder/linux/include/resource-monitoring-instances.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * 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 -#include -#include -#include - -/// 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; -}; diff --git a/examples/placeholder/linux/resource-monitoring-instances.cpp b/examples/placeholder/linux/resource-monitoring-delegates.cpp similarity index 60% rename from examples/placeholder/linux/resource-monitoring-instances.cpp rename to examples/placeholder/linux/resource-monitoring-delegates.cpp index a030beed78c7e6..f7a5662d6f5577 100644 --- a/examples/placeholder/linux/resource-monitoring-instances.cpp +++ b/examples/placeholder/linux/resource-monitoring-delegates.cpp @@ -19,78 +19,89 @@ #include #include #include -#include +#include using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; +using namespace chip::app::Clusters::ActivatedCarbonFilterMonitoring; +using namespace chip::app::Clusters::HepaFilterMonitoring; using chip::Protocols::InteractionModel::Status; -constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(Feature::kCondition) | - static_cast(Feature::kWarning) | - static_cast(Feature::kReplacementProductList) }; -constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Feature::kCondition) | - static_cast(Feature::kWarning) | - static_cast(Feature::kReplacementProductList) }; +constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(ResourceMonitoring::Feature::kCondition) | + static_cast(ResourceMonitoring::Feature::kWarning) | + static_cast(ResourceMonitoring::Feature::kReplacementProductList) }; +constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(ResourceMonitoring::Feature::kCondition) | + static_cast(ResourceMonitoring::Feature::kWarning) | + static_cast(ResourceMonitoring::Feature::kReplacementProductList) }; -static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; -static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; +static ActivatedCarbonFilterMonitoringDelegate * gActivatedCarbonFilterDelegate = nullptr; +static ResourceMonitoring::Instance * gActivatedCarbonFilterInstance = nullptr; + +static HepaFilterMonitoringDelegate * gHepaFilterDelegate = nullptr; +static ResourceMonitoring::Instance * gHepaFilterInstance = nullptr; static ImmutableReplacementProductListManager sReplacementProductListManager; //-- Activated Carbon Filter Monitoring Instance methods -CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() +CHIP_ERROR ActivatedCarbonFilterMonitoringDelegate::Init() { ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()"); - SetReplacementProductListManagerInstance(&sReplacementProductListManager); + GetInstance()->SetReplacementProductListManagerInstance(&sReplacementProductListManager); return CHIP_NO_ERROR; } -Status ActivatedCarbonFilterMonitoringInstance::PreResetCondition() +Status ActivatedCarbonFilterMonitoringDelegate::PreResetCondition() { - ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PreResetCondition()"); + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::PreResetCondition()"); return Status::Success; } -Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition() +Status ActivatedCarbonFilterMonitoringDelegate::PostResetCondition() { - ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PostResetCondition()"); + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::PostResetCondition()"); return Status::Success; } //-- Hepa Filter Monitoring instance methods -CHIP_ERROR HepaFilterMonitoringInstance::AppInit() +CHIP_ERROR HepaFilterMonitoringDelegate::Init() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - SetReplacementProductListManagerInstance(&sReplacementProductListManager); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::Init()"); + GetInstance()->SetReplacementProductListManagerInstance(&sReplacementProductListManager); return CHIP_NO_ERROR; } -Status HepaFilterMonitoringInstance::PreResetCondition() +Status HepaFilterMonitoringDelegate::PreResetCondition() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PreResetCondition()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::PreResetCondition()"); return Status::Success; } -Status HepaFilterMonitoringInstance::PostResetCondition() +Status HepaFilterMonitoringDelegate::PostResetCondition() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PostResetCondition()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::PostResetCondition()"); return Status::Success; } void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) { VerifyOrDie(gActivatedCarbonFilterInstance == nullptr); - gActivatedCarbonFilterInstance = new ActivatedCarbonFilterMonitoringInstance( - endpoint, static_cast(gActivatedCarbonFeatureMap.to_ulong()), DegradationDirectionEnum::kDown, true); + + gActivatedCarbonFilterDelegate = new ActivatedCarbonFilterMonitoringDelegate; + gActivatedCarbonFilterInstance = new ResourceMonitoring::Instance( + gActivatedCarbonFilterDelegate, endpoint, ActivatedCarbonFilterMonitoring::Id, + static_cast(gActivatedCarbonFeatureMap.to_ulong()), ResourceMonitoring::DegradationDirectionEnum::kDown, true); gActivatedCarbonFilterInstance->Init(); } void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) { VerifyOrDie(gHepaFilterInstance == nullptr); - gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast(gHepaFilterFeatureMap.to_ulong()), - DegradationDirectionEnum::kDown, true); + + gHepaFilterDelegate = new HepaFilterMonitoringDelegate; + gHepaFilterInstance = new ResourceMonitoring::Instance(gHepaFilterDelegate, endpoint, HepaFilterMonitoring::Id, + static_cast(gHepaFilterFeatureMap.to_ulong()), + ResourceMonitoring::DegradationDirectionEnum::kDown, true); gHepaFilterInstance->Init(); } diff --git a/examples/resource-monitoring-app/linux/BUILD.gn b/examples/resource-monitoring-app/linux/BUILD.gn index e9d5e391def96c..b9a1e41f92b053 100644 --- a/examples/resource-monitoring-app/linux/BUILD.gn +++ b/examples/resource-monitoring-app/linux/BUILD.gn @@ -31,8 +31,8 @@ config("includes") { executable("chip-resource-monitoring-app") { sources = [ "${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", + "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/delegates/ActivatedCarbonFilterMonitoring.cpp", + "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/delegates/HepaFilterMonitoring.cpp", "include/CHIPProjectAppConfig.h", "src/main.cpp", ] @@ -40,7 +40,7 @@ executable("chip-resource-monitoring-app") { deps = [ "${chip_root}/examples/platform/linux:app-main", "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common", - "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common:instances", + "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common:delegates", "${chip_root}/src/lib", ] diff --git a/examples/resource-monitoring-app/linux/src/main.cpp b/examples/resource-monitoring-app/linux/src/main.cpp index dd6e1231d6a9e2..b6059739ced19f 100644 --- a/examples/resource-monitoring-app/linux/src/main.cpp +++ b/examples/resource-monitoring-app/linux/src/main.cpp @@ -20,8 +20,8 @@ #include #include #include -#include -#include +#include +#include #include using namespace chip; @@ -36,11 +36,17 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static_cast(Feature::kWarning) | static_cast(Feature::kReplacementProductList) }; -static HepaFilterMonitoringInstance gHepaFilterInstance(0x1, static_cast(gHepaFilterFeatureMap.to_ulong()), +static HepaFilterMonitoringDelegate gHepaFilterDelegate; +static ResourceMonitoring::Instance gHepaFilterInstance(&gHepaFilterDelegate, 0x1, HepaFilterMonitoring::Id, + static_cast(gHepaFilterFeatureMap.to_ulong()), Clusters::ResourceMonitoring::DegradationDirectionEnum::kDown, true); -static ActivatedCarbonFilterMonitoringInstance - gActivatedCarbonFilterInstance(0x1, static_cast(gActivatedCarbonFeatureMap.to_ulong()), - Clusters::ResourceMonitoring::DegradationDirectionEnum::kDown, true); + +static ActivatedCarbonFilterMonitoringDelegate gActivatedCarbonFilterDelegate; +static ResourceMonitoring::Instance gActivatedCarbonFilterInstance(&gActivatedCarbonFilterDelegate, 0x1, + ActivatedCarbonFilterMonitoring::Id, + static_cast(gActivatedCarbonFeatureMap.to_ulong()), + Clusters::ResourceMonitoring::DegradationDirectionEnum::kDown, + true); void ApplicationInit() { diff --git a/examples/resource-monitoring-app/resource-monitoring-common/BUILD.gn b/examples/resource-monitoring-app/resource-monitoring-common/BUILD.gn index 9156c450353a66..0d33513378e9c7 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/BUILD.gn +++ b/examples/resource-monitoring-app/resource-monitoring-common/BUILD.gn @@ -19,7 +19,7 @@ config("config") { include_dirs = [ "include" ] } -source_set("instances") { +source_set("delegates") { public_configs = [ ":config" ] } diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/instances/ActivatedCarbonFilterMonitoring.h b/examples/resource-monitoring-app/resource-monitoring-common/include/delegates/ActivatedCarbonFilterMonitoring.h similarity index 68% rename from examples/resource-monitoring-app/resource-monitoring-common/include/instances/ActivatedCarbonFilterMonitoring.h rename to examples/resource-monitoring-app/resource-monitoring-common/include/delegates/ActivatedCarbonFilterMonitoring.h index a077a6b9a7209f..9b064f8526906e 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/instances/ActivatedCarbonFilterMonitoring.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/delegates/ActivatedCarbonFilterMonitoring.h @@ -32,22 +32,17 @@ namespace Clusters { namespace ResourceMonitoring { -/// This is an application level Instance to handle ActivatedCarbonfilterMonitoringInstance commands according to the specific +/// This is an application level delegate to handle ActivatedCarbonFilterMonitoringDelegate commands according to the specific /// business logic. -class ActivatedCarbonFilterMonitoringInstance : public ResourceMonitoring::Instance +class ActivatedCarbonFilterMonitoringDelegate : public ResourceMonitoring::Delegate { private: - CHIP_ERROR AppInit() override; + CHIP_ERROR Init() override; chip::Protocols::InteractionModel::Status PreResetCondition() override; chip::Protocols::InteractionModel::Status PostResetCondition() override; public: - ActivatedCarbonFilterMonitoringInstance( - EndpointId aEndpointId, uint32_t aFeature, - ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, - bool aResetConditionCommandSupported) : - Instance(aEndpointId, ActivatedCarbonFilterMonitoring::Id, aFeature, aDegradationDirection, - aResetConditionCommandSupported){}; + ~ActivatedCarbonFilterMonitoringDelegate() override = default; }; } // namespace ResourceMonitoring diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/instances/HepaFilterMonitoring.h b/examples/resource-monitoring-app/resource-monitoring-common/include/delegates/HepaFilterMonitoring.h similarity index 68% rename from examples/resource-monitoring-app/resource-monitoring-common/include/instances/HepaFilterMonitoring.h rename to examples/resource-monitoring-app/resource-monitoring-common/include/delegates/HepaFilterMonitoring.h index a5ef89785e0a35..ea7b4f76da973e 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/instances/HepaFilterMonitoring.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/delegates/HepaFilterMonitoring.h @@ -32,19 +32,16 @@ namespace Clusters { namespace ResourceMonitoring { -/// This is an application level instance to handle HepaFilterMonitoringInstance commands according to the specific business logic. -class HepaFilterMonitoringInstance : public ResourceMonitoring::Instance +/// This is an application level delegate to handle HepaFilterMonitoringDelegate commands according to the specific business logic. +class HepaFilterMonitoringDelegate : public ResourceMonitoring::Delegate { private: - CHIP_ERROR AppInit() override; + CHIP_ERROR Init() override; chip::Protocols::InteractionModel::Status PreResetCondition() override; chip::Protocols::InteractionModel::Status PostResetCondition() override; public: - HepaFilterMonitoringInstance(EndpointId aEndpointId, uint32_t aFeature, - ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, - bool aResetConditionCommandSupported) : - Instance(aEndpointId, HepaFilterMonitoring::Id, aFeature, aDegradationDirection, aResetConditionCommandSupported){}; + ~HepaFilterMonitoringDelegate() override = default; }; } // namespace ResourceMonitoring diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/delegates/ActivatedCarbonFilterMonitoring.cpp similarity index 82% rename from examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp rename to examples/resource-monitoring-app/resource-monitoring-common/src/delegates/ActivatedCarbonFilterMonitoring.cpp index 3ab33e675e02a9..2c00ee8b80a115 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/delegates/ActivatedCarbonFilterMonitoring.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -46,24 +46,24 @@ StaticReplacementProductListManager sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0], ArraySize(sActivatedCarbonFilterReplacementProductsList)); -//-- Activated carbon filter Monitoring Instance methods -CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() +//-- Activated carbon filter Monitoring Delegate methods +CHIP_ERROR ActivatedCarbonFilterMonitoringDelegate::Init() { ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()"); - SetReplacementProductListManagerInstance(&sActivatedCarbonFilterReplacementProductListManager); + GetInstance()->SetReplacementProductListManagerInstance(&sActivatedCarbonFilterReplacementProductListManager); return CHIP_NO_ERROR; } -Status ActivatedCarbonFilterMonitoringInstance::PreResetCondition() +Status ActivatedCarbonFilterMonitoringDelegate::PreResetCondition() { - ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PreResetCondition()"); + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::PreResetCondition()"); return Status::Success; } -Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition() +Status ActivatedCarbonFilterMonitoringDelegate::PostResetCondition() { - ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PostResetCondition()"); + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::PostResetCondition()"); return Status::Success; } diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/delegates/HepaFilterMonitoring.cpp similarity index 74% rename from examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp rename to examples/resource-monitoring-app/resource-monitoring-common/src/delegates/HepaFilterMonitoring.cpp index 6404f973a95097..31a7a478093d99 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/delegates/HepaFilterMonitoring.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -36,24 +36,24 @@ using chip::Protocols::InteractionModel::Status; static ImmutableReplacementProductListManager sHepaFilterReplacementProductListManager; -//-- Hepa filter Monitoring instance methods -CHIP_ERROR HepaFilterMonitoringInstance::AppInit() +//-- Hepa filter Monitoring Delegate methods +CHIP_ERROR HepaFilterMonitoringDelegate::Init() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::Init()"); - SetReplacementProductListManagerInstance(&sHepaFilterReplacementProductListManager); + GetInstance()->SetReplacementProductListManagerInstance(&sHepaFilterReplacementProductListManager); return CHIP_NO_ERROR; } -Status HepaFilterMonitoringInstance::PreResetCondition() +Status HepaFilterMonitoringDelegate::PreResetCondition() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PreResetCondition()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::PreResetCondition()"); return Status::Success; } -Status HepaFilterMonitoringInstance::PostResetCondition() +Status HepaFilterMonitoringDelegate::PostResetCondition() { - ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PostResetCondition()"); + ChipLogDetail(Zcl, "HepaFilterMonitoringDelegate::PostResetCondition()"); return Status::Success; } diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 970a85c957bdf3..61d90da007df0a 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -31,7 +31,6 @@ namespace ResourceMonitoring { // max of 20 characters as defined by the constraint on the ProductIdentifierValue in the specification static constexpr size_t kProductIdentifierValueMaxNameLength = 20u; -static constexpr std::array AliasedClusters = { HepaFilterMonitoring::Id, ActivatedCarbonFilterMonitoring::Id }; // Enum for ChangeIndicationEnum enum class ChangeIndicationEnum : uint8_t diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index 8b2f9ea467fc37..c8d8d44bb59d9a 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -45,11 +45,26 @@ namespace app { namespace Clusters { namespace ResourceMonitoring { +Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, uint32_t aFeatureMap, + ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, + bool aResetConditionCommandSupported) : + CommandHandlerInterface(Optional(aEndpointId), aClusterId), + AttributeAccessInterface(Optional(aEndpointId), aClusterId), mDelegate(aDelegate), mEndpointId(aEndpointId), + mClusterId(aClusterId), mDegradationDirection(aDegradationDirection), mFeatureMap(aFeatureMap), + mResetConditionCommandSupported(aResetConditionCommandSupported) +{ + mDelegate->SetInstance(this); +}; + +Instance::~Instance() +{ + InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + unregisterAttributeAccessOverride(this); +} + CHIP_ERROR Instance::Init() { ChipLogDetail(Zcl, "ResourceMonitoring: Init"); - // Check that the cluster ID given is a valid mode select alias cluster ID. - VerifyOrDie(IsValidAliasCluster()); // Check if the cluster has been selected in zap VerifyOrDie(emberAfContainsServer(mEndpointId, mClusterId)); @@ -58,8 +73,8 @@ CHIP_ERROR Instance::Init() ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); - ChipLogDetail(Zcl, "ResourceMonitoring: calling AppInit()"); - ReturnErrorOnFailure(AppInit()); + ChipLogDetail(Zcl, "ResourceMonitoring: calling mDelegate->Init()"); + ReturnErrorOnFailure(mDelegate->Init()); return CHIP_NO_ERROR; } @@ -157,63 +172,6 @@ ReplacementProductListManager * Instance::GetReplacementProductListManagerInstan return mReplacementProductListManager; } -Status Instance::OnResetCondition() -{ - ChipLogDetail(Zcl, "ResourceMonitoringServer::OnResetCondition()"); - - // call application specific pre reset logic, - // anything other than Success will cause the command to fail, and not do any of the resets - auto status = PreResetCondition(); - if (status != Status::Success) - { - return status; - } - // Handle the reset of the condition attribute, if supported - if (emberAfContainsAttribute(GetEndpointId(), mClusterId, Attributes::Condition::Id)) - { - if (GetDegradationDirection() == DegradationDirectionEnum::kDown) - { - UpdateCondition(100); - } - else if (GetDegradationDirection() == DegradationDirectionEnum::kUp) - { - UpdateCondition(0); - } - } - - // handle the reset of the ChangeIndication attribute, mandatory - UpdateChangeIndication(ChangeIndicationEnum::kOk); - - // Handle the reset of the LastChangedTime attribute, if supported - if (emberAfContainsAttribute(GetEndpointId(), mClusterId, Attributes::LastChangedTime::Id)) - { - System::Clock::Milliseconds64 currentUnixTimeMS; - System::Clock::ClockImpl clock; - CHIP_ERROR err = clock.GetClock_RealTimeMS(currentUnixTimeMS); - if (err == CHIP_NO_ERROR) - { - System::Clock::Seconds32 currentUnixTime = std::chrono::duration_cast(currentUnixTimeMS); - UpdateLastChangedTime(DataModel::MakeNullable(currentUnixTime.count())); - } - } - - // call application specific post reset logic - status = PostResetCondition(); - return status; -} - -Status Instance::PreResetCondition() -{ - ChipLogDetail(Zcl, "ResourceMonitoringServer::PreResetCondition()"); - return Status::Success; -} - -Status Instance::PostResetCondition() -{ - ChipLogDetail(Zcl, "ResourceMonitoringServer::PostResetCondition()"); - return Status::Success; -} - // This method is called by the interaction model engine when a command destined for this instance is received. void Instance::InvokeCommand(HandlerContext & handlerContext) { @@ -242,7 +200,7 @@ CHIP_ERROR Instance::EnumerateAcceptedCommands(const ConcreteClusterPath & clust return CHIP_NO_ERROR; } -CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) +CHIP_ERROR Instance::ReadReplaceableProductList(AttributeValueEncoder & aEncoder) { CHIP_ERROR err = CHIP_NO_ERROR; if (HasFeature(ResourceMonitoring::Feature::kReplacementProductList)) @@ -301,7 +259,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu break; } case Attributes::ReplacementProductList::Id: { - return ReadReplacableProductList(aEncoder); + return ReadReplaceableProductList(aEncoder); break; } } @@ -373,24 +331,69 @@ void Instance::LoadPersistentAttributes() } } -bool Instance::IsValidAliasCluster() const +void Instance::HandleResetCondition(HandlerContext & ctx, + const ResourceMonitoring::Commands::ResetCondition::DecodableType & commandData) +{ + + Status resetConditionStatus = mDelegate->OnResetCondition(); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, resetConditionStatus); +} + +Status Delegate::OnResetCondition() { - for (unsigned int AliasedCluster : AliasedClusters) + ChipLogDetail(Zcl, "ResourceMonitoringServer::OnResetCondition()"); + + // call application specific pre reset logic, + // anything other than Success will cause the command to fail, and not do any of the resets + auto status = PreResetCondition(); + if (status != Status::Success) + { + return status; + } + // Handle the reset of the condition attribute, if supported + if (emberAfContainsAttribute(mInstance->GetEndpointId(), mInstance->GetClusterId(), Attributes::Condition::Id)) + { + if (mInstance->GetDegradationDirection() == DegradationDirectionEnum::kDown) + { + mInstance->UpdateCondition(100); + } + else if (mInstance->GetDegradationDirection() == DegradationDirectionEnum::kUp) + { + mInstance->UpdateCondition(0); + } + } + + // handle the reset of the ChangeIndication attribute, mandatory + mInstance->UpdateChangeIndication(ChangeIndicationEnum::kOk); + + // Handle the reset of the LastChangedTime attribute, if supported + if (emberAfContainsAttribute(mInstance->GetEndpointId(), mInstance->GetClusterId(), Attributes::LastChangedTime::Id)) { - if (mClusterId == AliasedCluster) + System::Clock::Milliseconds64 currentUnixTimeMS; + System::Clock::ClockImpl clock; + CHIP_ERROR err = clock.GetClock_RealTimeMS(currentUnixTimeMS); + if (err == CHIP_NO_ERROR) { - return true; + System::Clock::Seconds32 currentUnixTime = std::chrono::duration_cast(currentUnixTimeMS); + mInstance->UpdateLastChangedTime(DataModel::MakeNullable(currentUnixTime.count())); } } - return false; + + // call application specific post reset logic + status = PostResetCondition(); + return status; } -void Instance::HandleResetCondition(HandlerContext & ctx, - const ResourceMonitoring::Commands::ResetCondition::DecodableType & commandData) +Status Delegate::PreResetCondition() { + ChipLogDetail(Zcl, "ResourceMonitoringServer::PreResetCondition()"); + return Status::Success; +} - Status resetConditionStatus = OnResetCondition(); - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, resetConditionStatus); +Status Delegate::PostResetCondition() +{ + ChipLogDetail(Zcl, "ResourceMonitoringServer::PostResetCondition()"); + return Status::Success; } } // namespace ResourceMonitoring diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h index f793b36c95cb32..80c6da82d37431 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h @@ -36,10 +36,37 @@ namespace app { namespace Clusters { namespace ResourceMonitoring { +// forward declarations +class Delegate; + class Instance : public CommandHandlerInterface, public AttributeAccessInterface { public: + /** + * Creates a resource monitoring cluster instance. The Init() method needs to be called for this instance to be registered and + * called by the interaction model at the appropriate times. + * + * @param aDelegate A pointer to the delegate to be used by this server. + * Note: the caller must ensure that the delegate lives throughout the instance's lifetime. + * @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. + * @param aClusterId The ID of the ResourceMonitoring aliased cluster to be instantiated. + * @param aFeatureMap The feature map of the cluster. + * @param aDegradationDirection The degradation direction of the cluster. + * @param aResetConditionCommandSupported Whether the ResetCondition command is supported by the cluster. + */ + Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, uint32_t aFeatureMap, + ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, + bool aResetConditionCommandSupported); + + ~Instance() override; + + // Not copyable or movable + Instance(const Instance &) = delete; + Instance & operator=(const Instance &) = delete; + Instance(Instance &&) = delete; + Instance & operator=(Instance &&) = delete; + /** * Initialise the Resource Monitoring cluster. * @@ -79,32 +106,69 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface DataModel::Nullable GetLastChangedTime() const; EndpointId GetEndpointId() const { return mEndpointId; } + ClusterId GetClusterId() const { return mClusterId; } + +private: + Delegate * mDelegate; + + EndpointId mEndpointId{}; + ClusterId mClusterId{}; + + // attribute Data Store + chip::Percent mCondition = 100; + DegradationDirectionEnum mDegradationDirection = DegradationDirectionEnum::kDown; + ChangeIndicationEnum mChangeIndication = ChangeIndicationEnum::kOk; + bool mInPlaceIndicator = true; + DataModel::Nullable mLastChangedTime; + ReplacementProductListManager * mReplacementProductListManager = nullptr; + + uint32_t mFeatureMap; + + bool mResetConditionCommandSupported = false; + + ReplacementProductListManager * GetReplacementProductListManagerInstance(); + + CHIP_ERROR ReadReplaceableProductList(AttributeValueEncoder & aEncoder); + + // CommandHandlerInterface + void InvokeCommand(HandlerContext & ctx) override; + CHIP_ERROR EnumerateAcceptedCommands(const ConcreteClusterPath & cluster, CommandIdCallback callback, void * context) override; + + // AttributeAccessInterface + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; + + template + void HandleCommand(HandlerContext & handlerContext, FuncT func); + + void LoadPersistentAttributes(); /** - * Creates a resource monitoring cluster instance. The Init() method needs to be called for this instance to be registered and - * called by the interaction model at the appropriate times. - * @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. - * @param aClusterId The ID of the ResourceMonitoring aliased cluster to be instantiated. - * @param aFeatureMap The feature map of the cluster. - * @param aDegradationDirection The degradation direction of the cluster. - * @param aResetConditionCommandSupported Whether the ResetCondition command is supported by the cluster. + * Internal method to handle the ResetCondition command. */ - Instance(EndpointId aEndpointId, ClusterId aClusterId, uint32_t aFeatureMap, - ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, - bool aResetConditionCommandSupported) : - CommandHandlerInterface(Optional(aEndpointId), aClusterId), - AttributeAccessInterface(Optional(aEndpointId), aClusterId), mEndpointId(aEndpointId), mClusterId(aClusterId), - mDegradationDirection(aDegradationDirection), mFeatureMap(aFeatureMap), - mResetConditionCommandSupported(aResetConditionCommandSupported) - {} + void HandleResetCondition(HandlerContext & ctx, + const ResourceMonitoring::Commands::ResetCondition::DecodableType & commandData); +}; // class Instance - ~Instance() = default; +class Delegate +{ + friend class Instance; - // Not copyable or movable - Instance(const Instance &) = delete; - Instance & operator=(const Instance &) = delete; - Instance(Instance &&) = delete; - Instance & operator=(Instance &&) = delete; +private: + Instance * mInstance = nullptr; + + /** + * This method is used by the SDK to set the instance pointer. This is done during the instantiation of an Instance object. + * @param aInstance A pointer to the Instance object related to this delegate object. + */ + void SetInstance(Instance * aInstance) { mInstance = aInstance; } + +protected: + Instance * GetInstance() { return mInstance; } + +public: + Delegate() = default; + virtual ~Delegate() = default; // The following methods should be overridden by the SDK user to implement the business logic of their application @@ -116,7 +180,7 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface * @return CHIP_NO_ERROR If the application was initialized successfully. All other values will cause the initialization to * fail. */ - virtual CHIP_ERROR AppInit() = 0; + virtual CHIP_ERROR Init() = 0; /** * This method may be overwritten by the SDK User, if the default behaviour is not desired. @@ -154,51 +218,6 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface * the failure. */ virtual chip::Protocols::InteractionModel::Status PostResetCondition(); - -private: - EndpointId mEndpointId{}; - ClusterId mClusterId{}; - - // attribute Data Store - chip::Percent mCondition = 100; - DegradationDirectionEnum mDegradationDirection = DegradationDirectionEnum::kDown; - ChangeIndicationEnum mChangeIndication = ChangeIndicationEnum::kOk; - bool mInPlaceIndicator = true; - DataModel::Nullable mLastChangedTime; - ReplacementProductListManager * mReplacementProductListManager = nullptr; - - uint32_t mFeatureMap; - - bool mResetConditionCommandSupported = false; - - ReplacementProductListManager * GetReplacementProductListManagerInstance(); - - CHIP_ERROR ReadReplacableProductList(AttributeValueEncoder & aEncoder); - - // CommandHandlerInterface - void InvokeCommand(HandlerContext & ctx) override; - CHIP_ERROR EnumerateAcceptedCommands(const ConcreteClusterPath & cluster, CommandIdCallback callback, void * context) override; - - // AttributeAccessInterface - CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; - - template - void HandleCommand(HandlerContext & handlerContext, FuncT func); - - void LoadPersistentAttributes(); - - /** - * This checks if the clusters instance is a valid ResourceMonitoring cluster based on the AliasedClusters list. - * @return true if the cluster is a valid ResourceMonitoring cluster. - */ - bool IsValidAliasCluster() const; - - /** - * Internal method to handle the ResetCondition command. - */ - void HandleResetCondition(HandlerContext & ctx, - const ResourceMonitoring::Commands::ResetCondition::DecodableType & commandData); }; } // namespace ResourceMonitoring