From 0b538a7c7687380c3ebb193cda2c8d696d1bd2c7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 17 Nov 2023 11:04:27 +0000 Subject: [PATCH] Restyled by clang-format --- .../include/microwave-oven-delegates-impl.h | 33 +++++++--------- .../src/microwave-oven-delegates-impl.cpp | 38 +++++++++--------- .../microwave-oven-control-server.cpp | 27 ++++++------- .../microwave-oven-control-server.h | 39 ++++++++----------- 4 files changed, 61 insertions(+), 76 deletions(-) diff --git a/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-delegates-impl.h b/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-delegates-impl.h index 357bffd6ae5d72..c9d981c053b58d 100644 --- a/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-delegates-impl.h +++ b/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-delegates-impl.h @@ -29,40 +29,40 @@ namespace app { namespace Clusters { namespace MicrowaveOvenControl { -// This is an application level delegate to handle operational state and microwave oven control commands according to the specific business logic. -class MicrowaveOvenDelegates : public MicrowaveOvenControl::Delegate , public OperationalState::Delegate +// This is an application level delegate to handle operational state and microwave oven control commands according to the specific +// business logic. +class MicrowaveOvenDelegates : public MicrowaveOvenControl::Delegate, public OperationalState::Delegate { public: - - //Microwave Oven Control Cluster delegate + // Microwave Oven Control Cluster delegate /** * Handle Command Callback in application: set-cooking-parameters */ - Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode,uint32_t cookTime,uint8_t powerSetting) override; + Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, + uint8_t powerSetting) override; /** * Handle Command Callback in application: add-more-time */ - Protocols::InteractionModel::Status HandleAddMoreTimeCallback(uint32_t addedCookTime) override; + Protocols::InteractionModel::Status HandleAddMoreTimeCallback(uint32_t addedCookTime) override; /** * Get the value of MinPower. */ - uint8_t GetMinPower() const override {return mMinPower;} + uint8_t GetMinPower() const override { return mMinPower; } /** * Get the value of MaxPower. */ - uint8_t GetMaxPower() const override {return mMaxPower;} + uint8_t GetMaxPower() const override { return mMaxPower; } /** * Get the value of PowerStep. */ - uint8_t GetPowerStep() const override {return mPowerStep;} - + uint8_t GetPowerStep() const override { return mPowerStep; } - //Operational State Cluster delegate + // Operational State Cluster delegate /** * Get the countdown time. * @return The current countdown time. @@ -111,9 +111,7 @@ class MicrowaveOvenDelegates : public MicrowaveOvenControl::Delegate , public Op */ void HandleStopStateCallback(OperationalState::GenericOperationalError & err) override; - private: - const OperationalState::GenericOperationalState rvcOpStateList[4] = { OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)), OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)), @@ -121,21 +119,20 @@ class MicrowaveOvenDelegates : public MicrowaveOvenControl::Delegate , public Op OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)), }; - app::DataModel::List mOperationalStateList = Span(rvcOpStateList); + app::DataModel::List mOperationalStateList = + Span(rvcOpStateList); const OperationalState::GenericOperationalPhase opPhaseList[1] = { // Phase List is null OperationalState::GenericOperationalPhase(DataModel::Nullable()), }; - Span mOperationalPhaseList = Span(opPhaseList); - + Span mOperationalPhaseList = + Span(opPhaseList); }; void Shutdown(); - - } // namespace MicrowaveOvenControl } // namespace Clusters } // namespace app diff --git a/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-delegates-impl.cpp b/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-delegates-impl.cpp index d910b5bdb665ba..14030085b063f8 100644 --- a/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-delegates-impl.cpp +++ b/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-delegates-impl.cpp @@ -25,7 +25,6 @@ using namespace chip::app::Clusters::OperationalState; using OperationalStateEnum = chip::app::Clusters::OperationalState::OperationalStateEnum; using Status = Protocols::InteractionModel::Status; - namespace { OperationalState::Instance * gOperationalStateInstance = nullptr; @@ -34,14 +33,15 @@ MicrowaveOvenDelegates * gMicrowaveOvenDelegates = nullptr; } // anonymous namespace -//Operational State command callbacks +// Operational State command callbacks app::DataModel::Nullable MicrowaveOvenDelegates::GetCountdownTime() { VerifyOrDie(gMicrowaveOvenControlInstance != nullptr); return static_cast>(gMicrowaveOvenControlInstance->GetCookTime()); } -CHIP_ERROR MicrowaveOvenDelegates::GetOperationalStateAtIndex(size_t index, OperationalState::GenericOperationalState & operationalState) +CHIP_ERROR MicrowaveOvenDelegates::GetOperationalStateAtIndex(size_t index, + OperationalState::GenericOperationalState & operationalState) { if (index > mOperationalStateList.size() - 1) { @@ -51,7 +51,8 @@ CHIP_ERROR MicrowaveOvenDelegates::GetOperationalStateAtIndex(size_t index, Oper return CHIP_NO_ERROR; } -CHIP_ERROR MicrowaveOvenDelegates::GetOperationalPhaseAtIndex(size_t index, OperationalState::GenericOperationalPhase & operationalPhase) +CHIP_ERROR MicrowaveOvenDelegates::GetOperationalPhaseAtIndex(size_t index, + OperationalState::GenericOperationalPhase & operationalPhase) { if (index > mOperationalPhaseList.size() - 1) { @@ -121,9 +122,9 @@ void MicrowaveOvenDelegates::HandleStopStateCallback(OperationalState::GenericOp } } - -//Microwave Oven Control command callbacks -Protocols::InteractionModel::Status MicrowaveOvenDelegates::HandleSetCookingParametersCallback(uint8_t cookMode,uint32_t cookTime,uint8_t powerSetting) +// Microwave Oven Control command callbacks +Protocols::InteractionModel::Status MicrowaveOvenDelegates::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, + uint8_t powerSetting) { VerifyOrDie(gMicrowaveOvenControlInstance != nullptr); @@ -132,7 +133,6 @@ Protocols::InteractionModel::Status MicrowaveOvenDelegates::HandleSetCookingPara gMicrowaveOvenControlInstance->SetCookTime(cookTime); gMicrowaveOvenControlInstance->SetPowerSetting(powerSetting); return Status::Success; - } Protocols::InteractionModel::Status MicrowaveOvenDelegates::HandleAddMoreTimeCallback(uint32_t addedCookTime) @@ -143,7 +143,6 @@ Protocols::InteractionModel::Status MicrowaveOvenDelegates::HandleAddMoreTimeCal return Status::Success; } - void MicrowaveOvenControl::Shutdown() { if (gOperationalStateInstance != nullptr) @@ -164,23 +163,24 @@ void MicrowaveOvenControl::Shutdown() } } - void emberAfMicrowaveOvenControlClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. - VerifyOrDie(gOperationalStateInstance == nullptr && gMicrowaveOvenDelegates == nullptr && gMicrowaveOvenControlInstance == nullptr); - gMicrowaveOvenDelegates = new MicrowaveOvenDelegates; - EndpointId aEndpoint = 0x01; - gOperationalStateInstance = new OperationalState::Instance(gMicrowaveOvenDelegates, aEndpoint, Clusters::OperationalState::Id); - gMicrowaveOvenControlInstance = new MicrowaveOvenControl::Instance(gMicrowaveOvenDelegates, aEndpoint, Clusters::MicrowaveOvenControl::Id); - - //Initialize instance of Operational state cluster + VerifyOrDie(gOperationalStateInstance == nullptr && gMicrowaveOvenDelegates == nullptr && + gMicrowaveOvenControlInstance == nullptr); + gMicrowaveOvenDelegates = new MicrowaveOvenDelegates; + EndpointId aEndpoint = 0x01; + gOperationalStateInstance = new OperationalState::Instance(gMicrowaveOvenDelegates, aEndpoint, Clusters::OperationalState::Id); + gMicrowaveOvenControlInstance = + new MicrowaveOvenControl::Instance(gMicrowaveOvenDelegates, aEndpoint, Clusters::MicrowaveOvenControl::Id); + + // Initialize instance of Operational state cluster gOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); gOperationalStateInstance->Init(); - //Initialize instance of Microwave Oven Control cluster + // Initialize instance of Microwave Oven Control cluster MicrowaveOvenControl::SetOPInstance(aEndpoint, gOperationalStateInstance); gMicrowaveOvenControlInstance->Init(); } -void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId){} +void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId) {} diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp index 687485a93bc89f..14ddd584349af1 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include #include -#include using namespace chip; using namespace chip::app; @@ -29,7 +29,7 @@ using namespace chip::app::Clusters; using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::MicrowaveOvenControl; using namespace chip::app::Clusters::MicrowaveOvenControl::Attributes; -using Status = Protocols::InteractionModel::Status; +using Status = Protocols::InteractionModel::Status; namespace { @@ -91,7 +91,7 @@ uint8_t Instance::GetPowerSetting() const void Instance::SetCookTime(uint32_t cookTime) { - if(mCookTime != cookTime) + if (mCookTime != cookTime) { MatterReportingAttributeChangeCallback(ConcreteAttributePath(mEndpointId, mClusterId, Attributes::CookTime::Id)); } @@ -100,7 +100,7 @@ void Instance::SetCookTime(uint32_t cookTime) void Instance::SetPowerSetting(uint8_t powerSetting) { - if(mPowerSettng != powerSetting) + if (mPowerSettng != powerSetting) { MatterReportingAttributeChangeCallback(ConcreteAttributePath(mEndpointId, mClusterId, Attributes::PowerSetting::Id)); } @@ -136,12 +136,10 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu ReturnErrorOnFailure(aEncoder.Encode(mDelegate->GetPowerStep())); } break; - } return CHIP_NO_ERROR; } - void Instance::InvokeCommand(HandlerContext & handlerContext) { ChipLogDetail(Zcl, "MicrowaveOvenControl: InvokeCommand"); @@ -160,7 +158,6 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) CommandHandlerInterface::HandleCommand( handlerContext, [this](HandlerContext & ctx, const auto & req) { HandleAddMoreTime(ctx, req); }); break; - } } @@ -169,11 +166,11 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: ChipLogDetail(Zcl, "MicrowaveOvenControl: HandleSetCookingParameters"); Status status; uint8_t opState; - auto & CookMode = req.cookMode; - auto & CookTime = req.cookTime; - auto & PowerSetting = req.powerSetting; + auto & CookMode = req.cookMode; + auto & CookTime = req.cookTime; + auto & PowerSetting = req.powerSetting; - //TODO: check if the input cook mode value is invalid + // TODO: check if the input cook mode value is invalid if (CookTime.HasValue() && (!IsCookTimeInRange(CookTime.Value()))) { @@ -182,7 +179,8 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: goto exit; } - if (PowerSetting.HasValue() && (!IsPowerSettingInRange(PowerSetting.Value(), mDelegate->GetMinPower(), mDelegate->GetMaxPower()))) + if (PowerSetting.HasValue() && + (!IsPowerSettingInRange(PowerSetting.Value(), mDelegate->GetMinPower(), mDelegate->GetMaxPower()))) { status = Status::InvalidCommand; ChipLogError(Zcl, "Failed to set cookPower, cookPower value is out of range"); @@ -232,7 +230,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: // set Microwave Oven cooking power to max power(default). reqCookTime = mDelegate->GetMaxPower(); } - status = mDelegate->HandleSetCookingParametersCallback(reqCookMode,reqCookTime,reqPowerSetting); + status = mDelegate->HandleSetCookingParametersCallback(reqCookMode, reqCookTime, reqPowerSetting); goto exit; } else @@ -286,7 +284,6 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi goto exit; } - exit: ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } @@ -319,13 +316,11 @@ OperationalState::Instance * GetOPInstance(EndpointId aEndpoint) return (ep >= kMicrowaveOvenControlInstanceTableSize ? nullptr : gOPInstanceTable[aEndpoint]); } - } // namespace MicrowaveOvenControl } // namespace Clusters } // namespace app } // namespace chip - /** @brief Microwave Oven Control Cluster Server Init * * Server Init diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h index c14b2b6bf62f8c..0e4a1bda84f695 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h @@ -19,24 +19,24 @@ #pragma once #include -#include -#include #include #include #include +#include +#include namespace chip { namespace app { namespace Clusters { namespace MicrowaveOvenControl { -constexpr uint32_t kDefaultCookTime = 30; -constexpr uint8_t kDefaultPowerSetting = 100; -constexpr uint8_t kDefaultMinPower = 10; -constexpr uint8_t kDefaultMaxPower = 100; -constexpr uint8_t kDefaultPowerStep = 10; -constexpr uint32_t kMaxCookTime = 65535; -constexpr uint32_t kMinCookTime = 1; +constexpr uint32_t kDefaultCookTime = 30; +constexpr uint8_t kDefaultPowerSetting = 100; +constexpr uint8_t kDefaultMinPower = 10; +constexpr uint8_t kDefaultMaxPower = 100; +constexpr uint8_t kDefaultPowerStep = 10; +constexpr uint32_t kMaxCookTime = 65535; +constexpr uint32_t kMinCookTime = 1; class Delegate; @@ -72,18 +72,16 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface uint8_t GetPowerSetting() const; void SetPowerSetting(uint8_t powerSetting); - private: Delegate * mDelegate; EndpointId mEndpointId; ClusterId mClusterId; - /** * set default values */ - uint32_t mCookTime = kDefaultCookTime; - uint8_t mPowerSettng = kDefaultPowerSetting; + uint32_t mCookTime = kDefaultCookTime; + uint8_t mPowerSettng = kDefaultPowerSetting; /** * IM-level implementation of read @@ -107,7 +105,6 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface * This programme will also check if the added time is out of range. */ void HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTime::DecodableType & req); - }; /** @brief @@ -116,7 +113,6 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface class Delegate { public: - Delegate() = default; virtual ~Delegate() = default; @@ -125,7 +121,8 @@ class Delegate * @brief Handle Command Callback in application: SetCookingParameters * @return Returns the Interaction Model status code which was user determined in the business logic */ - virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode,uint32_t cookTime,uint8_t powerSetting) = 0; + virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, + uint8_t powerSetting) = 0; /** * @brief Handle Command Callback in application: AddMoreTime @@ -148,8 +145,6 @@ class Delegate */ virtual uint8_t GetPowerStep() const = 0; - - private: friend class Instance; @@ -167,9 +162,9 @@ class Delegate /** * set default values */ - uint8_t mMinPower = kDefaultMinPower; - uint8_t mMaxPower = kDefaultMaxPower; - uint8_t mPowerStep = kDefaultPowerStep; + uint8_t mMinPower = kDefaultMinPower; + uint8_t mMaxPower = kDefaultMaxPower; + uint8_t mPowerStep = kDefaultPowerStep; }; /** @@ -186,13 +181,11 @@ bool IsCookTimeInRange(uint32_t cookTime); */ bool IsPowerSettingInRange(uint8_t powerSetting, uint8_t minCookPower, uint8_t maxCookPower); - /** * @brief Set Operational State Cluster instance by endpoint id. */ void SetOPInstance(EndpointId aEndpoint, OperationalState::Instance * aInstance); - /** * @brief Get Operational State Cluster instance by endpoint id. */