From 4f7ee384d8ca541f600e33b6b2d42dc470d385a7 Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Tue, 27 Jun 2023 18:57:05 +0800 Subject: [PATCH 01/29] Add laundry-washer-controls-cluster server implementation Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-delegate.h | 42 ++++ .../laundry-washer-controls-server.cpp | 201 ++++++++++++++++++ .../laundry-washer-controls-server.h | 33 +++ src/app/zap_cluster_list.json | 1 + 4 files changed, 277 insertions(+) create mode 100644 src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h create mode 100644 src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp create mode 100644 src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h new file mode 100644 index 00000000000000..e0db52b1e72daa --- /dev/null +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -0,0 +1,42 @@ +/* + * + * 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 +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace LaundryWasherControls { + +/** @brief + * Defines methods for implementing application-specific logic for the Washer Controls Cluster. + */ +class Delegate +{ +public: + virtual CHIP_ERROR HandleGetSpinSpeedsList(app::AttributeValueEncoder & aEncoder) = 0; + virtual CHIP_ERROR HandleGetSupportedRinses(app::AttributeValueEncoder & aEncoder) = 0; + virtual ~Delegate() = default; +}; + +} // namespace LaundryWasherControls +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp new file mode 100644 index 00000000000000..63b45d51da67e2 --- /dev/null +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -0,0 +1,201 @@ +/** + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::LaundryWasherControls; +using namespace chip::app::Clusters::LaundryWasherControls::Attributes; +using chip::Protocols::InteractionModel::Status; + +static constexpr size_t kLaundryWasherControlsDelegateTableSize = + EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + +// ----------------------------------------------------------------------------- +// Delegate Implementation +// +using chip::app::Clusters::LaundryWasherControls::Delegate; +namespace { +Delegate * gDelegateTable[kLaundryWasherControlsDelegateTableSize] = { nullptr }; +} + +namespace chip { +namespace app { +namespace Clusters { +namespace LaundryWasherControls { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) +{ + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + if (ep < kLaundryWasherControlsDelegateTableSize) + { + gDelegateTable[ep] = delegate; + } + else + { + } +} +} // namespace LaundryWasherControls +} // namespace Clusters +} // namespace app +} // namespace chip + +namespace { +Delegate * GetDelegate(EndpointId endpoint) +{ + uint16_t ep = + emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[ep]); +} + +bool isDelegateNull(Delegate * delegate, EndpointId endpoint) +{ + if (delegate == nullptr) + { + ChipLogProgress(Zcl, "Laundry Washer Control has no delegate set for endpoint:%u", endpoint); + return true; + } + return false; +} + +class LaundryWasherControlsAttrAccess : public AttributeAccessInterface +{ +public: + LaundryWasherControlsAttrAccess() : AttributeAccessInterface(Optional::Missing(), LaundryWasherControls::Id) {} + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + +private: + CHIP_ERROR ReadSpinSpeeds(AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadSpinSpeedCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadNumberOfRinses(EndpointId endpoint, AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadSupportedRinses(AttributeValueEncoder & aEncoder, Delegate * delegate); +}; + +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + return delegate->HandleGetSpinSpeedsList(aEncoder); +} + +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeedCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder) +{ + DataModel::Nullable speedSetting; + SpinSpeedCurrent::Get(endpoint, speedSetting); + uint8_t ret = 0; + if (!speedSetting.IsNull()) + { + ret = speedSetting.Value(); + } + + return aEncoder.Encode(ret); +} + +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadNumberOfRinses(EndpointId endpoint, AttributeValueEncoder & aEncoder) +{ + LaundryWasherControls::NumberOfRinsesEnum numOfRinses; + NumberOfRinses::Get(endpoint, &numOfRinses); + + return aEncoder.Encode(numOfRinses); +} + +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(AttributeValueEncoder & aEncoder, Delegate * delegate) +{ + return delegate->HandleGetSupportedRinses(aEncoder); +} + +CHIP_ERROR LaundryWasherControlsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + EndpointId endpoint = aPath.mEndpointId; + Delegate * delegate = GetDelegate(endpoint); + + if (aPath.mClusterId != LaundryWasherControls::Id) + { + // We shouldn't have been called at all. + return CHIP_ERROR_INVALID_ARGUMENT; + } + switch (aPath.mAttributeId) + { + case Attributes::SpinSpeeds::Id: + if (isDelegateNull(delegate, endpoint)) + { + return aEncoder.EncodeEmptyList(); + } + return ReadSpinSpeeds(aEncoder, delegate); + case Attributes::SpinSpeedCurrent::Id: + return ReadSpinSpeedCurrent(endpoint, aEncoder); + case Attributes::NumberOfRinses::Id: + return ReadNumberOfRinses(endpoint, aEncoder); + case Attributes::SupportedRinses::Id: + if (isDelegateNull(delegate, endpoint)) + { + return aEncoder.EncodeEmptyList(); + } + return ReadSupportedRinses(aEncoder, delegate); + default: + break; + } + return CHIP_NO_ERROR; +} +} // namespace + +void emberAfLaundryWasherControlsClusterInitCallback(chip::EndpointId endpoint) +{ + return; +} + +using imcode = Protocols::InteractionModel::Status; + +void MatterLaundryWasherControlsClusterServerAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath) +{ + // ToDo + return; +} + +chip::Protocols::InteractionModel::Status +MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath, + EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) +{ + // ToDo + return imcode::Success; +} + +LaundryWasherControlsAttrAccess gAttrAccess; + +void MatterLaundryWasherControlsPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gAttrAccess); +} diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h new file mode 100644 index 00000000000000..b397a64ca6f561 --- /dev/null +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -0,0 +1,33 @@ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "laundry-washer-controls-delegate.h" +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace LaundryWasherControls { + +void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + +} // namespace LaundryWasherControls +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/zap_cluster_list.json b/src/app/zap_cluster_list.json index dd6fdf70b8e1ab..7170d755d47c9f 100644 --- a/src/app/zap_cluster_list.json +++ b/src/app/zap_cluster_list.json @@ -287,6 +287,7 @@ "UNIT_TESTING_CLUSTER": ["test-cluster-server"], "USER_LABEL_CLUSTER": ["user-label-server"], "WAKE_ON_LAN_CLUSTER": ["wake-on-lan-server"], + "LAUNDRY_WASHER_CONTROLS_CLUSTER": ["laundry-washer-controls-server"], "WIFI_NETWORK_DIAGNOSTICS_CLUSTER": ["wifi-network-diagnostics-server"], "WINDOW_COVERING_CLUSTER": ["window-covering-server"], "ZLL_COMMISSIONING_CLUSTER": [] From 440f57b1636b69267005422ec9549678779e0431 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 27 Jun 2023 10:58:45 +0000 Subject: [PATCH 02/29] Restyled by clang-format --- .../laundry-washer-controls-delegate.h | 4 ++-- .../laundry-washer-controls-server.cpp | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h index e0db52b1e72daa..3c61253adb8064 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -31,9 +31,9 @@ namespace LaundryWasherControls { class Delegate { public: - virtual CHIP_ERROR HandleGetSpinSpeedsList(app::AttributeValueEncoder & aEncoder) = 0; + virtual CHIP_ERROR HandleGetSpinSpeedsList(app::AttributeValueEncoder & aEncoder) = 0; virtual CHIP_ERROR HandleGetSupportedRinses(app::AttributeValueEncoder & aEncoder) = 0; - virtual ~Delegate() = default; + virtual ~Delegate() = default; }; } // namespace LaundryWasherControls diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 63b45d51da67e2..94d4c9ae7c9255 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -59,8 +59,8 @@ namespace LaundryWasherControls { void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - uint16_t ep = - emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, + EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); // if endpoint is found if (ep < kLaundryWasherControlsDelegateTableSize) { @@ -78,8 +78,8 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) namespace { Delegate * GetDelegate(EndpointId endpoint) { - uint16_t ep = - emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, + EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); return (ep >= kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[ep]); } @@ -185,9 +185,8 @@ void MatterLaundryWasherControlsClusterServerAttributeChangedCallback(const chip return; } -chip::Protocols::InteractionModel::Status -MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath, - EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) +chip::Protocols::InteractionModel::Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback( + const chip::app::ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) { // ToDo return imcode::Success; From ef282db5d400c755dbdcb3e0f694b2d3da62652d Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Wed, 28 Jun 2023 13:43:18 +0800 Subject: [PATCH 03/29] Refine the definition Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-server.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 94d4c9ae7c9255..e59ad4899c9d14 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -47,7 +47,6 @@ static constexpr size_t kLaundryWasherControlsDelegateTableSize = // ----------------------------------------------------------------------------- // Delegate Implementation // -using chip::app::Clusters::LaundryWasherControls::Delegate; namespace { Delegate * gDelegateTable[kLaundryWasherControlsDelegateTableSize] = { nullptr }; } @@ -185,10 +184,9 @@ void MatterLaundryWasherControlsClusterServerAttributeChangedCallback(const chip return; } -chip::Protocols::InteractionModel::Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback( +Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback( const chip::app::ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) { - // ToDo return imcode::Success; } From 6ae46e2574c3173d1ac73b5c04850492ba3758e1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 28 Jun 2023 05:44:05 +0000 Subject: [PATCH 04/29] Restyled by clang-format --- .../laundry-washer-controls-server.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index e59ad4899c9d14..51524d11423a2f 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -184,8 +184,9 @@ void MatterLaundryWasherControlsClusterServerAttributeChangedCallback(const chip return; } -Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback( - const chip::app::ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) +Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath, + EmberAfAttributeType attributeType, uint16_t size, + uint8_t * value) { return imcode::Success; } From 665b2e3f5561978d3405cc9b440e2d402844fce9 Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Mon, 10 Jul 2023 19:15:06 +0800 Subject: [PATCH 05/29] * Remove unnecessary code to read the attribute * Remove the deleget * Change the implementation to accept the attribute from the example Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-delegate.h | 42 ----- .../laundry-washer-controls-server.cpp | 152 +++++------------- .../laundry-washer-controls-server.h | 28 +++- 3 files changed, 68 insertions(+), 154 deletions(-) delete mode 100644 src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h deleted file mode 100644 index 3c61253adb8064..00000000000000 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * 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 -#include - -namespace chip { -namespace app { -namespace Clusters { -namespace LaundryWasherControls { - -/** @brief - * Defines methods for implementing application-specific logic for the Washer Controls Cluster. - */ -class Delegate -{ -public: - virtual CHIP_ERROR HandleGetSpinSpeedsList(app::AttributeValueEncoder & aEncoder) = 0; - virtual CHIP_ERROR HandleGetSupportedRinses(app::AttributeValueEncoder & aEncoder) = 0; - virtual ~Delegate() = default; -}; - -} // namespace LaundryWasherControls -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 51524d11423a2f..4145b9a7ff3dac 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -41,57 +40,7 @@ using namespace chip::app::Clusters::LaundryWasherControls; using namespace chip::app::Clusters::LaundryWasherControls::Attributes; using chip::Protocols::InteractionModel::Status; -static constexpr size_t kLaundryWasherControlsDelegateTableSize = - EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; - -// ----------------------------------------------------------------------------- -// Delegate Implementation -// -namespace { -Delegate * gDelegateTable[kLaundryWasherControlsDelegateTableSize] = { nullptr }; -} - -namespace chip { -namespace app { -namespace Clusters { -namespace LaundryWasherControls { - -void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) -{ - uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, - EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); - // if endpoint is found - if (ep < kLaundryWasherControlsDelegateTableSize) - { - gDelegateTable[ep] = delegate; - } - else - { - } -} -} // namespace LaundryWasherControls -} // namespace Clusters -} // namespace app -} // namespace chip - namespace { -Delegate * GetDelegate(EndpointId endpoint) -{ - uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, - EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); - return (ep >= kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[ep]); -} - -bool isDelegateNull(Delegate * delegate, EndpointId endpoint) -{ - if (delegate == nullptr) - { - ChipLogProgress(Zcl, "Laundry Washer Control has no delegate set for endpoint:%u", endpoint); - return true; - } - return false; -} - class LaundryWasherControlsAttrAccess : public AttributeAccessInterface { public: @@ -99,48 +48,58 @@ class LaundryWasherControlsAttrAccess : public AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; private: - CHIP_ERROR ReadSpinSpeeds(AttributeValueEncoder & aEncoder, Delegate * delegate); - CHIP_ERROR ReadSpinSpeedCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder); - CHIP_ERROR ReadNumberOfRinses(EndpointId endpoint, AttributeValueEncoder & aEncoder); - CHIP_ERROR ReadSupportedRinses(AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); }; -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(AttributeValueEncoder & aEncoder, Delegate * delegate) -{ - return delegate->HandleGetSpinSpeedsList(aEncoder); -} - -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeedCurrent(EndpointId endpoint, AttributeValueEncoder & aEncoder) +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - DataModel::Nullable speedSetting; - SpinSpeedCurrent::Get(endpoint, speedSetting); - uint8_t ret = 0; - if (!speedSetting.IsNull()) + const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); + const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = + gLaundryWasherManager->getSpinSpeedProvider(aPath.mEndpointId); + if (attrProvider.begin() == nullptr) { - ret = speedSetting.Value(); + aEncoder.EncodeEmptyList(); + return CHIP_NO_ERROR; } - - return aEncoder.Encode(ret); -} - -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadNumberOfRinses(EndpointId endpoint, AttributeValueEncoder & aEncoder) -{ - LaundryWasherControls::NumberOfRinsesEnum numOfRinses; - NumberOfRinses::Get(endpoint, &numOfRinses); - - return aEncoder.Encode(numOfRinses); + CHIP_ERROR err; + err = aEncoder.EncodeList([attrProvider](const auto & encoder) -> CHIP_ERROR { + const auto * end = attrProvider.end(); + for (auto * it = attrProvider.begin(); it != end; ++it) + { + auto & spinSpeed = *it; + ReturnErrorOnFailure(encoder.Encode(spinSpeed)); + } + return CHIP_NO_ERROR; + }); + return err; } -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(AttributeValueEncoder & aEncoder, Delegate * delegate) +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - return delegate->HandleGetSupportedRinses(aEncoder); + const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); + const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = + gLaundryWasherManager->getSupportedRinseProvider(aPath.mEndpointId); + if (attrProvider.begin() == nullptr) + { + aEncoder.EncodeEmptyList(); + return CHIP_NO_ERROR; + } + CHIP_ERROR err; + err = aEncoder.EncodeList([attrProvider](const auto & encoder) -> CHIP_ERROR { + const auto * end = attrProvider.end(); + for (auto * it = attrProvider.begin(); it != end; ++it) + { + auto & rinse = *it; + ReturnErrorOnFailure(encoder.Encode(rinse)); + } + return CHIP_NO_ERROR; + }); + return err; } CHIP_ERROR LaundryWasherControlsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - EndpointId endpoint = aPath.mEndpointId; - Delegate * delegate = GetDelegate(endpoint); - if (aPath.mClusterId != LaundryWasherControls::Id) { // We shouldn't have been called at all. @@ -149,21 +108,9 @@ CHIP_ERROR LaundryWasherControlsAttrAccess::Read(const ConcreteReadAttributePath switch (aPath.mAttributeId) { case Attributes::SpinSpeeds::Id: - if (isDelegateNull(delegate, endpoint)) - { - return aEncoder.EncodeEmptyList(); - } - return ReadSpinSpeeds(aEncoder, delegate); - case Attributes::SpinSpeedCurrent::Id: - return ReadSpinSpeedCurrent(endpoint, aEncoder); - case Attributes::NumberOfRinses::Id: - return ReadNumberOfRinses(endpoint, aEncoder); + return ReadSpinSpeeds(aPath, aEncoder); case Attributes::SupportedRinses::Id: - if (isDelegateNull(delegate, endpoint)) - { - return aEncoder.EncodeEmptyList(); - } - return ReadSupportedRinses(aEncoder, delegate); + return ReadSupportedRinses(aPath, aEncoder); default: break; } @@ -176,21 +123,6 @@ void emberAfLaundryWasherControlsClusterInitCallback(chip::EndpointId endpoint) return; } -using imcode = Protocols::InteractionModel::Status; - -void MatterLaundryWasherControlsClusterServerAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath) -{ - // ToDo - return; -} - -Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath, - EmberAfAttributeType attributeType, uint16_t size, - uint8_t * value) -{ - return imcode::Success; -} - LaundryWasherControlsAttrAccess gAttrAccess; void MatterLaundryWasherControlsPluginServerInitCallback() diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index b397a64ca6f561..4897877a720cce 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -17,7 +17,6 @@ #pragma once -#include "laundry-washer-controls-delegate.h" #include namespace chip { @@ -25,7 +24,32 @@ namespace app { namespace Clusters { namespace LaundryWasherControls { -void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); +class LaundryWasherManager +{ +public: + template + struct AttributeProvider + { + using pointer = const T *; + + inline pointer begin() const { return mBegin; } + inline pointer end() const { return mEnd; } + + AttributeProvider() : mBegin(nullptr), mEnd(nullptr) {} + + AttributeProvider(const pointer aBegin, const pointer aEnd) : mBegin(aBegin), mEnd(aEnd) {} + + pointer mBegin; + pointer mEnd; + }; + + virtual AttributeProvider getSpinSpeedProvider(EndpointId endpointId) const = 0; + virtual AttributeProvider getSupportedRinseProvider(EndpointId endpointId) const = 0; + + virtual ~LaundryWasherManager() {} +}; + +const LaundryWasherManager * getLaundryWasherManager(); } // namespace LaundryWasherControls } // namespace Clusters From bb9b0b1209b6df049603d0001ae3bf46ff1d8358 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 10 Jul 2023 11:19:59 +0000 Subject: [PATCH 06/29] Restyled by clang-format --- .../laundry-washer-controls-server.cpp | 10 ++++++---- .../laundry-washer-controls-server.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 4145b9a7ff3dac..25b04343d1f082 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -52,11 +52,12 @@ class LaundryWasherControlsAttrAccess : public AttributeAccessInterface CHIP_ERROR ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); }; -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, + AttributeValueEncoder & aEncoder) { const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = - gLaundryWasherManager->getSpinSpeedProvider(aPath.mEndpointId); + gLaundryWasherManager->getSpinSpeedProvider(aPath.mEndpointId); if (attrProvider.begin() == nullptr) { aEncoder.EncodeEmptyList(); @@ -75,11 +76,12 @@ CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(const ConcreteReadAtt return err; } -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, + AttributeValueEncoder & aEncoder) { const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = - gLaundryWasherManager->getSupportedRinseProvider(aPath.mEndpointId); + gLaundryWasherManager->getSupportedRinseProvider(aPath.mEndpointId); if (attrProvider.begin() == nullptr) { aEncoder.EncodeEmptyList(); diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 4897877a720cce..ee57d0669dd78b 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -43,7 +43,7 @@ class LaundryWasherManager pointer mEnd; }; - virtual AttributeProvider getSpinSpeedProvider(EndpointId endpointId) const = 0; + virtual AttributeProvider getSpinSpeedProvider(EndpointId endpointId) const = 0; virtual AttributeProvider getSupportedRinseProvider(EndpointId endpointId) const = 0; virtual ~LaundryWasherManager() {} From 45fde9d2728bdae4fa24945f5677bc57c6807e9f Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Thu, 13 Jul 2023 14:49:02 +0800 Subject: [PATCH 07/29] * Add "const" to the read-only attribute * Remove the empty emberAfLaundryWasherControlsClusterInitCallback() that app-level can implement it Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-server.cpp | 21 ++++--------------- .../laundry-washer-controls-server.h | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 25b04343d1f082..14525fcab2d07c 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -56,13 +56,9 @@ CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(const ConcreteReadAtt AttributeValueEncoder & aEncoder) { const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); - const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = + const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = gLaundryWasherManager->getSpinSpeedProvider(aPath.mEndpointId); - if (attrProvider.begin() == nullptr) - { - aEncoder.EncodeEmptyList(); - return CHIP_NO_ERROR; - } + aEncoder.EncodeEmptyList(); CHIP_ERROR err; err = aEncoder.EncodeList([attrProvider](const auto & encoder) -> CHIP_ERROR { const auto * end = attrProvider.end(); @@ -80,13 +76,9 @@ CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(const ConcreteRe AttributeValueEncoder & aEncoder) { const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); - const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = + const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = gLaundryWasherManager->getSupportedRinseProvider(aPath.mEndpointId); - if (attrProvider.begin() == nullptr) - { - aEncoder.EncodeEmptyList(); - return CHIP_NO_ERROR; - } + aEncoder.EncodeEmptyList(); CHIP_ERROR err; err = aEncoder.EncodeList([attrProvider](const auto & encoder) -> CHIP_ERROR { const auto * end = attrProvider.end(); @@ -120,11 +112,6 @@ CHIP_ERROR LaundryWasherControlsAttrAccess::Read(const ConcreteReadAttributePath } } // namespace -void emberAfLaundryWasherControlsClusterInitCallback(chip::EndpointId endpoint) -{ - return; -} - LaundryWasherControlsAttrAccess gAttrAccess; void MatterLaundryWasherControlsPluginServerInitCallback() diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index ee57d0669dd78b..28f504bb40cf4c 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -43,8 +43,8 @@ class LaundryWasherManager pointer mEnd; }; - virtual AttributeProvider getSpinSpeedProvider(EndpointId endpointId) const = 0; - virtual AttributeProvider getSupportedRinseProvider(EndpointId endpointId) const = 0; + virtual AttributeProvider getSpinSpeedProvider(const EndpointId endpointId) const = 0; + virtual AttributeProvider getSupportedRinseProvider(const EndpointId endpointId) const = 0; virtual ~LaundryWasherManager() {} }; From 39985291f882b9986e70a37b63728a2793cb92eb Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Fri, 14 Jul 2023 17:34:59 +0800 Subject: [PATCH 08/29] * Add LaundryWasherServer get/set API to access the attributes Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-server.cpp | 47 +++++++++++++++++++ .../laundry-washer-controls-server.h | 33 +++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 14525fcab2d07c..4fa7bfb5af980c 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -118,3 +118,50 @@ void MatterLaundryWasherControlsPluginServerInitCallback() { registerAttributeAccessOverride(&gAttrAccess); } + +LaundryWasherServer LaundryWasherServer::sInstance; + +/********************************************************** + * LaundryWasherServer public methods + *********************************************************/ + +LaundryWasherServer & LaundryWasherServer::Instance() +{ + return sInstance; +} + +EmberAfStatus LaundryWasherServer::SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent) +{ + DataModel::Nullable spinSpeedCurrent; + EmberAfStatus res = SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); + + if ((res == EMBER_ZCL_STATUS_SUCCESS) && (spinSpeedCurrent != newSpinSpeedCurrent)) + { + res = SpinSpeedCurrent::Set(endpointId, newSpinSpeedCurrent); + } + + return res; +} + +EmberAfStatus LaundryWasherServer::GetSpinSpeedCurrent(chip ::EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent) +{ + return SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); +} + +EmberAfStatus LaundryWasherServer::SetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses) +{ + NumberOfRinsesEnum numberOfRinses; + EmberAfStatus res = NumberOfRinses::Get(endpointId, &numberOfRinses); + + if ((res == EMBER_ZCL_STATUS_SUCCESS) && (numberOfRinses != newNumberOfRinses)) + { + res = NumberOfRinses::Set(endpointId, newNumberOfRinses); + } + + return res; +} + +EmberAfStatus LaundryWasherServer::GetNumberOfRinses(chip ::EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses) +{ + return NumberOfRinses::Get(endpointId, &numberOfRinses); +} diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 28f504bb40cf4c..644f8e2914692b 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -18,6 +18,7 @@ #pragma once #include +#include namespace chip { namespace app { @@ -51,6 +52,38 @@ class LaundryWasherManager const LaundryWasherManager * getLaundryWasherManager(); +/** + * @brief LaundryWasher Server Plugin class + */ +class LaundryWasherServer +{ +public: + static LaundryWasherServer & Instance(); + + /** + * @brief Set/Get the attribute newSpinSpeedCurrent + * + * @param endpointId ID of the endpoint + * @param newSpinSpeedCurrent attribute SpinSpeedCurrent + * @return true on success, false on failure + */ + EmberAfStatus SetSpinSpeedCurrent(chip::EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent); + EmberAfStatus GetSpinSpeedCurrent(chip::EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent); + + /** + * @brief Set/Get the attribute NumberOfRinses + * + * @param endpointId ID of the endpoint + * @param newNumberOfRinses attribute NumberOfRinses + * @return true on success, false on failure + */ + EmberAfStatus SetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses); + EmberAfStatus GetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses); + +private: + static LaundryWasherServer sInstance; +}; + } // namespace LaundryWasherControls } // namespace Clusters } // namespace app From b92715fdf73b74803e3d79b05d1f13a2f5938f3a Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Wed, 19 Jul 2023 11:30:11 +0800 Subject: [PATCH 09/29] * Add the API to get/set the SpinSpeeds and SupportedRinses attribute of LaundryWasherControl cluster * Save/Load the SpinSpeeds and SupportedRinses attribute to/from the flash Signed-off-by: Chin-Ran Lo --- src/app/chip_data_model.gni | 5 + .../LaundryWasherDataProvider.cpp | 210 ++++++++++++++++++ .../LaundryWasherDataProvider.h | 156 +++++++++++++ .../laundry-washer-controls-server.cpp | 192 ++++++++++------ .../laundry-washer-controls-server.h | 135 ++++++++--- src/lib/support/DefaultStorageKeyAllocator.h | 11 + 6 files changed, 609 insertions(+), 100 deletions(-) create mode 100644 src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp create mode 100644 src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 0f4dd4fe183d91..8fcaf477d884fc 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -274,6 +274,11 @@ template("chip_data_model") { "${_app_root}/clusters/${cluster}/resource-monitoring-cluster-objects.cpp", "${_app_root}/clusters/${cluster}/resource-monitoring-cluster-objects.h", ] + } else if (cluster == "laundry-washer-controls-server") { + sources += [ + "${_app_root}/clusters/${cluster}/${cluster}.cpp", + "${_app_root}/clusters/${cluster}/LaundryWasherDataProvider.cpp", + ] } else { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ] } diff --git a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp new file mode 100644 index 00000000000000..54bb8edbb4202d --- /dev/null +++ b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp @@ -0,0 +1,210 @@ +/* + * + * 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. + */ + +#include "LaundryWasherDataProvider.h" +#include +namespace chip { + +CHIP_ERROR LaundryWasherDataProvider::StoreSpinSpeedList(EndpointId endpoint, ClusterId clusterId, const SpinSpeedList & spinSpeedList) +{ + uint8_t buffer[kLaundryWasherMaxSerializedSize]; + TLV::TLVWriter writer; + TLV::TLVType outerType; + writer.Init(buffer); + ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, outerType)); + for (auto const & spinSpeed : spinSpeedList) + { + ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), spinSpeed.data())); + } + ReturnErrorOnFailure(writer.EndContainer(outerType)); + return mPersistentStorage->SyncSetKeyValue(DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), + buffer, static_cast(writer.GetLengthWritten())); +} + +CHIP_ERROR LaundryWasherDataProvider::LoadSpinSpeedList(EndpointId endpoint, ClusterId clusterId, SpinSpeedListCharSpan ** pSpinSpeedList, size_t & size) +{ + uint8_t buffer[kLaundryWasherMaxSerializedSize]; + MutableByteSpan bufferSpan(buffer); + size = 0; + CHIP_ERROR err = CHIP_NO_ERROR; + ReturnErrorOnFailure(Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), bufferSpan)); + TLV::TLVReader reader; + TLV::TLVType outerType; + reader.Init(bufferSpan.data(), bufferSpan.size()); + ReturnErrorOnFailure(reader.Next(TLV::TLVType::kTLVType_Array, TLV::AnonymousTag())); + ReturnErrorOnFailure(reader.EnterContainer(outerType)); + size_t i = 0; + SpinSpeedListCharSpan * head = nullptr; + while (reader.Next() != CHIP_ERROR_END_OF_TLV) + { + SpinSpeedListCharSpan * newSpinSpeed = chip::Platform::New(); + if (newSpinSpeed == nullptr) + { + ChipLogProgress(Zcl, "Malloc error"); + break; + } + newSpinSpeed->Next = nullptr; + CharSpan readSpinSpeed; + ReturnErrorOnFailure(reader.Get(readSpinSpeed)); + + if (readSpinSpeed.size()) + { + if (readSpinSpeed.size() <= kSpinSpeedMaxSize) + { + char * dest = const_cast(newSpinSpeed->SpinSpeed_c); + size_t len = readSpinSpeed.size(); + memcpy(dest, readSpinSpeed.data(), len); + newSpinSpeed->spinSpeed = CharSpan::fromCharString(newSpinSpeed->SpinSpeed_c); + } + else + { + err = CHIP_ERROR_BUFFER_TOO_SMALL; + } + } + else + { + chip::Platform::Delete(newSpinSpeed); + continue; + } + i++; + if (head == nullptr) + { + head = newSpinSpeed; + } + else + { + SpinSpeedListCharSpan * pList = head; + while (pList->Next != nullptr) + { + pList = pList->Next; + } + pList->Next = newSpinSpeed; + } + } + ReturnErrorOnFailure(reader.ExitContainer(outerType)); + size = i; + *pSpinSpeedList = head; + return err; +} + +void LaundryWasherDataProvider::ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList) +{ + while (spinSpeedList) + { + SpinSpeedListCharSpan * del = spinSpeedList; + spinSpeedList = spinSpeedList->Next; + chip::Platform::Delete(del); + } +} + +CHIP_ERROR LaundryWasherDataProvider::ClearSpinSpeedList(EndpointId endpoint, ClusterId clusterId) +{ + return mPersistentStorage->SyncDeleteKeyValue( + DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName()); +} + +CHIP_ERROR LaundryWasherDataProvider::StoreSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, const SupportedRinsesList & supportedRinsesList) +{ + uint8_t buffer[kLaundryWasherMaxSerializedSize]; + TLV::TLVWriter writer; + TLV::TLVType outerType; + writer.Init(buffer); + ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, outerType)); + for (auto const & supportedRinse : supportedRinsesList) + { + //ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), supportedRinse.data())); + //ReturnErrorOnFailure(supportedRinse.Encode(writer, TLV::AnonymousTag())); + ReturnErrorOnFailure(writer.Put(TLV::AnonymousTag(), supportedRinse)); + } + ReturnErrorOnFailure(writer.EndContainer(outerType)); + return mPersistentStorage->SyncSetKeyValue(DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), + buffer, static_cast(writer.GetLengthWritten())); +} + +CHIP_ERROR LaundryWasherDataProvider::LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, SupportedRinsesListSpan ** pSupportedRinsesList, size_t & size) +{ + uint8_t buffer[kLaundryWasherMaxSerializedSize]; + MutableByteSpan bufferSpan(buffer); + size = 0; + CHIP_ERROR err = CHIP_NO_ERROR; + ReturnErrorOnFailure(Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), bufferSpan)); + TLV::TLVReader reader; + TLV::TLVType outerType; + reader.Init(bufferSpan.data(), bufferSpan.size()); + ReturnErrorOnFailure(reader.Next(TLV::TLVType::kTLVType_Array, TLV::AnonymousTag())); + ReturnErrorOnFailure(reader.EnterContainer(outerType)); + size_t i = 0; + SupportedRinsesListSpan * head = nullptr; + while (reader.Next() != CHIP_ERROR_END_OF_TLV) + { + SupportedRinsesListSpan* newSupportedRinse = chip::Platform::New(); + if (newSupportedRinse== nullptr) + { + ChipLogProgress(Zcl, "Malloc error"); + break; + } + newSupportedRinse->Next = nullptr; + NumberOfRinsesEnum numberOfRinses; + ReturnErrorOnFailure(reader.Get(numberOfRinses)); + newSupportedRinse->numberOfRinses = numberOfRinses; + i++; + if (head == nullptr) + { + head = newSupportedRinse; + } + else + { + SupportedRinsesListSpan* pList = head; + while (pList->Next != nullptr) + { + pList = pList->Next; + } + pList->Next = newSupportedRinse; + } + } + ReturnErrorOnFailure(reader.ExitContainer(outerType)); + size = i; + *pSupportedRinsesList = head; + return err; +} + +void LaundryWasherDataProvider::ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList) +{ + while (supportedRinsesList) + { + SupportedRinsesListSpan* del = supportedRinsesList; + supportedRinsesList = supportedRinsesList->Next; + chip::Platform::Delete(del); + } +} + +CHIP_ERROR LaundryWasherDataProvider::ClearSupportedRinsesList(EndpointId endpoint, ClusterId clusterId) +{ + return mPersistentStorage->SyncDeleteKeyValue( + DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName()); +} + +CHIP_ERROR LaundryWasherDataProvider::Load(const char * key, MutableByteSpan & buffer) +{ + uint16_t size = static_cast(buffer.size()); + ReturnErrorOnFailure(mPersistentStorage->SyncGetKeyValue(key, buffer.data(), size)); + buffer = MutableByteSpan(buffer.data(), size); + return CHIP_NO_ERROR; +} + +} diff --git a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h new file mode 100644 index 00000000000000..3458c84cc53c0c --- /dev/null +++ b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h @@ -0,0 +1,156 @@ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include +#include + +#include + +using namespace chip; +using namespace chip::app::Clusters::LaundryWasherControls; + + +namespace chip { + + +constexpr size_t kSpinSpeedMaxSize = 32u; +constexpr size_t kLaundryWasherMaxSerializedSize = 512u; + +/** + * A class that can create a link list for spin speed list of laundry washer controls cluster + */ +struct SpinSpeedListCharSpan +{ + char SpinSpeed_c[kSpinSpeedMaxSize]; + CharSpan spinSpeed; + SpinSpeedListCharSpan * Next; +}; + +/** + * A class that can create a link list for supported rinses list of laundry washer controls cluster + */ +struct SupportedRinsesListSpan +{ + NumberOfRinsesEnum numberOfRinses; + SupportedRinsesListSpan * Next; +}; + +/** + * Interface to help manage the phase list and operation state list of the Operational State Cluster. + */ +class LaundryWasherDataProvider +{ +public: + using SpinSpeedList = chip::app::DataModel::List; + using SupportedRinsesList = chip::app::DataModel::List; + + ~LaundryWasherDataProvider() {} + + /** + * Init the operational state data provider. + * @param persistentStorage The refence of pesistent storage object. + * @return void + */ + void Init(PersistentStorageDelegate & persistentStorage) { mPersistentStorage = &persistentStorage; } + + /** + * Store spin speed list to storage. + * @param endpointId The endpoint for which to save the list[string]. + * @param clusterId The cluster for which to save the list[string]. + * @param spinSpeedList The spin speed list for which to save. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR StoreSpinSpeedList(EndpointId endpoint, ClusterId clusterId, const SpinSpeedList & spinSpeedList); + + /** + * Load spin speed list from storage. + * @param endpointId The endpoint for which to load the list[string]. + * @param clusterId The cluster for which to load the list[string]. + * @param pSpinSpeedList The pointer to load phase list. + * @param size The number of phase list's item. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR LoadSpinSpeedList(EndpointId endpoint, ClusterId clusterId, SpinSpeedListCharSpan ** pSpinSpeedList, size_t & size); + + /** + * Rlease spinSpeedListCharSpan + * @param spinSpeedList The pointer for which to clear the SpinSpeedListCharSpan. + * @return void + */ + void ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList); + + /** + * Clear spin speed list from storage. + * @param endpointId The endpoint for which to clear the list[string]. + * @param clusterId The cluster for which to clear the list[string]. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR ClearSpinSpeedList(EndpointId endpoint, ClusterId clusterId); + + /** + * Store supported rinses list to storage. + * @param endpointId The endpoint for which to save the list[string]. + * @param clusterId The cluster for which to save the list[string]. + * @param supportedRinsesList The supported rinses list for which to save. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR StoreSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, const SupportedRinsesList & supportedRinsesList); + + /** + * Load supported rinses list from storage. + * @param endpointId The endpoint for which to load the list[string]. + * @param clusterId The cluster for which to load the list[string]. + * @param pSupportedRinsesList The pointer to load phase list. + * @param size The number of phase list's item. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, SupportedRinsesListSpan ** pSupportedRinsesList, size_t & size); + + /** + * Rlease SupportedRinsesListSpan + * @param supportedRinsesList The pointer for which to clear the SupportedRinsesListSpan. + * @return void + */ + void ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList); + + /** + * Clear supported rinses list from storage. + * @param endpointId The endpoint for which to clear the list[string]. + * @param clusterId The cluster for which to clear the list[string]. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR ClearSupportedRinsesList(EndpointId endpoint, ClusterId clusterId); + +private: + /** + * Load content by key from storage. + * @param key key to save the content. + * @param buffer buffer to save the content. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR Load(const char * key, MutableByteSpan & buffer); + PersistentStorageDelegate * mPersistentStorage = nullptr; +}; + + + +} // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 4fa7bfb5af980c..a3d93a8af3b532 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -40,59 +41,13 @@ using namespace chip::app::Clusters::LaundryWasherControls; using namespace chip::app::Clusters::LaundryWasherControls::Attributes; using chip::Protocols::InteractionModel::Status; -namespace { -class LaundryWasherControlsAttrAccess : public AttributeAccessInterface -{ -public: - LaundryWasherControlsAttrAccess() : AttributeAccessInterface(Optional::Missing(), LaundryWasherControls::Id) {} - CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - -private: - CHIP_ERROR ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); - CHIP_ERROR ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); -}; - -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, - AttributeValueEncoder & aEncoder) -{ - const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); - const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = - gLaundryWasherManager->getSpinSpeedProvider(aPath.mEndpointId); - aEncoder.EncodeEmptyList(); - CHIP_ERROR err; - err = aEncoder.EncodeList([attrProvider](const auto & encoder) -> CHIP_ERROR { - const auto * end = attrProvider.end(); - for (auto * it = attrProvider.begin(); it != end; ++it) - { - auto & spinSpeed = *it; - ReturnErrorOnFailure(encoder.Encode(spinSpeed)); - } - return CHIP_NO_ERROR; - }); - return err; -} +LaundryWasherControlsServer LaundryWasherControlsServer::sInstance; -CHIP_ERROR LaundryWasherControlsAttrAccess::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, - AttributeValueEncoder & aEncoder) -{ - const LaundryWasherControls::LaundryWasherManager * gLaundryWasherManager = LaundryWasherControls::getLaundryWasherManager(); - const LaundryWasherControls::LaundryWasherManager::AttributeProvider attrProvider = - gLaundryWasherManager->getSupportedRinseProvider(aPath.mEndpointId); - aEncoder.EncodeEmptyList(); - CHIP_ERROR err; - err = aEncoder.EncodeList([attrProvider](const auto & encoder) -> CHIP_ERROR { - const auto * end = attrProvider.end(); - for (auto * it = attrProvider.begin(); it != end; ++it) - { - auto & rinse = *it; - ReturnErrorOnFailure(encoder.Encode(rinse)); - } - return CHIP_NO_ERROR; - }); - return err; -} +/********************************************************** + * LaundryWasherControlsServer public methods + *********************************************************/ -CHIP_ERROR LaundryWasherControlsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +CHIP_ERROR LaundryWasherControlsServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { if (aPath.mClusterId != LaundryWasherControls::Id) { @@ -110,27 +65,20 @@ CHIP_ERROR LaundryWasherControlsAttrAccess::Read(const ConcreteReadAttributePath } return CHIP_NO_ERROR; } -} // namespace -LaundryWasherControlsAttrAccess gAttrAccess; - -void MatterLaundryWasherControlsPluginServerInitCallback() +CHIP_ERROR LaundryWasherControlsServer::Init() { - registerAttributeAccessOverride(&gAttrAccess); -} - -LaundryWasherServer LaundryWasherServer::sInstance; + mLaundryWasherDataProvider.Init(Server::GetInstance().GetPersistentStorage()); -/********************************************************** - * LaundryWasherServer public methods - *********************************************************/ + return CHIP_NO_ERROR; +} -LaundryWasherServer & LaundryWasherServer::Instance() +LaundryWasherControlsServer & LaundryWasherControlsServer::Instance() { return sInstance; } -EmberAfStatus LaundryWasherServer::SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent) +EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent) { DataModel::Nullable spinSpeedCurrent; EmberAfStatus res = SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); @@ -143,12 +91,12 @@ EmberAfStatus LaundryWasherServer::SetSpinSpeedCurrent(EndpointId endpointId, Da return res; } -EmberAfStatus LaundryWasherServer::GetSpinSpeedCurrent(chip ::EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent) +EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent) { return SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); } -EmberAfStatus LaundryWasherServer::SetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses) +EmberAfStatus LaundryWasherControlsServer::SetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses) { NumberOfRinsesEnum numberOfRinses; EmberAfStatus res = NumberOfRinses::Get(endpointId, &numberOfRinses); @@ -161,7 +109,117 @@ EmberAfStatus LaundryWasherServer::SetNumberOfRinses(EndpointId endpointId, Numb return res; } -EmberAfStatus LaundryWasherServer::GetNumberOfRinses(chip ::EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses) +EmberAfStatus LaundryWasherControlsServer::GetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses) { return NumberOfRinses::Get(endpointId, &numberOfRinses); } + +EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedList(EndpointId endpointId, const SpinSpeedList & spinSpeedList) +{ + CHIP_ERROR err = mLaundryWasherDataProvider.StoreSpinSpeedList(endpointId, LaundryWasherControls::Id, spinSpeedList); + return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); +} + +EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedList(EndpointId endpointId, SpinSpeedListCharSpan ** spinSpeedList, size_t & size) +{ + CHIP_ERROR err = mLaundryWasherDataProvider.LoadSpinSpeedList(endpointId, LaundryWasherControls::Id, spinSpeedList, size); + return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); +} + +EmberAfStatus LaundryWasherControlsServer::SetSupportedRinsesList(EndpointId endpointId, const SupportedRinsesList & supportedRinsesList) +{ + CHIP_ERROR err = mLaundryWasherDataProvider.StoreSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList); + return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); +} + +EmberAfStatus LaundryWasherControlsServer::GetSupportedRinsesList(EndpointId endpointId, SupportedRinsesListSpan ** supportedRinsesList, size_t & size) +{ + CHIP_ERROR err = mLaundryWasherDataProvider.LoadSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList, size); + return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); +} + +/********************************************************** + * LaundryWasherControlsServer private methods + *********************************************************/ +void LaundryWasherControlsServer::ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList) +{ + mLaundryWasherDataProvider.ReleaseSpinSpeedList(spinSpeedList); +} + +CHIP_ERROR LaundryWasherControlsServer::ClearSpinSpeedList(EndpointId endpointId) +{ + return mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); +} + +void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesListSpan* supportedRinsesList) +{ + mLaundryWasherDataProvider.ReleaseSupportedRinsesList(supportedRinsesList); +} + +CHIP_ERROR LaundryWasherControlsServer::ClearSupportedRinsesList(EndpointId endpointId) +{ + return mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); +} + +CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, + AttributeValueEncoder & aEncoder) +{ + SpinSpeedListCharSpan * spinSpeedList = nullptr; + size_t size = 0; + EndpointId endpointId = aPath.mEndpointId; + GetSpinSpeedList(endpointId, &spinSpeedList, size); + CHIP_ERROR err = CHIP_NO_ERROR; + + aEncoder.EncodeEmptyList(); + if (size > 0) + { + return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + for (SpinSpeedListCharSpan * pHead = spinSpeedList; pHead != nullptr; pHead = pHead->Next) + { + ReturnErrorOnFailure(encoder.Encode(pHead->spinSpeed)); + } + ReleaseSpinSpeedList(spinSpeedList); + spinSpeedList = nullptr; + return CHIP_NO_ERROR; + }); + } + return err; +} + +CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, + AttributeValueEncoder & aEncoder) +{ + SupportedRinsesListSpan * supportedRinsesList = nullptr; + size_t size = 0; + EndpointId endpointId = aPath.mEndpointId; + GetSupportedRinsesList(endpointId, &supportedRinsesList, size); + CHIP_ERROR err = CHIP_NO_ERROR; + + aEncoder.EncodeEmptyList(); + if (size > 0) + { + return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + + for (SupportedRinsesListSpan* pHead = supportedRinsesList; pHead != nullptr; pHead = pHead->Next) + { + ReturnErrorOnFailure(encoder.Encode(pHead->numberOfRinses)); + } + ReleaseSupportedRinsesList(supportedRinsesList); + supportedRinsesList = nullptr; + return CHIP_NO_ERROR; + }); + } + return err; +} + +/********************************************************** + * Register LaundryWasherControlsServer + *********************************************************/ + +void MatterLaundryWasherControlsPluginServerInitCallback() +{ + LaundryWasherControlsServer & laundryWasherControlsServer = LaundryWasherControlsServer::Instance(); + registerAttributeAccessOverride(&laundryWasherControlsServer); + laundryWasherControlsServer.Init(); +} + diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 644f8e2914692b..dd7bd89d12ef1f 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -19,69 +19,138 @@ #include #include +#include +#include "LaundryWasherDataProvider.h" namespace chip { namespace app { namespace Clusters { namespace LaundryWasherControls { -class LaundryWasherManager -{ -public: - template - struct AttributeProvider - { - using pointer = const T *; - - inline pointer begin() const { return mBegin; } - inline pointer end() const { return mEnd; } - - AttributeProvider() : mBegin(nullptr), mEnd(nullptr) {} - - AttributeProvider(const pointer aBegin, const pointer aEnd) : mBegin(aBegin), mEnd(aEnd) {} - - pointer mBegin; - pointer mEnd; - }; - - virtual AttributeProvider getSpinSpeedProvider(const EndpointId endpointId) const = 0; - virtual AttributeProvider getSupportedRinseProvider(const EndpointId endpointId) const = 0; - - virtual ~LaundryWasherManager() {} -}; - -const LaundryWasherManager * getLaundryWasherManager(); - /** - * @brief LaundryWasher Server Plugin class + * @brief LaundryWasherControls Server Plugin class */ -class LaundryWasherServer +class LaundryWasherControlsServer : public AttributeAccessInterface { public: - static LaundryWasherServer & Instance(); + LaundryWasherControlsServer() : AttributeAccessInterface(Optional::Missing(), LaundryWasherControls::Id) {} + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + static LaundryWasherControlsServer & Instance(); + + using SpinSpeedList = DataModel::List; + using SupportedRinsesList = DataModel::List; + + /** + * Init the laundry washer server. + * @param void + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR Init(); /** - * @brief Set/Get the attribute newSpinSpeedCurrent + * @brief Set the attribute newSpinSpeedCurrent * * @param endpointId ID of the endpoint * @param newSpinSpeedCurrent attribute SpinSpeedCurrent * @return true on success, false on failure */ EmberAfStatus SetSpinSpeedCurrent(chip::EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent); + + /** + * @brief Get the attribute newSpinSpeedCurrent + * + * @param endpointId ID of the endpoint + * @param SpinSpeedCurrent attribute SpinSpeedCurrent + * @return true on success, false on failure + */ EmberAfStatus GetSpinSpeedCurrent(chip::EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent); /** - * @brief Set/Get the attribute NumberOfRinses + * @brief Set the attribute NumberOfRinses * * @param endpointId ID of the endpoint * @param newNumberOfRinses attribute NumberOfRinses * @return true on success, false on failure */ EmberAfStatus SetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses); + + /** + * @brief Get the attribute NumberOfRinses + * + * @param endpointId ID of the endpoint + * @param NumberOfRinses attribute NumberOfRinses + * @return true on success, false on failure + */ EmberAfStatus GetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses); + /** + * Set spin speed list. + * @param endpointId ID of the endpoint + * @param spinSpeedList The spin speed list for which to save. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + EmberAfStatus SetSpinSpeedList(EndpointId endpointId, const SpinSpeedList & spinSpeedList); + + /** + * Get spin speed list. + * @param endpointId ID of the endpoint + * @param spinSpeedList The pointer to load spin speed list. + * @param size The number of phase list's item. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + EmberAfStatus GetSpinSpeedList(EndpointId endpointId, SpinSpeedListCharSpan ** spinSpeedList, size_t & size); + + /** + * Set supportd rinses list. + * @param endpointId ID of the endpoint + * @param SupportedRinsesList The supported rinses list for which to save. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + EmberAfStatus SetSupportedRinsesList(EndpointId endpointId, const SupportedRinsesList & supportedRinsesList); + + /** + * Get supported rinses list. + * @param endpointId ID of the endpoint + * @param supportedRinsesList The pointer to load supported rinses list. + * @param size The number of phase list's item. + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + EmberAfStatus GetSupportedRinsesList(EndpointId endpointId, SupportedRinsesListSpan ** supportedRinsesList, size_t & size); private: - static LaundryWasherServer sInstance; + /** + * Rlease SpinSpeedListCharSpan + * @param spinSpeedList The pointer for which to clear the SpinSpeedListCharSpan. + * @return void + */ + void ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList); + + /** + * Clear spin speed list. + * @param endpointId ID of the endpoint + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR ClearSpinSpeedList(EndpointId endpointId); + + /** + * Rlease SupportedRinsesListSpan + * @param supportedRinsesList The pointer for which to clear the SupportedRinsesListSpan. + * @return void + */ + void ReleaseSupportedRinsesList(SupportedRinsesListSpan* supportedRinsesList); + + /** + * Clear supported rinses list. + * @param endpointId ID of the endpoint + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + CHIP_ERROR ClearSupportedRinsesList(EndpointId endpointId); + + CHIP_ERROR ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); + + LaundryWasherDataProvider mLaundryWasherDataProvider; + + static LaundryWasherControlsServer sInstance; }; } // namespace LaundryWasherControls diff --git a/src/lib/support/DefaultStorageKeyAllocator.h b/src/lib/support/DefaultStorageKeyAllocator.h index 9adc8fdf287353..40826d4cd7a2a1 100644 --- a/src/lib/support/DefaultStorageKeyAllocator.h +++ b/src/lib/support/DefaultStorageKeyAllocator.h @@ -182,6 +182,17 @@ class DefaultStorageKeyAllocator return StorageKeyName::Formatted("f/%x/icd/%x", fabric, index); } + // Laundry Washer Control cluster + static StorageKeyName LaundryWasherCtrlSpinSpeedsList(EndpointId endpoint, ClusterId clusterId) + { + return StorageKeyName::Formatted("g/lwc/ssl/%x/%" PRIx32, endpoint, clusterId); + } + + static StorageKeyName LaundryWasherCtrlSupportedRinsesList(EndpointId endpoint, ClusterId clusterId) + { + return StorageKeyName::Formatted("g/lwc/srl/%x/%" PRIx32, endpoint, clusterId); + } + static StorageKeyName OTADefaultProviders() { return StorageKeyName::FromConst("g/o/dp"); } static StorageKeyName OTACurrentProvider() { return StorageKeyName::FromConst("g/o/cp"); } static StorageKeyName OTAUpdateToken() { return StorageKeyName::FromConst("g/o/ut"); } From 9e98b9603f4e7820fbda76709983942368d5b147 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 19 Jul 2023 03:33:00 +0000 Subject: [PATCH 10/29] Restyled by whitespace --- .../laundry-washer-controls-server.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index a3d93a8af3b532..566b654b7fd2f7 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -222,4 +222,3 @@ void MatterLaundryWasherControlsPluginServerInitCallback() registerAttributeAccessOverride(&laundryWasherControlsServer); laundryWasherControlsServer.Init(); } - From 59934be5e1ee75b4e0650ddf71410a3e1e161c88 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 19 Jul 2023 03:33:11 +0000 Subject: [PATCH 11/29] Restyled by clang-format --- .../LaundryWasherDataProvider.cpp | 54 +++++++++++-------- .../LaundryWasherDataProvider.h | 11 ++-- .../laundry-washer-controls-server.cpp | 47 ++++++++-------- .../laundry-washer-controls-server.h | 9 ++-- 4 files changed, 66 insertions(+), 55 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp index 54bb8edbb4202d..780882b5b1183d 100644 --- a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp +++ b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp @@ -20,7 +20,8 @@ #include namespace chip { -CHIP_ERROR LaundryWasherDataProvider::StoreSpinSpeedList(EndpointId endpoint, ClusterId clusterId, const SpinSpeedList & spinSpeedList) +CHIP_ERROR LaundryWasherDataProvider::StoreSpinSpeedList(EndpointId endpoint, ClusterId clusterId, + const SpinSpeedList & spinSpeedList) { uint8_t buffer[kLaundryWasherMaxSerializedSize]; TLV::TLVWriter writer; @@ -32,23 +33,26 @@ CHIP_ERROR LaundryWasherDataProvider::StoreSpinSpeedList(EndpointId endpoint, Cl ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), spinSpeed.data())); } ReturnErrorOnFailure(writer.EndContainer(outerType)); - return mPersistentStorage->SyncSetKeyValue(DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), - buffer, static_cast(writer.GetLengthWritten())); + return mPersistentStorage->SyncSetKeyValue( + DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), buffer, + static_cast(writer.GetLengthWritten())); } -CHIP_ERROR LaundryWasherDataProvider::LoadSpinSpeedList(EndpointId endpoint, ClusterId clusterId, SpinSpeedListCharSpan ** pSpinSpeedList, size_t & size) +CHIP_ERROR LaundryWasherDataProvider::LoadSpinSpeedList(EndpointId endpoint, ClusterId clusterId, + SpinSpeedListCharSpan ** pSpinSpeedList, size_t & size) { uint8_t buffer[kLaundryWasherMaxSerializedSize]; MutableByteSpan bufferSpan(buffer); size = 0; CHIP_ERROR err = CHIP_NO_ERROR; - ReturnErrorOnFailure(Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), bufferSpan)); + ReturnErrorOnFailure( + Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), bufferSpan)); TLV::TLVReader reader; TLV::TLVType outerType; reader.Init(bufferSpan.data(), bufferSpan.size()); ReturnErrorOnFailure(reader.Next(TLV::TLVType::kTLVType_Array, TLV::AnonymousTag())); ReturnErrorOnFailure(reader.EnterContainer(outerType)); - size_t i = 0; + size_t i = 0; SpinSpeedListCharSpan * head = nullptr; while (reader.Next() != CHIP_ERROR_END_OF_TLV) { @@ -97,7 +101,7 @@ CHIP_ERROR LaundryWasherDataProvider::LoadSpinSpeedList(EndpointId endpoint, Clu } } ReturnErrorOnFailure(reader.ExitContainer(outerType)); - size = i; + size = i; *pSpinSpeedList = head; return err; } @@ -107,7 +111,7 @@ void LaundryWasherDataProvider::ReleaseSpinSpeedList(SpinSpeedListCharSpan * spi while (spinSpeedList) { SpinSpeedListCharSpan * del = spinSpeedList; - spinSpeedList = spinSpeedList->Next; + spinSpeedList = spinSpeedList->Next; chip::Platform::Delete(del); } } @@ -118,7 +122,8 @@ CHIP_ERROR LaundryWasherDataProvider::ClearSpinSpeedList(EndpointId endpoint, Cl DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName()); } -CHIP_ERROR LaundryWasherDataProvider::StoreSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, const SupportedRinsesList & supportedRinsesList) +CHIP_ERROR LaundryWasherDataProvider::StoreSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, + const SupportedRinsesList & supportedRinsesList) { uint8_t buffer[kLaundryWasherMaxSerializedSize]; TLV::TLVWriter writer; @@ -127,33 +132,36 @@ CHIP_ERROR LaundryWasherDataProvider::StoreSupportedRinsesList(EndpointId endpoi ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, outerType)); for (auto const & supportedRinse : supportedRinsesList) { - //ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), supportedRinse.data())); - //ReturnErrorOnFailure(supportedRinse.Encode(writer, TLV::AnonymousTag())); + // ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), supportedRinse.data())); + // ReturnErrorOnFailure(supportedRinse.Encode(writer, TLV::AnonymousTag())); ReturnErrorOnFailure(writer.Put(TLV::AnonymousTag(), supportedRinse)); } ReturnErrorOnFailure(writer.EndContainer(outerType)); - return mPersistentStorage->SyncSetKeyValue(DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), - buffer, static_cast(writer.GetLengthWritten())); + return mPersistentStorage->SyncSetKeyValue( + DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), buffer, + static_cast(writer.GetLengthWritten())); } -CHIP_ERROR LaundryWasherDataProvider::LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, SupportedRinsesListSpan ** pSupportedRinsesList, size_t & size) +CHIP_ERROR LaundryWasherDataProvider::LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, + SupportedRinsesListSpan ** pSupportedRinsesList, size_t & size) { uint8_t buffer[kLaundryWasherMaxSerializedSize]; MutableByteSpan bufferSpan(buffer); size = 0; CHIP_ERROR err = CHIP_NO_ERROR; - ReturnErrorOnFailure(Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), bufferSpan)); + ReturnErrorOnFailure( + Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), bufferSpan)); TLV::TLVReader reader; TLV::TLVType outerType; reader.Init(bufferSpan.data(), bufferSpan.size()); ReturnErrorOnFailure(reader.Next(TLV::TLVType::kTLVType_Array, TLV::AnonymousTag())); ReturnErrorOnFailure(reader.EnterContainer(outerType)); - size_t i = 0; + size_t i = 0; SupportedRinsesListSpan * head = nullptr; while (reader.Next() != CHIP_ERROR_END_OF_TLV) { - SupportedRinsesListSpan* newSupportedRinse = chip::Platform::New(); - if (newSupportedRinse== nullptr) + SupportedRinsesListSpan * newSupportedRinse = chip::Platform::New(); + if (newSupportedRinse == nullptr) { ChipLogProgress(Zcl, "Malloc error"); break; @@ -169,7 +177,7 @@ CHIP_ERROR LaundryWasherDataProvider::LoadSupportedRinsesList(EndpointId endpoin } else { - SupportedRinsesListSpan* pList = head; + SupportedRinsesListSpan * pList = head; while (pList->Next != nullptr) { pList = pList->Next; @@ -178,7 +186,7 @@ CHIP_ERROR LaundryWasherDataProvider::LoadSupportedRinsesList(EndpointId endpoin } } ReturnErrorOnFailure(reader.ExitContainer(outerType)); - size = i; + size = i; *pSupportedRinsesList = head; return err; } @@ -187,8 +195,8 @@ void LaundryWasherDataProvider::ReleaseSupportedRinsesList(SupportedRinsesListSp { while (supportedRinsesList) { - SupportedRinsesListSpan* del = supportedRinsesList; - supportedRinsesList = supportedRinsesList->Next; + SupportedRinsesListSpan * del = supportedRinsesList; + supportedRinsesList = supportedRinsesList->Next; chip::Platform::Delete(del); } } @@ -207,4 +215,4 @@ CHIP_ERROR LaundryWasherDataProvider::Load(const char * key, MutableByteSpan & b return CHIP_NO_ERROR; } -} +} // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h index 3458c84cc53c0c..c3dd79a691b1f7 100644 --- a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h +++ b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h @@ -20,18 +20,16 @@ #include #include -#include #include +#include #include using namespace chip; using namespace chip::app::Clusters::LaundryWasherControls; - namespace chip { - constexpr size_t kSpinSpeedMaxSize = 32u; constexpr size_t kLaundryWasherMaxSerializedSize = 512u; @@ -60,7 +58,7 @@ struct SupportedRinsesListSpan class LaundryWasherDataProvider { public: - using SpinSpeedList = chip::app::DataModel::List; + using SpinSpeedList = chip::app::DataModel::List; using SupportedRinsesList = chip::app::DataModel::List; ~LaundryWasherDataProvider() {} @@ -123,7 +121,8 @@ class LaundryWasherDataProvider * @param size The number of phase list's item. * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. */ - CHIP_ERROR LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, SupportedRinsesListSpan ** pSupportedRinsesList, size_t & size); + CHIP_ERROR LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, SupportedRinsesListSpan ** pSupportedRinsesList, + size_t & size); /** * Rlease SupportedRinsesListSpan @@ -151,6 +150,4 @@ class LaundryWasherDataProvider PersistentStorageDelegate * mPersistentStorage = nullptr; }; - - } // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 566b654b7fd2f7..b2325ee1f99bdb 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -78,7 +78,8 @@ LaundryWasherControlsServer & LaundryWasherControlsServer::Instance() return sInstance; } -EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent) +EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpointId, + DataModel::Nullable newSpinSpeedCurrent) { DataModel::Nullable spinSpeedCurrent; EmberAfStatus res = SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); @@ -91,7 +92,8 @@ EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpoi return res; } -EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent) +EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedCurrent(EndpointId endpointId, + DataModel::Nullable & spinSpeedCurrent) { return SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); } @@ -117,25 +119,30 @@ EmberAfStatus LaundryWasherControlsServer::GetNumberOfRinses(EndpointId endpoint EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedList(EndpointId endpointId, const SpinSpeedList & spinSpeedList) { CHIP_ERROR err = mLaundryWasherDataProvider.StoreSpinSpeedList(endpointId, LaundryWasherControls::Id, spinSpeedList); - return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); + return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } -EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedList(EndpointId endpointId, SpinSpeedListCharSpan ** spinSpeedList, size_t & size) +EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedList(EndpointId endpointId, SpinSpeedListCharSpan ** spinSpeedList, + size_t & size) { CHIP_ERROR err = mLaundryWasherDataProvider.LoadSpinSpeedList(endpointId, LaundryWasherControls::Id, spinSpeedList, size); - return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); + return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } -EmberAfStatus LaundryWasherControlsServer::SetSupportedRinsesList(EndpointId endpointId, const SupportedRinsesList & supportedRinsesList) +EmberAfStatus LaundryWasherControlsServer::SetSupportedRinsesList(EndpointId endpointId, + const SupportedRinsesList & supportedRinsesList) { - CHIP_ERROR err = mLaundryWasherDataProvider.StoreSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList); - return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); + CHIP_ERROR err = + mLaundryWasherDataProvider.StoreSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList); + return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } -EmberAfStatus LaundryWasherControlsServer::GetSupportedRinsesList(EndpointId endpointId, SupportedRinsesListSpan ** supportedRinsesList, size_t & size) +EmberAfStatus LaundryWasherControlsServer::GetSupportedRinsesList(EndpointId endpointId, + SupportedRinsesListSpan ** supportedRinsesList, size_t & size) { - CHIP_ERROR err = mLaundryWasherDataProvider.LoadSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList, size); - return (err == CHIP_NO_ERROR)?(EMBER_ZCL_STATUS_SUCCESS):(EMBER_ZCL_STATUS_FAILURE); + CHIP_ERROR err = + mLaundryWasherDataProvider.LoadSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList, size); + return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } /********************************************************** @@ -151,7 +158,7 @@ CHIP_ERROR LaundryWasherControlsServer::ClearSpinSpeedList(EndpointId endpointId return mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); } -void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesListSpan* supportedRinsesList) +void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList) { mLaundryWasherDataProvider.ReleaseSupportedRinsesList(supportedRinsesList); } @@ -161,12 +168,11 @@ CHIP_ERROR LaundryWasherControlsServer::ClearSupportedRinsesList(EndpointId endp return mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); } -CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, - AttributeValueEncoder & aEncoder) +CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { SpinSpeedListCharSpan * spinSpeedList = nullptr; - size_t size = 0; - EndpointId endpointId = aPath.mEndpointId; + size_t size = 0; + EndpointId endpointId = aPath.mEndpointId; GetSpinSpeedList(endpointId, &spinSpeedList, size); CHIP_ERROR err = CHIP_NO_ERROR; @@ -187,11 +193,11 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttribu } CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, - AttributeValueEncoder & aEncoder) + AttributeValueEncoder & aEncoder) { SupportedRinsesListSpan * supportedRinsesList = nullptr; - size_t size = 0; - EndpointId endpointId = aPath.mEndpointId; + size_t size = 0; + EndpointId endpointId = aPath.mEndpointId; GetSupportedRinsesList(endpointId, &supportedRinsesList, size); CHIP_ERROR err = CHIP_NO_ERROR; @@ -199,8 +205,7 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAt if (size > 0) { return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - - for (SupportedRinsesListSpan* pHead = supportedRinsesList; pHead != nullptr; pHead = pHead->Next) + for (SupportedRinsesListSpan * pHead = supportedRinsesList; pHead != nullptr; pHead = pHead->Next) { ReturnErrorOnFailure(encoder.Encode(pHead->numberOfRinses)); } diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index dd7bd89d12ef1f..f041791d30ed96 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -17,10 +17,10 @@ #pragma once +#include "LaundryWasherDataProvider.h" #include -#include #include -#include "LaundryWasherDataProvider.h" +#include namespace chip { namespace app { @@ -37,7 +37,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; static LaundryWasherControlsServer & Instance(); - using SpinSpeedList = DataModel::List; + using SpinSpeedList = DataModel::List; using SupportedRinsesList = DataModel::List; /** @@ -116,6 +116,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. */ EmberAfStatus GetSupportedRinsesList(EndpointId endpointId, SupportedRinsesListSpan ** supportedRinsesList, size_t & size); + private: /** * Rlease SpinSpeedListCharSpan @@ -136,7 +137,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param supportedRinsesList The pointer for which to clear the SupportedRinsesListSpan. * @return void */ - void ReleaseSupportedRinsesList(SupportedRinsesListSpan* supportedRinsesList); + void ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList); /** * Clear supported rinses list. From 14f1ed7ef9c1396efa1a80ddde7023eb2aa9dd03 Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Thu, 20 Jul 2023 11:23:47 +0800 Subject: [PATCH 12/29] * Move the release / clean member functions to public - ReleaseSpinSpeedList / ClearSpinSpeedList - ReleaseSupportedRinsesList / ClearSupportedRinsesList Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-server.cpp | 18 +++++++++++------- .../laundry-washer-controls-server.h | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index b2325ee1f99bdb..03cddbde6a20b6 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -145,17 +145,16 @@ EmberAfStatus LaundryWasherControlsServer::GetSupportedRinsesList(EndpointId end return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } -/********************************************************** - * LaundryWasherControlsServer private methods - *********************************************************/ void LaundryWasherControlsServer::ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList) { mLaundryWasherDataProvider.ReleaseSpinSpeedList(spinSpeedList); } -CHIP_ERROR LaundryWasherControlsServer::ClearSpinSpeedList(EndpointId endpointId) +EmberAfStatus LaundryWasherControlsServer::ClearSpinSpeedList(EndpointId endpointId) { - return mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); + CHIP_ERROR err = + mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); + return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList) @@ -163,11 +162,16 @@ void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesList mLaundryWasherDataProvider.ReleaseSupportedRinsesList(supportedRinsesList); } -CHIP_ERROR LaundryWasherControlsServer::ClearSupportedRinsesList(EndpointId endpointId) +EmberAfStatus LaundryWasherControlsServer::ClearSupportedRinsesList(EndpointId endpointId) { - return mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); + CHIP_ERROR err = + mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); + return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } +/********************************************************** + * LaundryWasherControlsServer private methods + *********************************************************/ CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { SpinSpeedListCharSpan * spinSpeedList = nullptr; diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index f041791d30ed96..b95d51ac30da65 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -117,7 +117,6 @@ class LaundryWasherControlsServer : public AttributeAccessInterface */ EmberAfStatus GetSupportedRinsesList(EndpointId endpointId, SupportedRinsesListSpan ** supportedRinsesList, size_t & size); -private: /** * Rlease SpinSpeedListCharSpan * @param spinSpeedList The pointer for which to clear the SpinSpeedListCharSpan. @@ -130,7 +129,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param endpointId ID of the endpoint * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. */ - CHIP_ERROR ClearSpinSpeedList(EndpointId endpointId); + EmberAfStatus ClearSpinSpeedList(EndpointId endpointId); /** * Rlease SupportedRinsesListSpan @@ -144,8 +143,9 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param endpointId ID of the endpoint * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. */ - CHIP_ERROR ClearSupportedRinsesList(EndpointId endpointId); + EmberAfStatus ClearSupportedRinsesList(EndpointId endpointId); +private: CHIP_ERROR ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); From 845d1ea50b741c06829d7b7157fb59a55cd275e3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 20 Jul 2023 03:25:17 +0000 Subject: [PATCH 13/29] Restyled by clang-format --- .../laundry-washer-controls-server.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 03cddbde6a20b6..4fff34acd2203e 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -152,8 +152,7 @@ void LaundryWasherControlsServer::ReleaseSpinSpeedList(SpinSpeedListCharSpan * s EmberAfStatus LaundryWasherControlsServer::ClearSpinSpeedList(EndpointId endpointId) { - CHIP_ERROR err = - mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); + CHIP_ERROR err = mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } @@ -164,8 +163,7 @@ void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesList EmberAfStatus LaundryWasherControlsServer::ClearSupportedRinsesList(EndpointId endpointId) { - CHIP_ERROR err = - mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); + CHIP_ERROR err = mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); } From 461d6e3d6fcca54e8d9857303c2ef2274671b3a1 Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Fri, 21 Jul 2023 19:29:12 +0800 Subject: [PATCH 14/29] * Add back the delegate interface and report the items one by one * Remove the data provider Signed-off-by: Chin-Ran Lo --- src/app/chip_data_model.gni | 5 - .../LaundryWasherDataProvider.cpp | 218 ------------------ .../LaundryWasherDataProvider.h | 153 ------------ .../laundry-washer-controls-delegate.h | 57 +++++ .../laundry-washer-controls-server.cpp | 181 ++++++--------- .../laundry-washer-controls-server.h | 78 +------ 6 files changed, 139 insertions(+), 553 deletions(-) delete mode 100644 src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp delete mode 100644 src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h create mode 100644 src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 8fcaf477d884fc..0f4dd4fe183d91 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -274,11 +274,6 @@ template("chip_data_model") { "${_app_root}/clusters/${cluster}/resource-monitoring-cluster-objects.cpp", "${_app_root}/clusters/${cluster}/resource-monitoring-cluster-objects.h", ] - } else if (cluster == "laundry-washer-controls-server") { - sources += [ - "${_app_root}/clusters/${cluster}/${cluster}.cpp", - "${_app_root}/clusters/${cluster}/LaundryWasherDataProvider.cpp", - ] } else { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ] } diff --git a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp deleted file mode 100644 index 780882b5b1183d..00000000000000 --- a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * - * 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. - */ - -#include "LaundryWasherDataProvider.h" -#include -namespace chip { - -CHIP_ERROR LaundryWasherDataProvider::StoreSpinSpeedList(EndpointId endpoint, ClusterId clusterId, - const SpinSpeedList & spinSpeedList) -{ - uint8_t buffer[kLaundryWasherMaxSerializedSize]; - TLV::TLVWriter writer; - TLV::TLVType outerType; - writer.Init(buffer); - ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, outerType)); - for (auto const & spinSpeed : spinSpeedList) - { - ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), spinSpeed.data())); - } - ReturnErrorOnFailure(writer.EndContainer(outerType)); - return mPersistentStorage->SyncSetKeyValue( - DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), buffer, - static_cast(writer.GetLengthWritten())); -} - -CHIP_ERROR LaundryWasherDataProvider::LoadSpinSpeedList(EndpointId endpoint, ClusterId clusterId, - SpinSpeedListCharSpan ** pSpinSpeedList, size_t & size) -{ - uint8_t buffer[kLaundryWasherMaxSerializedSize]; - MutableByteSpan bufferSpan(buffer); - size = 0; - CHIP_ERROR err = CHIP_NO_ERROR; - ReturnErrorOnFailure( - Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName(), bufferSpan)); - TLV::TLVReader reader; - TLV::TLVType outerType; - reader.Init(bufferSpan.data(), bufferSpan.size()); - ReturnErrorOnFailure(reader.Next(TLV::TLVType::kTLVType_Array, TLV::AnonymousTag())); - ReturnErrorOnFailure(reader.EnterContainer(outerType)); - size_t i = 0; - SpinSpeedListCharSpan * head = nullptr; - while (reader.Next() != CHIP_ERROR_END_OF_TLV) - { - SpinSpeedListCharSpan * newSpinSpeed = chip::Platform::New(); - if (newSpinSpeed == nullptr) - { - ChipLogProgress(Zcl, "Malloc error"); - break; - } - newSpinSpeed->Next = nullptr; - CharSpan readSpinSpeed; - ReturnErrorOnFailure(reader.Get(readSpinSpeed)); - - if (readSpinSpeed.size()) - { - if (readSpinSpeed.size() <= kSpinSpeedMaxSize) - { - char * dest = const_cast(newSpinSpeed->SpinSpeed_c); - size_t len = readSpinSpeed.size(); - memcpy(dest, readSpinSpeed.data(), len); - newSpinSpeed->spinSpeed = CharSpan::fromCharString(newSpinSpeed->SpinSpeed_c); - } - else - { - err = CHIP_ERROR_BUFFER_TOO_SMALL; - } - } - else - { - chip::Platform::Delete(newSpinSpeed); - continue; - } - i++; - if (head == nullptr) - { - head = newSpinSpeed; - } - else - { - SpinSpeedListCharSpan * pList = head; - while (pList->Next != nullptr) - { - pList = pList->Next; - } - pList->Next = newSpinSpeed; - } - } - ReturnErrorOnFailure(reader.ExitContainer(outerType)); - size = i; - *pSpinSpeedList = head; - return err; -} - -void LaundryWasherDataProvider::ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList) -{ - while (spinSpeedList) - { - SpinSpeedListCharSpan * del = spinSpeedList; - spinSpeedList = spinSpeedList->Next; - chip::Platform::Delete(del); - } -} - -CHIP_ERROR LaundryWasherDataProvider::ClearSpinSpeedList(EndpointId endpoint, ClusterId clusterId) -{ - return mPersistentStorage->SyncDeleteKeyValue( - DefaultStorageKeyAllocator::LaundryWasherCtrlSpinSpeedsList(endpoint, clusterId).KeyName()); -} - -CHIP_ERROR LaundryWasherDataProvider::StoreSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, - const SupportedRinsesList & supportedRinsesList) -{ - uint8_t buffer[kLaundryWasherMaxSerializedSize]; - TLV::TLVWriter writer; - TLV::TLVType outerType; - writer.Init(buffer); - ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, outerType)); - for (auto const & supportedRinse : supportedRinsesList) - { - // ReturnErrorOnFailure(writer.PutString(TLV::AnonymousTag(), supportedRinse.data())); - // ReturnErrorOnFailure(supportedRinse.Encode(writer, TLV::AnonymousTag())); - ReturnErrorOnFailure(writer.Put(TLV::AnonymousTag(), supportedRinse)); - } - ReturnErrorOnFailure(writer.EndContainer(outerType)); - return mPersistentStorage->SyncSetKeyValue( - DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), buffer, - static_cast(writer.GetLengthWritten())); -} - -CHIP_ERROR LaundryWasherDataProvider::LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, - SupportedRinsesListSpan ** pSupportedRinsesList, size_t & size) -{ - uint8_t buffer[kLaundryWasherMaxSerializedSize]; - MutableByteSpan bufferSpan(buffer); - size = 0; - CHIP_ERROR err = CHIP_NO_ERROR; - ReturnErrorOnFailure( - Load(DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName(), bufferSpan)); - TLV::TLVReader reader; - TLV::TLVType outerType; - reader.Init(bufferSpan.data(), bufferSpan.size()); - ReturnErrorOnFailure(reader.Next(TLV::TLVType::kTLVType_Array, TLV::AnonymousTag())); - ReturnErrorOnFailure(reader.EnterContainer(outerType)); - size_t i = 0; - SupportedRinsesListSpan * head = nullptr; - while (reader.Next() != CHIP_ERROR_END_OF_TLV) - { - SupportedRinsesListSpan * newSupportedRinse = chip::Platform::New(); - if (newSupportedRinse == nullptr) - { - ChipLogProgress(Zcl, "Malloc error"); - break; - } - newSupportedRinse->Next = nullptr; - NumberOfRinsesEnum numberOfRinses; - ReturnErrorOnFailure(reader.Get(numberOfRinses)); - newSupportedRinse->numberOfRinses = numberOfRinses; - i++; - if (head == nullptr) - { - head = newSupportedRinse; - } - else - { - SupportedRinsesListSpan * pList = head; - while (pList->Next != nullptr) - { - pList = pList->Next; - } - pList->Next = newSupportedRinse; - } - } - ReturnErrorOnFailure(reader.ExitContainer(outerType)); - size = i; - *pSupportedRinsesList = head; - return err; -} - -void LaundryWasherDataProvider::ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList) -{ - while (supportedRinsesList) - { - SupportedRinsesListSpan * del = supportedRinsesList; - supportedRinsesList = supportedRinsesList->Next; - chip::Platform::Delete(del); - } -} - -CHIP_ERROR LaundryWasherDataProvider::ClearSupportedRinsesList(EndpointId endpoint, ClusterId clusterId) -{ - return mPersistentStorage->SyncDeleteKeyValue( - DefaultStorageKeyAllocator::LaundryWasherCtrlSupportedRinsesList(endpoint, clusterId).KeyName()); -} - -CHIP_ERROR LaundryWasherDataProvider::Load(const char * key, MutableByteSpan & buffer) -{ - uint16_t size = static_cast(buffer.size()); - ReturnErrorOnFailure(mPersistentStorage->SyncGetKeyValue(key, buffer.data(), size)); - buffer = MutableByteSpan(buffer.data(), size); - return CHIP_NO_ERROR; -} - -} // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h b/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h deleted file mode 100644 index c3dd79a691b1f7..00000000000000 --- a/src/app/clusters/laundry-washer-controls-server/LaundryWasherDataProvider.h +++ /dev/null @@ -1,153 +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. - */ - -#pragma once - -#include -#include - -#include -#include - -#include - -using namespace chip; -using namespace chip::app::Clusters::LaundryWasherControls; - -namespace chip { - -constexpr size_t kSpinSpeedMaxSize = 32u; -constexpr size_t kLaundryWasherMaxSerializedSize = 512u; - -/** - * A class that can create a link list for spin speed list of laundry washer controls cluster - */ -struct SpinSpeedListCharSpan -{ - char SpinSpeed_c[kSpinSpeedMaxSize]; - CharSpan spinSpeed; - SpinSpeedListCharSpan * Next; -}; - -/** - * A class that can create a link list for supported rinses list of laundry washer controls cluster - */ -struct SupportedRinsesListSpan -{ - NumberOfRinsesEnum numberOfRinses; - SupportedRinsesListSpan * Next; -}; - -/** - * Interface to help manage the phase list and operation state list of the Operational State Cluster. - */ -class LaundryWasherDataProvider -{ -public: - using SpinSpeedList = chip::app::DataModel::List; - using SupportedRinsesList = chip::app::DataModel::List; - - ~LaundryWasherDataProvider() {} - - /** - * Init the operational state data provider. - * @param persistentStorage The refence of pesistent storage object. - * @return void - */ - void Init(PersistentStorageDelegate & persistentStorage) { mPersistentStorage = &persistentStorage; } - - /** - * Store spin speed list to storage. - * @param endpointId The endpoint for which to save the list[string]. - * @param clusterId The cluster for which to save the list[string]. - * @param spinSpeedList The spin speed list for which to save. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR StoreSpinSpeedList(EndpointId endpoint, ClusterId clusterId, const SpinSpeedList & spinSpeedList); - - /** - * Load spin speed list from storage. - * @param endpointId The endpoint for which to load the list[string]. - * @param clusterId The cluster for which to load the list[string]. - * @param pSpinSpeedList The pointer to load phase list. - * @param size The number of phase list's item. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR LoadSpinSpeedList(EndpointId endpoint, ClusterId clusterId, SpinSpeedListCharSpan ** pSpinSpeedList, size_t & size); - - /** - * Rlease spinSpeedListCharSpan - * @param spinSpeedList The pointer for which to clear the SpinSpeedListCharSpan. - * @return void - */ - void ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList); - - /** - * Clear spin speed list from storage. - * @param endpointId The endpoint for which to clear the list[string]. - * @param clusterId The cluster for which to clear the list[string]. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR ClearSpinSpeedList(EndpointId endpoint, ClusterId clusterId); - - /** - * Store supported rinses list to storage. - * @param endpointId The endpoint for which to save the list[string]. - * @param clusterId The cluster for which to save the list[string]. - * @param supportedRinsesList The supported rinses list for which to save. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR StoreSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, const SupportedRinsesList & supportedRinsesList); - - /** - * Load supported rinses list from storage. - * @param endpointId The endpoint for which to load the list[string]. - * @param clusterId The cluster for which to load the list[string]. - * @param pSupportedRinsesList The pointer to load phase list. - * @param size The number of phase list's item. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR LoadSupportedRinsesList(EndpointId endpoint, ClusterId clusterId, SupportedRinsesListSpan ** pSupportedRinsesList, - size_t & size); - - /** - * Rlease SupportedRinsesListSpan - * @param supportedRinsesList The pointer for which to clear the SupportedRinsesListSpan. - * @return void - */ - void ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList); - - /** - * Clear supported rinses list from storage. - * @param endpointId The endpoint for which to clear the list[string]. - * @param clusterId The cluster for which to clear the list[string]. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR ClearSupportedRinsesList(EndpointId endpoint, ClusterId clusterId); - -private: - /** - * Load content by key from storage. - * @param key key to save the content. - * @param buffer buffer to save the content. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - CHIP_ERROR Load(const char * key, MutableByteSpan & buffer); - PersistentStorageDelegate * mPersistentStorage = nullptr; -}; - -} // namespace chip diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h new file mode 100644 index 00000000000000..ba3f07b4af6378 --- /dev/null +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -0,0 +1,57 @@ +/* + * + * 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 +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace LaundryWasherControls { + +/** @brief + * Defines methods for implementing application-specific logic for the laundry washer controls cluster. + */ +class Delegate +{ +public: + Delegate() = default; + virtual ~Delegate() = default; + + /** + * Get the list of supported spin_speed list. + * @param index The index of the spin_speed, with 0 representing the first one. + * @param spinSpeed The spin speed is filled. + */ + virtual CHIP_ERROR GetSpinSpeedAtIndex(size_t index, CharSpan & spinSpeed) = 0; + + /** + * Get the list of supported rinses list. + * @param index The index of the supported rinses with 0 representing the first one. + * @param supportedRinse The supported rinse is filled. + */ + virtual CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse) = 0; + +}; + +} // namespace LaundryWasherControls +} // namespace Clusters +} // namespace app +} // namespace chip + diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 4fff34acd2203e..b29f9b5edf6ecc 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -29,11 +29,13 @@ #include #include #include -#include +#include "laundry-washer-controls-delegate.h" +#include "laundry-washer-controls-server.h" #include #include #include + using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; @@ -41,36 +43,35 @@ using namespace chip::app::Clusters::LaundryWasherControls; using namespace chip::app::Clusters::LaundryWasherControls::Attributes; using chip::Protocols::InteractionModel::Status; +static constexpr size_t kLaundryWasherControlsDelegateTableSize = + EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; + +// ----------------------------------------------------------------------------- +// Delegate Implementation +// +namespace { +Delegate * gDelegateTable[kLaundryWasherControlsDelegateTableSize] = { nullptr }; +} + +namespace { +Delegate * GetDelegate(EndpointId endpoint) +{ + return (endpoint > kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[endpoint]); +} + +} + LaundryWasherControlsServer LaundryWasherControlsServer::sInstance; /********************************************************** * LaundryWasherControlsServer public methods *********************************************************/ - -CHIP_ERROR LaundryWasherControlsServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +void LaundryWasherControlsServer::SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - if (aPath.mClusterId != LaundryWasherControls::Id) + if (endpoint < kLaundryWasherControlsDelegateTableSize) { - // We shouldn't have been called at all. - return CHIP_ERROR_INVALID_ARGUMENT; + gDelegateTable[endpoint] = delegate; } - switch (aPath.mAttributeId) - { - case Attributes::SpinSpeeds::Id: - return ReadSpinSpeeds(aPath, aEncoder); - case Attributes::SupportedRinses::Id: - return ReadSupportedRinses(aPath, aEncoder); - default: - break; - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR LaundryWasherControlsServer::Init() -{ - mLaundryWasherDataProvider.Init(Server::GetInstance().GetPersistentStorage()); - - return CHIP_NO_ERROR; } LaundryWasherControlsServer & LaundryWasherControlsServer::Instance() @@ -83,7 +84,6 @@ EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpoi { DataModel::Nullable spinSpeedCurrent; EmberAfStatus res = SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent); - if ((res == EMBER_ZCL_STATUS_SUCCESS) && (spinSpeedCurrent != newSpinSpeedCurrent)) { res = SpinSpeedCurrent::Set(endpointId, newSpinSpeedCurrent); @@ -116,107 +116,69 @@ EmberAfStatus LaundryWasherControlsServer::GetNumberOfRinses(EndpointId endpoint return NumberOfRinses::Get(endpointId, &numberOfRinses); } -EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedList(EndpointId endpointId, const SpinSpeedList & spinSpeedList) -{ - CHIP_ERROR err = mLaundryWasherDataProvider.StoreSpinSpeedList(endpointId, LaundryWasherControls::Id, spinSpeedList); - return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); -} - -EmberAfStatus LaundryWasherControlsServer::GetSpinSpeedList(EndpointId endpointId, SpinSpeedListCharSpan ** spinSpeedList, - size_t & size) -{ - CHIP_ERROR err = mLaundryWasherDataProvider.LoadSpinSpeedList(endpointId, LaundryWasherControls::Id, spinSpeedList, size); - return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); -} - -EmberAfStatus LaundryWasherControlsServer::SetSupportedRinsesList(EndpointId endpointId, - const SupportedRinsesList & supportedRinsesList) -{ - CHIP_ERROR err = - mLaundryWasherDataProvider.StoreSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList); - return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); -} - -EmberAfStatus LaundryWasherControlsServer::GetSupportedRinsesList(EndpointId endpointId, - SupportedRinsesListSpan ** supportedRinsesList, size_t & size) -{ - CHIP_ERROR err = - mLaundryWasherDataProvider.LoadSupportedRinsesList(endpointId, LaundryWasherControls::Id, supportedRinsesList, size); - return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); -} - -void LaundryWasherControlsServer::ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList) -{ - mLaundryWasherDataProvider.ReleaseSpinSpeedList(spinSpeedList); -} - -EmberAfStatus LaundryWasherControlsServer::ClearSpinSpeedList(EndpointId endpointId) -{ - CHIP_ERROR err = mLaundryWasherDataProvider.ClearSpinSpeedList(endpointId, LaundryWasherControls::Id); - return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); -} - -void LaundryWasherControlsServer::ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList) -{ - mLaundryWasherDataProvider.ReleaseSupportedRinsesList(supportedRinsesList); -} - -EmberAfStatus LaundryWasherControlsServer::ClearSupportedRinsesList(EndpointId endpointId) -{ - CHIP_ERROR err = mLaundryWasherDataProvider.ClearSupportedRinsesList(endpointId, LaundryWasherControls::Id); - return (err == CHIP_NO_ERROR) ? (EMBER_ZCL_STATUS_SUCCESS) : (EMBER_ZCL_STATUS_FAILURE); -} - /********************************************************** * LaundryWasherControlsServer private methods *********************************************************/ -CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +CHIP_ERROR LaundryWasherControlsServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - SpinSpeedListCharSpan * spinSpeedList = nullptr; - size_t size = 0; - EndpointId endpointId = aPath.mEndpointId; - GetSpinSpeedList(endpointId, &spinSpeedList, size); - CHIP_ERROR err = CHIP_NO_ERROR; + if (aPath.mClusterId != LaundryWasherControls::Id) + { + // We shouldn't have been called at all. + return CHIP_ERROR_INVALID_ARGUMENT; + } + switch (aPath.mAttributeId) + { + case Attributes::SpinSpeeds::Id: + return ReadSpinSpeeds(aPath, aEncoder); + case Attributes::SupportedRinses::Id: + return ReadSupportedRinses(aPath, aEncoder); + default: + break; + } + return CHIP_NO_ERROR; +} +CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ aEncoder.EncodeEmptyList(); - if (size > 0) - { - return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - for (SpinSpeedListCharSpan * pHead = spinSpeedList; pHead != nullptr; pHead = pHead->Next) + Delegate *delegate = GetDelegate(aPath.mEndpointId); + VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); + + return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + for (uint8_t i = 0 ; true ; i++) { - ReturnErrorOnFailure(encoder.Encode(pHead->spinSpeed)); + CharSpan spinSpeed; + auto err = delegate->GetSpinSpeedAtIndex(i, spinSpeed); + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) + { + return CHIP_NO_ERROR; + } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(encoder.Encode(spinSpeed)); } - ReleaseSpinSpeedList(spinSpeedList); - spinSpeedList = nullptr; - return CHIP_NO_ERROR; - }); - } - return err; + }); } CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - SupportedRinsesListSpan * supportedRinsesList = nullptr; - size_t size = 0; - EndpointId endpointId = aPath.mEndpointId; - GetSupportedRinsesList(endpointId, &supportedRinsesList, size); - CHIP_ERROR err = CHIP_NO_ERROR; - aEncoder.EncodeEmptyList(); - if (size > 0) - { - return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - for (SupportedRinsesListSpan * pHead = supportedRinsesList; pHead != nullptr; pHead = pHead->Next) + Delegate *delegate = GetDelegate(aPath.mEndpointId); + VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); + + return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + for (uint8_t i = 0 ; true ; i++) { - ReturnErrorOnFailure(encoder.Encode(pHead->numberOfRinses)); + NumberOfRinsesEnum supportedRinse; + auto err = delegate->GetSupportedRinseAtIndex(i, supportedRinse); + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) + { + return CHIP_NO_ERROR; + } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(encoder.Encode(supportedRinse)); } - ReleaseSupportedRinsesList(supportedRinsesList); - supportedRinsesList = nullptr; - return CHIP_NO_ERROR; - }); - } - return err; + }); } /********************************************************** @@ -227,5 +189,4 @@ void MatterLaundryWasherControlsPluginServerInitCallback() { LaundryWasherControlsServer & laundryWasherControlsServer = LaundryWasherControlsServer::Instance(); registerAttributeAccessOverride(&laundryWasherControlsServer); - laundryWasherControlsServer.Init(); } diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index b95d51ac30da65..26f43e1e170038 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -17,10 +17,10 @@ #pragma once -#include "LaundryWasherDataProvider.h" #include #include #include +#include "laundry-washer-controls-delegate.h" namespace chip { namespace app { @@ -34,18 +34,25 @@ class LaundryWasherControlsServer : public AttributeAccessInterface { public: LaundryWasherControlsServer() : AttributeAccessInterface(Optional::Missing(), LaundryWasherControls::Id) {} - CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; static LaundryWasherControlsServer & Instance(); using SpinSpeedList = DataModel::List; using SupportedRinsesList = DataModel::List; + /** + * Set the default delegate of laundry washer server at endpoint x + * @param endpoint ID of the endpoint + * @param delegate The default delegate at the endpoint + * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. + */ + static void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate); + /** * Init the laundry washer server. * @param void * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. */ - CHIP_ERROR Init(); +// CHIP_ERROR Init(); /** * @brief Set the attribute newSpinSpeedCurrent @@ -83,74 +90,11 @@ class LaundryWasherControlsServer : public AttributeAccessInterface */ EmberAfStatus GetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses); - /** - * Set spin speed list. - * @param endpointId ID of the endpoint - * @param spinSpeedList The spin speed list for which to save. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - EmberAfStatus SetSpinSpeedList(EndpointId endpointId, const SpinSpeedList & spinSpeedList); - - /** - * Get spin speed list. - * @param endpointId ID of the endpoint - * @param spinSpeedList The pointer to load spin speed list. - * @param size The number of phase list's item. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - EmberAfStatus GetSpinSpeedList(EndpointId endpointId, SpinSpeedListCharSpan ** spinSpeedList, size_t & size); - - /** - * Set supportd rinses list. - * @param endpointId ID of the endpoint - * @param SupportedRinsesList The supported rinses list for which to save. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - EmberAfStatus SetSupportedRinsesList(EndpointId endpointId, const SupportedRinsesList & supportedRinsesList); - - /** - * Get supported rinses list. - * @param endpointId ID of the endpoint - * @param supportedRinsesList The pointer to load supported rinses list. - * @param size The number of phase list's item. - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - EmberAfStatus GetSupportedRinsesList(EndpointId endpointId, SupportedRinsesListSpan ** supportedRinsesList, size_t & size); - - /** - * Rlease SpinSpeedListCharSpan - * @param spinSpeedList The pointer for which to clear the SpinSpeedListCharSpan. - * @return void - */ - void ReleaseSpinSpeedList(SpinSpeedListCharSpan * spinSpeedList); - - /** - * Clear spin speed list. - * @param endpointId ID of the endpoint - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - EmberAfStatus ClearSpinSpeedList(EndpointId endpointId); - - /** - * Rlease SupportedRinsesListSpan - * @param supportedRinsesList The pointer for which to clear the SupportedRinsesListSpan. - * @return void - */ - void ReleaseSupportedRinsesList(SupportedRinsesListSpan * supportedRinsesList); - - /** - * Clear supported rinses list. - * @param endpointId ID of the endpoint - * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. - */ - EmberAfStatus ClearSupportedRinsesList(EndpointId endpointId); - private: + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; CHIP_ERROR ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder); - LaundryWasherDataProvider mLaundryWasherDataProvider; - static LaundryWasherControlsServer sInstance; }; From 21fa5ee35a8684851dac1a4d9555f8c99144978e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 21 Jul 2023 11:31:27 +0000 Subject: [PATCH 15/29] Restyled by whitespace --- .../laundry-washer-controls-delegate.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h index ba3f07b4af6378..251d6c91657f5f 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -54,4 +54,3 @@ class Delegate } // namespace Clusters } // namespace app } // namespace chip - From 7bef9a0076e2b0865eee60161cb0893dae050072 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 21 Jul 2023 11:31:28 +0000 Subject: [PATCH 16/29] Restyled by clang-format --- .../laundry-washer-controls-delegate.h | 5 +- .../laundry-washer-controls-server.cpp | 47 +++++++++---------- .../laundry-washer-controls-server.h | 4 +- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h index 251d6c91657f5f..41c623bbf743bc 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -31,7 +31,7 @@ namespace LaundryWasherControls { class Delegate { public: - Delegate() = default; + Delegate() = default; virtual ~Delegate() = default; /** @@ -46,8 +46,7 @@ class Delegate * @param index The index of the supported rinses with 0 representing the first one. * @param supportedRinse The supported rinse is filled. */ - virtual CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse) = 0; - + virtual CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse) = 0; }; } // namespace LaundryWasherControls diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index b29f9b5edf6ecc..2faa989cbf6d5b 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -19,6 +19,8 @@ #include #include +#include "laundry-washer-controls-delegate.h" +#include "laundry-washer-controls-server.h" #include #include #include @@ -29,13 +31,10 @@ #include #include #include -#include "laundry-washer-controls-delegate.h" -#include "laundry-washer-controls-server.h" #include #include #include - using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; @@ -59,7 +58,7 @@ Delegate * GetDelegate(EndpointId endpoint) return (endpoint > kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[endpoint]); } -} +} // namespace LaundryWasherControlsServer LaundryWasherControlsServer::sInstance; @@ -141,21 +140,21 @@ CHIP_ERROR LaundryWasherControlsServer::Read(const ConcreteReadAttributePath & a CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { aEncoder.EncodeEmptyList(); - Delegate *delegate = GetDelegate(aPath.mEndpointId); + Delegate * delegate = GetDelegate(aPath.mEndpointId); VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - for (uint8_t i = 0 ; true ; i++) + for (uint8_t i = 0; true; i++) + { + CharSpan spinSpeed; + auto err = delegate->GetSpinSpeedAtIndex(i, spinSpeed); + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) { - CharSpan spinSpeed; - auto err = delegate->GetSpinSpeedAtIndex(i, spinSpeed); - if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) - { - return CHIP_NO_ERROR; - } - ReturnErrorOnFailure(err); - ReturnErrorOnFailure(encoder.Encode(spinSpeed)); + return CHIP_NO_ERROR; } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(encoder.Encode(spinSpeed)); + } }); } @@ -163,21 +162,21 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAt AttributeValueEncoder & aEncoder) { aEncoder.EncodeEmptyList(); - Delegate *delegate = GetDelegate(aPath.mEndpointId); + Delegate * delegate = GetDelegate(aPath.mEndpointId); VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - for (uint8_t i = 0 ; true ; i++) + for (uint8_t i = 0; true; i++) + { + NumberOfRinsesEnum supportedRinse; + auto err = delegate->GetSupportedRinseAtIndex(i, supportedRinse); + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) { - NumberOfRinsesEnum supportedRinse; - auto err = delegate->GetSupportedRinseAtIndex(i, supportedRinse); - if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) - { - return CHIP_NO_ERROR; - } - ReturnErrorOnFailure(err); - ReturnErrorOnFailure(encoder.Encode(supportedRinse)); + return CHIP_NO_ERROR; } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(encoder.Encode(supportedRinse)); + } }); } diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 26f43e1e170038..692bb1d11cac2a 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -17,10 +17,10 @@ #pragma once +#include "laundry-washer-controls-delegate.h" #include #include #include -#include "laundry-washer-controls-delegate.h" namespace chip { namespace app { @@ -52,7 +52,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param void * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. */ -// CHIP_ERROR Init(); + // CHIP_ERROR Init(); /** * @brief Set the attribute newSpinSpeedCurrent From bbe0590f97974aa7f4825844fa673b71f493e3cf Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Fri, 21 Jul 2023 20:11:23 +0800 Subject: [PATCH 17/29] * Remove the unused definition for storage-key-alloc Signed-off-by: Chin-Ran Lo --- src/lib/support/DefaultStorageKeyAllocator.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/lib/support/DefaultStorageKeyAllocator.h b/src/lib/support/DefaultStorageKeyAllocator.h index 40826d4cd7a2a1..9adc8fdf287353 100644 --- a/src/lib/support/DefaultStorageKeyAllocator.h +++ b/src/lib/support/DefaultStorageKeyAllocator.h @@ -182,17 +182,6 @@ class DefaultStorageKeyAllocator return StorageKeyName::Formatted("f/%x/icd/%x", fabric, index); } - // Laundry Washer Control cluster - static StorageKeyName LaundryWasherCtrlSpinSpeedsList(EndpointId endpoint, ClusterId clusterId) - { - return StorageKeyName::Formatted("g/lwc/ssl/%x/%" PRIx32, endpoint, clusterId); - } - - static StorageKeyName LaundryWasherCtrlSupportedRinsesList(EndpointId endpoint, ClusterId clusterId) - { - return StorageKeyName::Formatted("g/lwc/srl/%x/%" PRIx32, endpoint, clusterId); - } - static StorageKeyName OTADefaultProviders() { return StorageKeyName::FromConst("g/o/dp"); } static StorageKeyName OTACurrentProvider() { return StorageKeyName::FromConst("g/o/cp"); } static StorageKeyName OTAUpdateToken() { return StorageKeyName::FromConst("g/o/ut"); } From 72d62795e15df152c4361e47cc8f26b20892dab5 Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 11:31:03 +0800 Subject: [PATCH 18/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 2faa989cbf6d5b..1a5c2ec946612a 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -143,7 +143,7 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttribu Delegate * delegate = GetDelegate(aPath.mEndpointId); VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); - return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + return aEncoder.EncodeList([delegate](const auto & encoder) -> CHIP_ERROR { for (uint8_t i = 0; true; i++) { CharSpan spinSpeed; From 9f38b00725b88e5d763e12fe1ddcad9299e35f10 Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 11:31:18 +0800 Subject: [PATCH 19/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 692bb1d11cac2a..7b4fa40c38b4e3 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -61,7 +61,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param newSpinSpeedCurrent attribute SpinSpeedCurrent * @return true on success, false on failure */ - EmberAfStatus SetSpinSpeedCurrent(chip::EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent); + EmberAfStatus SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable newSpinSpeedCurrent); /** * @brief Get the attribute newSpinSpeedCurrent From f619a527679feb3bda3ef5fec76012a0390959bd Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 11:31:29 +0800 Subject: [PATCH 20/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 7b4fa40c38b4e3..8d95d14c9b7b48 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -70,7 +70,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param SpinSpeedCurrent attribute SpinSpeedCurrent * @return true on success, false on failure */ - EmberAfStatus GetSpinSpeedCurrent(chip::EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent); + EmberAfStatus GetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable & spinSpeedCurrent); /** * @brief Set the attribute NumberOfRinses From b4f1b0173bf5a70c83ff52d8fd4d608e2321b6c8 Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 11:31:49 +0800 Subject: [PATCH 21/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 1a5c2ec946612a..34a8622a7eb252 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -165,7 +165,7 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAt Delegate * delegate = GetDelegate(aPath.mEndpointId); VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); - return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + return aEncoder.EncodeList([delegate](const auto & encoder) -> CHIP_ERROR { for (uint8_t i = 0; true; i++) { NumberOfRinsesEnum supportedRinse; From 402da53786cda06b3b1edda9fccf88130b39ff23 Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 12:04:05 +0800 Subject: [PATCH 22/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 34a8622a7eb252..a9c1fb04e2bad3 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -161,7 +161,6 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttribu CHIP_ERROR LaundryWasherControlsServer::ReadSupportedRinses(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - aEncoder.EncodeEmptyList(); Delegate * delegate = GetDelegate(aPath.mEndpointId); VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); From db5a449f30863301f12843457bfeb800e34878e4 Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Sat, 22 Jul 2023 12:40:18 +0800 Subject: [PATCH 23/29] * Use MutableCharSpan to replace CharSpan * Add to calculate the delegate id from endpoint Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-delegate.h | 2 +- .../laundry-washer-controls-server.cpp | 15 +++++++++++---- .../laundry-washer-controls-server.h | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h index 41c623bbf743bc..db8ae11e34b89b 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -39,7 +39,7 @@ class Delegate * @param index The index of the spin_speed, with 0 representing the first one. * @param spinSpeed The spin speed is filled. */ - virtual CHIP_ERROR GetSpinSpeedAtIndex(size_t index, CharSpan & spinSpeed) = 0; + virtual CHIP_ERROR GetSpinSpeedAtIndex(size_t index, MutableCharSpan & spinSpeed) = 0; /** * Get the list of supported rinses list. diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index a9c1fb04e2bad3..31b4cbf044d9f7 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -55,7 +55,10 @@ Delegate * gDelegateTable[kLaundryWasherControlsDelegateTableSize] = { nullptr } namespace { Delegate * GetDelegate(EndpointId endpoint) { - return (endpoint > kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[endpoint]); + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, + EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); + return (ep >= kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[ep]); + } } // namespace @@ -67,9 +70,12 @@ LaundryWasherControlsServer LaundryWasherControlsServer::sInstance; *********************************************************/ void LaundryWasherControlsServer::SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) { - if (endpoint < kLaundryWasherControlsDelegateTableSize) + uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, + EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); + // if endpoint is found + if (ep < kLaundryWasherControlsDelegateTableSize) { - gDelegateTable[endpoint] = delegate; + gDelegateTable[ep] = delegate; } } @@ -146,7 +152,8 @@ CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttribu return aEncoder.EncodeList([delegate](const auto & encoder) -> CHIP_ERROR { for (uint8_t i = 0; true; i++) { - CharSpan spinSpeed; + char buffer[kMaxSpinSpeedLength]; + MutableCharSpan spinSpeed(buffer); auto err = delegate->GetSpinSpeedAtIndex(i, spinSpeed); if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) { diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 8d95d14c9b7b48..1f40a716fc1648 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -39,6 +39,8 @@ class LaundryWasherControlsServer : public AttributeAccessInterface using SpinSpeedList = DataModel::List; using SupportedRinsesList = DataModel::List; + static constexpr uint8_t kMaxSpinSpeedLength = 64; + /** * Set the default delegate of laundry washer server at endpoint x * @param endpoint ID of the endpoint From 550253fc611fb351b1a4457de3ab54ff9fea8ae7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 22 Jul 2023 04:40:58 +0000 Subject: [PATCH 24/29] Restyled by clang-format --- .../laundry-washer-controls-server.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 31b4cbf044d9f7..76832e4c091eb8 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -58,7 +58,6 @@ Delegate * GetDelegate(EndpointId endpoint) uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, LaundryWasherControls::Id, EMBER_AF_LAUNDRY_WASHER_CONTROLS_CLUSTER_SERVER_ENDPOINT_COUNT); return (ep >= kLaundryWasherControlsDelegateTableSize ? nullptr : gDelegateTable[ep]); - } } // namespace @@ -145,7 +144,6 @@ CHIP_ERROR LaundryWasherControlsServer::Read(const ConcreteReadAttributePath & a CHIP_ERROR LaundryWasherControlsServer::ReadSpinSpeeds(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { - aEncoder.EncodeEmptyList(); Delegate * delegate = GetDelegate(aPath.mEndpointId); VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is nullptr")); From cc8b13faadbb52bf08216dc304b3566287ef0322 Mon Sep 17 00:00:00 2001 From: Chin-Ran Lo Date: Sat, 22 Jul 2023 14:36:57 +0800 Subject: [PATCH 25/29] * Refine the comment Signed-off-by: Chin-Ran Lo --- .../laundry-washer-controls-delegate.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h index db8ae11e34b89b..5529413a40cb88 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -36,6 +36,8 @@ class Delegate /** * Get the list of supported spin_speed list. + * Fills in the provided spin_speed at index `index` if there is one, + * or returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of spin_speed. * @param index The index of the spin_speed, with 0 representing the first one. * @param spinSpeed The spin speed is filled. */ @@ -43,6 +45,8 @@ class Delegate /** * Get the list of supported rinses list. + * Fills in the provided rinses at index `index` if there is one, + * or returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of rinses. * @param index The index of the supported rinses with 0 representing the first one. * @param supportedRinse The supported rinse is filled. */ From de033f2580bfa0bbc91a09a0a43f80d76a8a9a16 Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:40:49 +0800 Subject: [PATCH 26/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 1f40a716fc1648..7a5eb7f7a017de 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -81,7 +81,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param newNumberOfRinses attribute NumberOfRinses * @return true on success, false on failure */ - EmberAfStatus SetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses); + EmberAfStatus SetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses); /** * @brief Get the attribute NumberOfRinses From 1da8c1a97d885a4e402d4c5ece796b22ead8b5cb Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:44:53 +0800 Subject: [PATCH 27/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 7a5eb7f7a017de..70666dc1340e1b 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -36,8 +36,6 @@ class LaundryWasherControlsServer : public AttributeAccessInterface LaundryWasherControlsServer() : AttributeAccessInterface(Optional::Missing(), LaundryWasherControls::Id) {} static LaundryWasherControlsServer & Instance(); - using SpinSpeedList = DataModel::List; - using SupportedRinsesList = DataModel::List; static constexpr uint8_t kMaxSpinSpeedLength = 64; From 866b712043d8466dabcf8e0798feb0766ee0c8ac Mon Sep 17 00:00:00 2001 From: crlonxp <88241281+crlonxp@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:45:33 +0800 Subject: [PATCH 28/29] Update src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h Co-authored-by: Boris Zbarsky --- .../laundry-washer-controls-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 70666dc1340e1b..8c629855419c96 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -88,7 +88,7 @@ class LaundryWasherControlsServer : public AttributeAccessInterface * @param NumberOfRinses attribute NumberOfRinses * @return true on success, false on failure */ - EmberAfStatus GetNumberOfRinses(chip::EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses); + EmberAfStatus GetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses); private: CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; From 37036489ed802ba46752686a56024024676f2cf8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 22 Jul 2023 06:45:51 +0000 Subject: [PATCH 29/29] Restyled by clang-format --- .../laundry-washer-controls-server.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index 8c629855419c96..ac9b4ca0b7f209 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -36,7 +36,6 @@ class LaundryWasherControlsServer : public AttributeAccessInterface LaundryWasherControlsServer() : AttributeAccessInterface(Optional::Missing(), LaundryWasherControls::Id) {} static LaundryWasherControlsServer & Instance(); - static constexpr uint8_t kMaxSpinSpeedLength = 64; /**