Skip to content

Commit

Permalink
[OPSTATE] Add OperationalError Event and OperationCompletion Event api (
Browse files Browse the repository at this point in the history
#27990)

* Add OperationalError event api for operational state cluster

* fix build error

* Add OperationCompletion event api for operational state cluster

* fix build error

* save the zap for all-clusters-app.zap

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Sep 13, 2023
1 parent adebb09 commit 6855476
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#include <app/CommandHandler.h>
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/EventLogging.h>
#include <app/EventLoggingDelegate.h>
#include <app/InteractionModelEngine.h>
#include <app/reporting/reporting.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <app/util/error-mapping.h>
Expand Down Expand Up @@ -294,3 +297,45 @@ CHIP_ERROR OperationalStateServer::Read(const ConcreteReadAttributePath & aPath,
}
return CHIP_NO_ERROR;
}

void OperationalStateServer::OnOperationalErrorDetect(const Structs::ErrorStateStruct::Type & aError)
{
ChipLogDetail(Zcl, "OperationalStateServer: OnOperationalErrorDetect");
MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, OperationalState::Attributes::OperationalState::Id);

EventNumber eventNumber;
Events::OperationalError::Type event{ aError };
EventLogger<Events::OperationalError::Type> eventData(event);
ConcreteEventPath path(mEndpointId, mClusterId, event.GetEventId());
EventManagement & logMgmt = chip::app::EventManagement::GetInstance();
EventOptions eventOptions;
eventOptions.mPath = path;
eventOptions.mPriority = event.GetPriorityLevel();

CHIP_ERROR err = logMgmt.LogEvent(&eventData, eventOptions, eventNumber);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationalError event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void OperationalStateServer::OnOperationCompletionDetect(const Events::OperationCompletion::Type & aEvent)
{
ChipLogDetail(Zcl, "OperationalStateServer: OnOperationCompletionDetect");
MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, OperationalState::Attributes::OperationalState::Id);

EventNumber eventNumber;
EventLogger<Events::OperationCompletion::Type> eventData(aEvent);
ConcreteEventPath path(mEndpointId, mClusterId, aEvent.GetEventId());
EventManagement & logMgmt = chip::app::EventManagement::GetInstance();
EventOptions eventOptions;
eventOptions.mPath = path;
eventOptions.mPriority = aEvent.GetPriorityLevel();

CHIP_ERROR err = logMgmt.LogEvent(&eventData, eventOptions, eventNumber);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "OperationalStateServer: Failed to record OnOperationCompletionDetect event: %" CHIP_ERROR_FORMAT,
err.Format());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,23 @@ class OperationalStateServer : public CommandHandlerInterface, public AttributeA
*/
void Shutdown();

/**
* @brief Called when the Node detects a OperationalError has been raised.
* @param aError OperationalError which detects
*/
void OnOperationalErrorDetect(const Structs::ErrorStateStruct::Type & aError);

/**
* @brief Called when the Node detects a OperationCompletion has been raised.
* @param aEvent OperationCompletion event
*/
void OnOperationCompletionDetect(const Events::OperationCompletion::Type & aEvent);

/**
* 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.
* @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration.
* @param aClusterId The ID of the ModeSelect aliased cluster to be instantiated.
* @param aClusterId The ID of the operational state aliased cluster to be instantiated.
*/
OperationalStateServer(EndpointId aEndpointId, ClusterId aClusterId) :
CommandHandlerInterface(MakeOptional(aEndpointId), aClusterId),
Expand Down Expand Up @@ -113,7 +125,6 @@ class OperationalStateServer : public CommandHandlerInterface, public AttributeA
EndpointId mEndpointId;
ClusterId mClusterId;
};

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

0 comments on commit 6855476

Please sign in to comment.