Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and liangpy4 committed Nov 17, 2023
1 parent 84d5352 commit 0b538a7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -111,31 +111,28 @@ 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)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
};

app::DataModel::List<const OperationalState::GenericOperationalState> mOperationalStateList = Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
app::DataModel::List<const OperationalState::GenericOperationalState> mOperationalStateList =
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);

const OperationalState::GenericOperationalPhase opPhaseList[1] = {
// Phase List is null
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
};

Span<const OperationalState::GenericOperationalPhase> mOperationalPhaseList = Span<const OperationalState::GenericOperationalPhase>(opPhaseList);

Span<const OperationalState::GenericOperationalPhase> mOperationalPhaseList =
Span<const OperationalState::GenericOperationalPhase>(opPhaseList);
};

void Shutdown();



} // namespace MicrowaveOvenControl
} // namespace Clusters
} // namespace app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,14 +33,15 @@ MicrowaveOvenDelegates * gMicrowaveOvenDelegates = nullptr;

} // anonymous namespace

//Operational State command callbacks
// Operational State command callbacks
app::DataModel::Nullable<uint32_t> MicrowaveOvenDelegates::GetCountdownTime()
{
VerifyOrDie(gMicrowaveOvenControlInstance != nullptr);
return static_cast<app::DataModel::Nullable<uint32_t>>(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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand All @@ -143,7 +143,6 @@ Protocols::InteractionModel::Status MicrowaveOvenDelegates::HandleAddMoreTimeCal
return Status::Success;
}


void MicrowaveOvenControl::Shutdown()
{
if (gOperationalStateInstance != nullptr)
Expand All @@ -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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/InteractionModelEngine.h>
#include <app/clusters/microwave-oven-control-server/microwave-oven-control-server.h>
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>
#include <app/util/error-mapping.h>
#include <app/reporting/reporting.h>

using namespace chip;
using namespace chip::app;
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 {

Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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");
Expand All @@ -160,7 +158,6 @@ void Instance::InvokeCommand(HandlerContext & handlerContext)
CommandHandlerInterface::HandleCommand<Commands::AddMoreTime::DecodableType>(
handlerContext, [this](HandlerContext & ctx, const auto & req) { HandleAddMoreTime(ctx, req); });
break;

}
}

Expand All @@ -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())))
{
Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -286,7 +284,6 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi
goto exit;
}


exit:
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status);
}
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0b538a7

Please sign in to comment.