Skip to content

Commit

Permalink
Refactored the OperationalState server code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hicklin committed Aug 3, 2023
1 parent 3bfcbc5 commit 16608a9
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 275 deletions.
2 changes: 1 addition & 1 deletion src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ template("chip_data_model") {
sources += [
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/${cluster}.h",
"${_app_root}/clusters/${cluster}/operational-state-delegate.h",
"${_app_root}/clusters/${cluster}/operational-state-cluster-objects.h",
]
} else if (cluster == "dishwasher-alarm-server") {
sources += [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,118 +188,54 @@ struct GenericOperationalPhase
};

/**
* 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.
* A class which represents the operational error event of an Operational State cluster derivation instance.
*/
class Delegate
class GenericErrorEvent : private app::Clusters::OperationalState::Events::OperationalError::Type
{
public:
/**
* Get the current operational state.
* @return The current operational state value
*/
virtual uint8_t GetCurrentOperationalState() = 0;

/**
* Get the list of supported operational states.
* 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.
* @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;

/**
* Get the list of supported operational phases.
* 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.
* @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;

/**
* Get current operational error.
* @param error The GenericOperationalError to fill with the current operational error value
*/
virtual void GetCurrentOperationalError(GenericOperationalError & error) = 0;

/**
* Get current phase
* @param phase The app::DataModel::Nullable<uint8_t> to fill with the current phase value
*/
virtual void GetCurrentPhase(app::DataModel::Nullable<uint8_t> & phase) = 0;

/**
* Get countdown time
* @param time The app::DataModel::Nullable<uint32_t> to fill with the coutdown time value
*/
virtual void GetCountdownTime(app::DataModel::Nullable<uint32_t> & time) = 0;
using super = app::Clusters::OperationalState::Events::OperationalError::Type;

/**
* Set current operational state.
* @param opState The operational state that should now be the current one.
*/
virtual CHIP_ERROR SetOperationalState(uint8_t opState) = 0;

/**
* Set operational error.
* @param opErrState The new operational error.
*/
virtual CHIP_ERROR SetOperationalError(const GenericOperationalError & opErrState) = 0;

/**
* Set operational phase.
* @param phase The operational phase that should now be the current one.
*/
virtual CHIP_ERROR SetPhase(const app::DataModel::Nullable<uint8_t> & phase) = 0;

/**
* Set coutdown time.
* @param time The coutdown time that should now be the current one.
*/
virtual CHIP_ERROR SetCountdownTime(const app::DataModel::Nullable<uint32_t> & time) = 0;

// command callback
/**
* Handle Command Callback in application: Pause
* @param[out] get operational error after callback.
*/
virtual void HandlePauseStateCallback(GenericOperationalError & err) = 0;

/**
* Handle Command Callback in application: Resume
* @param[out] get operational error after callback.
*/
virtual void HandleResumeStateCallback(GenericOperationalError & err) = 0;
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;

/**
* Handle Command Callback in application: Start
* @param[out] get operational error after callback.
*/
virtual void HandleStartStateCallback(GenericOperationalError & err) = 0;
private:
ClusterId mClusterId;
};

/**
* Handle Command Callback in application: Stop
* @param[out] get operational error after callback.
*/
virtual void HandleStopStateCallback(GenericOperationalError & err) = 0;
/**
* 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;

Delegate() = default;
public:
GenericOperationCompletionEvent(ClusterId aClusterId, uint8_t aCompletionErrorCode,
const Optional<DataModel::Nullable<uint32_t>> & aTotalOperationalTime = NullOptional,
const Optional<DataModel::Nullable<uint32_t>> & 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;

virtual ~Delegate() = default;
private:
ClusterId mClusterId;
};

// @brief Instance getter for the delegate for the given operational state alias cluster on the given endpoint.
// 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)
// @note This API should always be called prior to using the delegate and the return pointer should never be cached.
// This should be implemented by the application.
// @return Default global delegate instance.
Delegate * GetOperationalStateDelegate(EndpointId endpointId, ClusterId clusterId);

} // namespace OperationalState
} // namespace Clusters
} // namespace app
Expand Down
Loading

0 comments on commit 16608a9

Please sign in to comment.