diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index 43a7e2f2810c17..5680634c786678 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -86,7 +86,6 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/time-synchronization-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/dishwasher-alarm-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/laundry-washer-controls-server" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-state-oven-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/src" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/electrical-energy-measurement-server" ) diff --git a/src/app/clusters/operational-state-oven-server/operational-state-oven-cluster-objects.h b/src/app/clusters/operational-state-oven-server/operational-state-oven-cluster-objects.h deleted file mode 100644 index 1910e00d20effb..00000000000000 --- a/src/app/clusters/operational-state-oven-server/operational-state-oven-cluster-objects.h +++ /dev/null @@ -1,271 +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 -#include - -namespace chip { -namespace app { -namespace Clusters { -namespace OperationalState { - -inline constexpr size_t kOperationalStateLabelMaxSize = 64u; -inline constexpr size_t kOperationalErrorLabelMaxSize = 64u; -inline constexpr size_t kOperationalErrorDetailsMaxSize = 64u; -inline constexpr size_t kOperationalPhaseNameMaxSize = 64u; - -/** - * A class which represents the operational state of an Operational State cluster derivation instance. - */ -struct GenericOperationalState : public app::Clusters::detail::Structs::OperationalStateStruct::Type -{ - GenericOperationalState(uint8_t state = to_underlying(OperationalStateEnum::kStopped), Optional label = NullOptional) - { - Set(state, label); - } - - GenericOperationalState(const GenericOperationalState & op) { *this = op; } - - GenericOperationalState & operator=(const GenericOperationalState & op) - { - Set(op.operationalStateID, op.operationalStateLabel); - return *this; - } - - void Set(uint8_t state, Optional label = NullOptional) - { - operationalStateID = state; - if (label.HasValue()) - { - memset(mOperationalStateLabelBuffer, 0, sizeof(mOperationalStateLabelBuffer)); - if (label.Value().size() > sizeof(mOperationalStateLabelBuffer)) - { - memcpy(mOperationalStateLabelBuffer, label.Value().data(), sizeof(mOperationalStateLabelBuffer)); - operationalStateLabel.SetValue(CharSpan(mOperationalStateLabelBuffer, sizeof(mOperationalStateLabelBuffer))); - } - else - { - memcpy(mOperationalStateLabelBuffer, label.Value().data(), label.Value().size()); - operationalStateLabel.SetValue(CharSpan(mOperationalStateLabelBuffer, label.Value().size())); - } - } - else - { - operationalStateLabel = NullOptional; - } - } - -private: - char mOperationalStateLabelBuffer[kOperationalStateLabelMaxSize]; -}; - -/** - * A class which represents the operational error of an Operational State cluster derivation instance. - */ -struct GenericOperationalError : public app::Clusters::detail::Structs::ErrorStateStruct::Type -{ - GenericOperationalError(uint8_t state, Optional label = NullOptional, - Optional details = NullOptional) - { - Set(state, label, details); - } - - GenericOperationalError(const GenericOperationalError & error) { *this = error; } - - GenericOperationalError & operator=(const GenericOperationalError & error) - { - Set(error.errorStateID, error.errorStateLabel, error.errorStateDetails); - return *this; - } - - void Set(uint8_t state, Optional label = NullOptional, Optional details = NullOptional) - { - errorStateID = state; - if (label.HasValue()) - { - memset(mErrorStateLabelBuffer, 0, sizeof(mErrorStateLabelBuffer)); - if (label.Value().size() > sizeof(mErrorStateLabelBuffer)) - { - memcpy(mErrorStateLabelBuffer, label.Value().data(), sizeof(mErrorStateLabelBuffer)); - errorStateLabel.SetValue(CharSpan(mErrorStateLabelBuffer, sizeof(mErrorStateLabelBuffer))); - } - else - { - memcpy(mErrorStateLabelBuffer, label.Value().data(), label.Value().size()); - errorStateLabel.SetValue(CharSpan(mErrorStateLabelBuffer, label.Value().size())); - } - } - else - { - errorStateLabel = NullOptional; - } - - if (details.HasValue()) - { - memset(mErrorStateDetailsBuffer, 0, sizeof(mErrorStateDetailsBuffer)); - if (details.Value().size() > sizeof(mErrorStateDetailsBuffer)) - { - memcpy(mErrorStateDetailsBuffer, details.Value().data(), sizeof(mErrorStateDetailsBuffer)); - errorStateDetails.SetValue(CharSpan(mErrorStateDetailsBuffer, sizeof(mErrorStateDetailsBuffer))); - } - else - { - memcpy(mErrorStateDetailsBuffer, details.Value().data(), details.Value().size()); - errorStateDetails.SetValue(CharSpan(mErrorStateDetailsBuffer, details.Value().size())); - } - } - else - { - errorStateDetails = NullOptional; - } - } - - bool IsEqual(const Structs::ErrorStateStruct::Type & rhs) const - { - if (errorStateID != rhs.errorStateID) - { - return false; - } - if (errorStateLabel.HasValue() != rhs.errorStateLabel.HasValue() || - errorStateDetails.HasValue() != rhs.errorStateDetails.HasValue()) - { - return false; - } - if (errorStateLabel.HasValue()) - { - if (!errorStateLabel.Value().data_equal(rhs.errorStateLabel.Value())) - { - return false; - } - } - if (errorStateDetails.HasValue()) - { - if (!errorStateDetails.Value().data_equal(rhs.errorStateDetails.Value())) - { - return false; - } - } - - return true; - } - -private: - char mErrorStateLabelBuffer[kOperationalErrorLabelMaxSize]; - char mErrorStateDetailsBuffer[kOperationalErrorDetailsMaxSize]; -}; - -/** - * A class which represents the operational phase of an Operational State cluster derivation instance. - */ -struct GenericOperationalPhase -{ - GenericOperationalPhase(app::DataModel::Nullable name) { Set(name); } - - GenericOperationalPhase(const GenericOperationalPhase & ph) { *this = ph; } - - GenericOperationalPhase & operator=(const GenericOperationalPhase & ph) - { - Set(ph.mPhaseName); - return *this; - } - - bool IsMissing() const { return mPhaseName.IsNull(); } - app::DataModel::Nullable mPhaseName; - -private: - void Set(app::DataModel::Nullable name) - { - if (name.IsNull()) - { - mPhaseName.SetNull(); - } - else - { - memset(mPhaseNameBuffer, 0, sizeof(mPhaseNameBuffer)); - if (name.Value().size() > sizeof(mPhaseNameBuffer)) - { - memcpy(mPhaseNameBuffer, name.Value().data(), sizeof(mPhaseNameBuffer)); - mPhaseName = app::DataModel::Nullable(CharSpan(mPhaseNameBuffer, sizeof(mPhaseNameBuffer))); - } - else - { - memcpy(mPhaseNameBuffer, name.Value().data(), name.Value().size()); - mPhaseName = app::DataModel::Nullable(CharSpan(mPhaseNameBuffer, name.Value().size())); - } - } - } - - char mPhaseNameBuffer[kOperationalPhaseNameMaxSize]; -}; - -/** - * A class which represents the operational error event of an Operational State cluster derivation instance. - */ -class GenericErrorEvent : private app::Clusters::OperationalState::Events::OperationalError::Type -{ - using super = app::Clusters::OperationalState::Events::OperationalError::Type; - -public: - GenericErrorEvent(ClusterId aClusterId, const Structs::ErrorStateStruct::Type & aError) : mClusterId(aClusterId) - { - errorState = aError; - } - using super::GetEventId; - using super::GetPriorityLevel; - ClusterId GetClusterId() const { return mClusterId; } - using super::Encode; - using super::kIsFabricScoped; - -private: - ClusterId mClusterId; -}; - -/** - * A class which represents the operational completion event of an Operational State cluster derivation instance. - */ -class GenericOperationCompletionEvent : private app::Clusters::OperationalState::Events::OperationCompletion::Type -{ - using super = app::Clusters::OperationalState::Events::OperationCompletion::Type; - -public: - GenericOperationCompletionEvent(ClusterId aClusterId, uint8_t aCompletionErrorCode, - const Optional> & aTotalOperationalTime = NullOptional, - const Optional> & aPausedTime = NullOptional) : - mClusterId(aClusterId) - { - completionErrorCode = aCompletionErrorCode; - totalOperationalTime = aTotalOperationalTime; - pausedTime = aPausedTime; - } - using super::GetEventId; - using super::GetPriorityLevel; - ClusterId GetClusterId() const { return mClusterId; } - using super::Encode; - using super::kIsFabricScoped; - -private: - ClusterId mClusterId; -}; - -} // namespace OperationalState -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/src/app/clusters/operational-state-oven-server/operational-state-oven-server.cpp b/src/app/clusters/operational-state-oven-server/operational-state-oven-server.cpp deleted file mode 100644 index 3c4809401b8db3..00000000000000 --- a/src/app/clusters/operational-state-oven-server/operational-state-oven-server.cpp +++ /dev/null @@ -1,411 +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. - */ - -/**************************************************************************** - * @file - * @brief Implementation for the Operational State Server Cluster - ***************************************************************************/ -#include "operational-state-oven-server.h" -#include -#include -#include -#include -#include -#include - -using namespace chip; -using namespace chip::app; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::OperationalState; -using namespace chip::app::Clusters::OperationalState::Attributes; - -using Status = Protocols::InteractionModel::Status; - -Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId) : - CommandHandlerInterface(MakeOptional(aEndpointId), aClusterId), AttributeAccessInterface(MakeOptional(aEndpointId), aClusterId), - mDelegate(aDelegate), mEndpointId(aEndpointId), mClusterId(aClusterId) -{ - mDelegate->SetInstance(this); -} - -Instance::~Instance() -{ - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); - unregisterAttributeAccessOverride(this); -} - -CHIP_ERROR Instance::Init() -{ - // Check if the cluster has been selected in zap - if (!emberAfContainsServer(mEndpointId, mClusterId)) - { - ChipLogError(Zcl, "Operational State: The cluster with ID %lu was not enabled in zap.", long(mClusterId)); - return CHIP_ERROR_INVALID_ARGUMENT; - } - - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); - - VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR Instance::SetCurrentPhase(const DataModel::Nullable & aPhase) -{ - if (!aPhase.IsNull()) - { - if (!IsSupportedPhase(aPhase.Value())) - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - } - - DataModel::Nullable oldPhase = mCurrentPhase; - mCurrentPhase = aPhase; - if (mCurrentPhase != oldPhase) - { - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::CurrentPhase::Id); - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR Instance::SetOperationalState(uint8_t aOpState) -{ - // Error is only allowed to be set by OnOperationalErrorDetected. - if (aOpState == to_underlying(OperationalStateEnum::kError) || !IsSupportedOperationalState(aOpState)) - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - - if (mOperationalError.errorStateID != to_underlying(ErrorStateEnum::kNoError)) - { - mOperationalError.Set(to_underlying(ErrorStateEnum::kNoError)); - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::OperationalError::Id); - } - - uint8_t oldState = mOperationalState; - mOperationalState = aOpState; - if (mOperationalState != oldState) - { - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::OperationalState::Id); - } - return CHIP_NO_ERROR; -} - -DataModel::Nullable Instance::GetCurrentPhase() const -{ - return mCurrentPhase; -} - -uint8_t Instance::GetCurrentOperationalState() const -{ - return mOperationalState; -} - -void Instance::GetCurrentOperationalError(GenericOperationalError & error) const -{ - error.Set(mOperationalError.errorStateID, mOperationalError.errorStateLabel, mOperationalError.errorStateDetails); -} - -void Instance::OnOperationalErrorDetected(const Structs::ErrorStateStruct::Type & aError) -{ - ChipLogDetail(Zcl, "OperationalStateServer: OnOperationalErrorDetected"); - // Set the OperationalState attribute to Error - if (mOperationalState != to_underlying(OperationalStateEnum::kError)) - { - mOperationalState = to_underlying(OperationalStateEnum::kError); - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::OperationalState::Id); - } - - // Set the OperationalError attribute - if (!mOperationalError.IsEqual(aError)) - { - mOperationalError.Set(aError.errorStateID, aError.errorStateLabel, aError.errorStateDetails); - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::OperationalError::Id); - } - - // Generate an ErrorDetected event - GenericErrorEvent event(mClusterId, aError); - EventNumber eventNumber; - CHIP_ERROR error = LogEvent(event, mEndpointId, eventNumber); - - if (error != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationalError event: %" CHIP_ERROR_FORMAT, error.Format()); - } -} - -void Instance::OnOperationCompletionDetected(uint8_t aCompletionErrorCode, - const Optional> & aTotalOperationalTime, - const Optional> & aPausedTime) const -{ - ChipLogDetail(Zcl, "OperationalStateServer: OnOperationCompletionDetected"); - - GenericOperationCompletionEvent event(mClusterId, aCompletionErrorCode, aTotalOperationalTime, aPausedTime); - EventNumber eventNumber; - CHIP_ERROR error = LogEvent(event, mEndpointId, eventNumber); - - if (error != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationCompletion event: %" CHIP_ERROR_FORMAT, - error.Format()); - } -} - -void Instance::ReportOperationalStateListChange() -{ - MatterReportingAttributeChangeCallback(ConcreteAttributePath(mEndpointId, mClusterId, Attributes::OperationalStateList::Id)); -} - -void Instance::ReportPhaseListChange() -{ - MatterReportingAttributeChangeCallback(ConcreteAttributePath(mEndpointId, mClusterId, Attributes::PhaseList::Id)); -} - -bool Instance::IsSupportedPhase(uint8_t aPhase) -{ - GenericOperationalPhase phase = GenericOperationalPhase(DataModel::Nullable()); - if (mDelegate->GetOperationalPhaseAtIndex(aPhase, phase) != CHIP_ERROR_NOT_FOUND) - { - return true; - } - return false; -} - -bool Instance::IsSupportedOperationalState(uint8_t aState) -{ - GenericOperationalState opState; - for (uint8_t i = 0; mDelegate->GetOperationalStateAtIndex(i, opState) != CHIP_ERROR_NOT_FOUND; i++) - { - if (opState.operationalStateID == aState) - { - return true; - } - } - ChipLogDetail(Zcl, "Cannot find an operational state with value %u", aState); - return false; -} - -// private - -template -void Instance::HandleCommand(HandlerContext & handlerContext, FuncT func) -{ - if (!handlerContext.mCommandHandled && (handlerContext.mRequestPath.mCommandId == RequestT::GetCommandId())) - { - RequestT requestPayload; - - // If the command matches what the caller is looking for, let's mark this as being handled - // even if errors happen after this. This ensures that we don't execute any fall-back strategies - // to handle this command since at this point, the caller is taking responsibility for handling - // the command in its entirety, warts and all. - // - handlerContext.SetCommandHandled(); - - if (DataModel::Decode(handlerContext.mPayload, requestPayload) != CHIP_NO_ERROR) - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, - Protocols::InteractionModel::Status::InvalidCommand); - return; - } - - func(handlerContext, requestPayload); - } -} - -// This function is called by the interaction model engine when a command destined for this instance is received. -void Instance::InvokeCommand(HandlerContext & handlerContext) -{ - ChipLogDetail(Zcl, "OperationalState: InvokeCommand"); - switch (handlerContext.mRequestPath.mCommandId) - { - case Commands::Pause::Id: - ChipLogDetail(Zcl, "OperationalState: Entering handling Pause state"); - - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & req) { HandlePauseState(ctx, req); }); - break; - - case Commands::Resume::Id: - ChipLogDetail(Zcl, "OperationalState: Entering handling Resume state"); - - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & req) { HandleResumeState(ctx, req); }); - break; - - case Commands::Start::Id: - ChipLogDetail(Zcl, "OperationalState: Entering handling Start state"); - - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & req) { HandleStartState(ctx, req); }); - break; - - case Commands::Stop::Id: - ChipLogDetail(Zcl, "OperationalState: Entering handling Stop state"); - - HandleCommand(handlerContext, - [this](HandlerContext & ctx, const auto & req) { HandleStopState(ctx, req); }); - break; - } -} - -CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) -{ - ChipLogError(Zcl, "OperationalState: Reading"); - switch (aPath.mAttributeId) - { - case OperationalState::Attributes::OperationalStateList::Id: { - return aEncoder.EncodeList([delegate = mDelegate](const auto & encoder) -> CHIP_ERROR { - GenericOperationalState opState; - size_t index = 0; - CHIP_ERROR err = CHIP_NO_ERROR; - while ((err = delegate->GetOperationalStateAtIndex(index, opState)) == CHIP_NO_ERROR) - { - ReturnErrorOnFailure(encoder.Encode(opState)); - index++; - } - if (err == CHIP_ERROR_NOT_FOUND) - { - return CHIP_NO_ERROR; - } - return err; - }); - } - break; - - case OperationalState::Attributes::OperationalState::Id: { - ChipLogError(Zcl, "OperationalState: H1"); - ReturnErrorOnFailure(aEncoder.Encode(GetCurrentOperationalState())); - } - break; - - case OperationalState::Attributes::OperationalError::Id: { - ReturnErrorOnFailure(aEncoder.Encode(mOperationalError)); - } - break; - - case OperationalState::Attributes::PhaseList::Id: { - GenericOperationalPhase phase = GenericOperationalPhase(DataModel::Nullable()); - size_t index = 0; - - if (mDelegate->GetOperationalPhaseAtIndex(index, phase) == CHIP_ERROR_NOT_FOUND || phase.IsMissing()) - { - return aEncoder.EncodeNull(); - } - return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - while (this->mDelegate->GetOperationalPhaseAtIndex(index, phase) != CHIP_ERROR_NOT_FOUND) - { - ReturnErrorOnFailure(encoder.Encode(phase.mPhaseName)); - index++; - } - return CHIP_NO_ERROR; - }); - } - break; - - case OperationalState::Attributes::CurrentPhase::Id: { - ReturnErrorOnFailure(aEncoder.Encode(GetCurrentPhase())); - } - break; - - case OperationalState::Attributes::CountdownTime::Id: { - ReturnErrorOnFailure(aEncoder.Encode(mDelegate->GetCountdownTime())); - } - break; - } - return CHIP_NO_ERROR; -} - -void Instance::HandlePauseState(HandlerContext & ctx, const Commands::Pause::DecodableType & req) -{ - ChipLogDetail(Zcl, "OperationalState: HandlePauseState"); - - GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); - uint8_t opState = GetCurrentOperationalState(); - - if (opState != to_underlying(OperationalStateEnum::kPaused) && opState != to_underlying(OperationalStateEnum::kRunning)) - { - err.Set(to_underlying(ErrorStateEnum::kCommandInvalidInState)); - } - else if (opState == to_underlying(OperationalStateEnum::kRunning)) - { - mDelegate->HandlePauseStateCallback(err); - } - - Commands::OperationalCommandResponse::Type response; - response.commandResponseState = err; - - ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); -} - -void Instance::HandleStopState(HandlerContext & ctx, const Commands::Stop::DecodableType & req) -{ - ChipLogDetail(Zcl, "OperationalState: HandleStopState"); - - GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); - uint8_t opState = GetCurrentOperationalState(); - - if (opState != to_underlying(OperationalStateEnum::kStopped)) - { - mDelegate->HandleStopStateCallback(err); - } - - Commands::OperationalCommandResponse::Type response; - response.commandResponseState = err; - - ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); -} - -void Instance::HandleStartState(HandlerContext & ctx, const Commands::Start::DecodableType & req) -{ - ChipLogDetail(Zcl, "OperationalState: HandleStartState"); - - GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); - uint8_t opState = GetCurrentOperationalState(); - - if (opState != to_underlying(OperationalStateEnum::kRunning)) - { - mDelegate->HandleStartStateCallback(err); - } - - Commands::OperationalCommandResponse::Type response; - response.commandResponseState = err; - - ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); -} - -void Instance::HandleResumeState(HandlerContext & ctx, const Commands::Resume::DecodableType & req) -{ - ChipLogDetail(Zcl, "OperationalState: HandleResumeState"); - - GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); - uint8_t opState = GetCurrentOperationalState(); - - if (opState != to_underlying(OperationalStateEnum::kPaused) && opState != to_underlying(OperationalStateEnum::kRunning)) - { - err.Set(to_underlying(ErrorStateEnum::kCommandInvalidInState)); - } - else if (opState == to_underlying(OperationalStateEnum::kPaused)) - { - mDelegate->HandleResumeStateCallback(err); - } - - Commands::OperationalCommandResponse::Type response; - response.commandResponseState = err; - - ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); -} diff --git a/src/app/clusters/operational-state-oven-server/operational-state-oven-server.h b/src/app/clusters/operational-state-oven-server/operational-state-oven-server.h deleted file mode 100644 index 23ebba36817d22..00000000000000 --- a/src/app/clusters/operational-state-oven-server/operational-state-oven-server.h +++ /dev/null @@ -1,280 +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 "operational-state-oven-cluster-objects.h" -#include -#include -#include -#include - -namespace chip { -namespace app { -namespace Clusters { -namespace OperationalState { - -class Uncopyable -{ -protected: - Uncopyable() {} - ~Uncopyable() = default; - -private: - Uncopyable(const Uncopyable &) = delete; - Uncopyable & operator=(const Uncopyable &) = delete; -}; - -class Delegate; - -/** - * Instance is a class that represents an instance of a derivation of the operational state cluster. - * It implements CommandHandlerInterface so it can generically handle commands for any derivation cluster id. - */ -class Instance : public CommandHandlerInterface, public AttributeAccessInterface, public Uncopyable -{ -public: - /** - * Creates an operational state cluster instance. The Init() function needs to be called for this instance - * to be registered and called by the interaction model at the appropriate times. - * It is possible to set the CurrentPhase and OperationalState via the Set... methods before calling Init(). - * @param aDelegate A pointer to the delegate to be used by this server. - * Note: the caller must ensure that the delegate lives throughout the instance's lifetime. - * @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. - * @param aClusterId The ID of the operational state derived cluster to be instantiated. - */ - Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId); - - ~Instance() override; - - /** - * Initialise the operational state server instance. - * This function must be called after defining an Instance class object. - * @return Returns an error if the given endpoint and cluster ID have not been enabled in zap or if the - * CommandHandler or AttributeHandler registration fails, else returns CHIP_NO_ERROR. - */ - CHIP_ERROR Init(); - - // Attribute setters - /** - * Set operational phase. - * @param aPhase The operational phase that should now be the current one. - * @return CHIP_ERROR_INVALID_ARGUMENT if aPhase is an invalid value. CHIP_NO_ERROR if set was successful. - */ - CHIP_ERROR SetCurrentPhase(const app::DataModel::Nullable & aPhase); - - /** - * Set current operational state to aOpState and the operational error to kNoError. - * NOTE: This method cannot be used to set the error state. The error state must be set via the - * OnOperationalErrorDetected method. - * @param aOpState The operational state that should now be the current one. - * @return CHIP_ERROR_INVALID_ARGUMENT if aOpState is an invalid value. CHIP_NO_ERROR if set was successful. - */ - CHIP_ERROR SetOperationalState(uint8_t aOpState); - - // Attribute getters - /** - * Get current phase. - * @return The current phase. - */ - app::DataModel::Nullable GetCurrentPhase() const; - - /** - * Get the current operational state. - * @return The current operational state value. - */ - uint8_t GetCurrentOperationalState() const; - - /** - * Get current operational error. - * @param error The GenericOperationalError to fill with the current operational error value - */ - void GetCurrentOperationalError(GenericOperationalError & error) const; - - // Event triggers - /** - * @brief Called when the Node detects a OperationalError has been raised. - * Note: This function also sets the OperationalState attribute to Error. - * @param aError OperationalError which detects - */ - void OnOperationalErrorDetected(const Structs::ErrorStateStruct::Type & aError); - - /** - * @brief Called when the Node detects a OperationCompletion has been raised. - * @param aCompletionErrorCode CompletionErrorCode - * @param aTotalOperationalTime TotalOperationalTime - * @param aPausedTime PausedTime - */ - void OnOperationCompletionDetected(uint8_t aCompletionErrorCode, - const Optional> & aTotalOperationalTime = NullOptional, - const Optional> & aPausedTime = NullOptional) const; - - // List change reporting - /** - * Reports that the contents of the operational state list has changed. - * The device SHALL call this method whenever it changes the operational state list. - */ - void ReportOperationalStateListChange(); - - /** - * Reports that the contents of the phase list has changed. - * The device SHALL call this method whenever it changes the phase list. - */ - void ReportPhaseListChange(); - - /** - * This function returns true if the phase value given exists in the PhaseList attribute, otherwise it returns false. - */ - bool IsSupportedPhase(uint8_t aPhase); - - /** - * This function returns true if the operational state value given exists in the OperationalStateList attribute, - * otherwise it returns false. - */ - bool IsSupportedOperationalState(uint8_t aState); - -private: - Delegate * mDelegate; - - EndpointId mEndpointId; - ClusterId mClusterId; - - // Attribute Data Store - app::DataModel::Nullable mCurrentPhase; - uint8_t mOperationalState = 0; // assume 0 for now. - GenericOperationalError mOperationalError = to_underlying(ErrorStateEnum::kNoError); - - // Inherited from CommandHandlerInterface - template - void HandleCommand(HandlerContext & handlerContext, FuncT func); - - // Inherited from CommandHandlerInterface - void InvokeCommand(HandlerContext & ctx) override; - - /** - * IM-level implementation of read - * @return appropriately mapped CHIP_ERROR if applicable (may return CHIP_IM_GLOBAL_STATUS errors) - */ - CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - - /** - * Handle Command: Pause. - */ - void HandlePauseState(HandlerContext & ctx, const Commands::Pause::DecodableType & req); - - /** - * Handle Command: Stop. - */ - void HandleStopState(HandlerContext & ctx, const Commands::Stop::DecodableType & req); - - /** - * Handle Command: Start. - */ - void HandleStartState(HandlerContext & ctx, const Commands::Start::DecodableType & req); - - /** - * Handle Command: Resume. - */ - void HandleResumeState(HandlerContext & ctx, const Commands::Resume::DecodableType & req); -}; - -/** - * A delegate to handle application logic of the Operational State aliased Cluster. - * The delegate API assumes there will be separate delegate objects for each cluster instance. - * (i.e. each separate operational state cluster derivation, on each separate endpoint), - * since the delegate methods are not handed the cluster id or endpoint. - */ -class Delegate -{ -public: - Delegate() = default; - - virtual ~Delegate() = default; - - /** - * Get the countdown time. - * NOTE: Changes to this attribute should not be reported. - * From the spec: Changes to this value SHALL NOT be reported in a subscription. - * @return The current countdown time. - */ - virtual app::DataModel::Nullable GetCountdownTime() = 0; - - /** - * Fills in the provided GenericOperationalState with the state at index `index` if there is one, - * or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of states. - * Note: This is used by the SDK to populate the operational state list attribute. If the contents of this list changes, - * the device SHALL call the Instance's ReportOperationalStateListChange method to report that this attribute has changed. - * @param index The index of the state, with 0 representing the first state. - * @param operationalState The GenericOperationalState is filled. - */ - virtual CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) = 0; - - /** - * Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one, - * or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases. - * Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the - * device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed. - * @param index The index of the phase, with 0 representing the first phase. - * @param operationalPhase The GenericOperationalPhase is filled. - */ - virtual CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) = 0; - - // command callback - /** - * Handle Command Callback in application: Pause - * @param[out] err operational error after callback. - */ - virtual void HandlePauseStateCallback(GenericOperationalError & err) = 0; - - /** - * Handle Command Callback in application: Resume - * @param[out] err operational error after callback. - */ - virtual void HandleResumeStateCallback(GenericOperationalError & err) = 0; - - /** - * Handle Command Callback in application: Start - * @param[out] err operational error after callback. - */ - virtual void HandleStartStateCallback(GenericOperationalError & err) = 0; - - /** - * Handle Command Callback in application: Stop - * @param[out] err operational error after callback. - */ - virtual void HandleStopStateCallback(GenericOperationalError & err) = 0; - -private: - friend class Instance; - - Instance * mInstance = nullptr; - - /** - * This method is used by the SDK to set the instance pointer. This is done during the instantiation of a Instance object. - * @param aInstance A pointer to the Instance object related to this delegate object. - */ - void SetInstance(Instance * aInstance) { mInstance = aInstance; } - -protected: - Instance * GetInstance() const { return mInstance; } -}; - -} // namespace OperationalState -} // namespace Clusters -} // namespace app -} // namespace chip