Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement event support for basic information cluster #12739

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,72 @@
#include "basic.h"

#include <app-common/zap-generated/attributes/Accessors.h>
#include <cstddef>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/EventLogging.h>
#include <app/util/attribute-storage.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/ConfigurationManager.h>
#include <platform/PlatformManager.h>

#include <cstddef>
#include <cstring>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::Basic;
using namespace chip::DeviceLayer;

namespace {

class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate
{
// Gets called by the current Node after completing a boot or reboot process.
void OnStartUp(uint32_t softwareVersion) override
{
ChipLogProgress(Zcl, "PlatformMgrDelegate: OnStartUp");

ForAllEndpointsWithServerCluster(
Basic::Id,
[](EndpointId endpoint, intptr_t context) -> Loop {
// If Basic cluster is implemented on this endpoint
Events::StartUp::Type event{ static_cast<uint32_t>(context) };
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber, EventOptions::Type::kUrgent))
{
ChipLogError(Zcl, "PlatformMgrDelegate: Failed to record StartUp event");
}

return Loop::Continue;
},
static_cast<intptr_t>(softwareVersion));
}

// Gets called by the current Node prior to any orderly shutdown sequence on a best-effort basis.
void OnShutDown() override
{
ChipLogProgress(Zcl, "PlatformMgrDelegate: OnShutDown");

ForAllEndpointsWithServerCluster(Basic::Id, [](EndpointId endpoint, intptr_t context) -> Loop {
// If Basic cluster is implemented on this endpoint
Events::ShutDown::Type event;
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "PlatformMgrDelegate: Failed to record ShutDown event");
}

return Loop::Continue;
});
}
};

PlatformMgrDelegate gPlatformMgrDelegate;

} // anonymous namespace

void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)
{
EmberAfStatus status;
Expand Down Expand Up @@ -167,4 +223,7 @@ void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)
}
}

void MatterBasicPluginServerInitCallback() {}
void MatterBasicPluginServerInitCallback()
{
PlatformMgr().SetDelegate(&gPlatformMgrDelegate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <app/AttributeAccessInterface.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/EventLogging.h>
#include <app/reporting/reporting.h>
#include <app/server/Dnssd.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -228,6 +229,20 @@ class OpCredsFabricTableDelegate : public FabricTableDelegate
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Fabric 0x%" PRIu8 " was deleted from fabric storage.", fabricId);
fabricListChanged();

// The Leave event SHOULD be emitted by a Node prior to permanently leaving the Fabric.
ForAllEndpointsWithServerCluster(Basic::Id, [](EndpointId endpoint, intptr_t context) -> Loop {
// If Basic cluster is implemented on this endpoint
Basic::Events::Leave::Type event;
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "OpCredsFabricTableDelegate: Failed to record Leave event");
}

return Loop::Continue;
});
}

// Gets called when a fabric is loaded into the FabricTable from KVS store.
Expand Down
27 changes: 26 additions & 1 deletion src/include/platform/PlatformManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ template <class>
class GenericThreadStackManagerImpl_OpenThread_LwIP;
} // namespace Internal

/**
* Defines the delegate class of Platform Manager to notify platform updates.
*/
class PlatformManagerDelegate
{
public:
virtual ~PlatformManagerDelegate() {}

/**
* @brief
* Called by the current Node after completing a boot or reboot process.
*/
virtual void OnStartUp(uint32_t softwareVersion) {}

/**
* @brief
* Called by the current Node prior to any orderly shutdown sequence on a
* best-effort basis.
*/
virtual void OnShutDown() {}
};

/**
* Provides features for initializing and interacting with the chip network
* stack on a chip-enabled device.
Expand All @@ -88,6 +110,8 @@ class PlatformManager
CHIP_ERROR InitChipStack();
CHIP_ERROR AddEventHandler(EventHandlerFunct handler, intptr_t arg = 0);
void RemoveEventHandler(EventHandlerFunct handler, intptr_t arg = 0);
void SetDelegate(PlatformManagerDelegate * delegate) { mDelegate = delegate; }
PlatformManagerDelegate * GetDelegate() const { return mDelegate; }

/**
* ScheduleWork can be called after InitChipStack has been called. Calls
Expand Down Expand Up @@ -156,7 +180,8 @@ class PlatformManager
#endif

private:
bool mInitialized = false;
bool mInitialized = false;
PlatformManagerDelegate * mDelegate = nullptr;

// ===== Members for internal use by the following friends.

Expand Down
25 changes: 21 additions & 4 deletions src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()

CHIP_ERROR PlatformManagerImpl::_Shutdown()
{
uint64_t upTime = 0;
PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate();
uint64_t upTime = 0;

// The ShutDown event SHOULD be emitted by a Node prior to any orderly shutdown sequence.
if (platformManagerDelegate != nullptr)
{
platformManagerDelegate->OnShutDown();
}

if (GetDiagnosticDataProvider().GetUpTime(upTime) == CHIP_NO_ERROR)
{
Expand All @@ -263,11 +270,21 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown()

void PlatformManagerImpl::HandleDeviceRebooted(intptr_t arg)
{
GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();
PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate();
GeneralDiagnosticsDelegate * generalDiagnosticsDelegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();

if (delegate != nullptr)
if (generalDiagnosticsDelegate != nullptr)
{
delegate->OnDeviceRebooted();
generalDiagnosticsDelegate->OnDeviceRebooted();
}

// The StartUp event SHALL be emitted by a Node after completing a boot or reboot process
if (platformManagerDelegate != nullptr)
{
uint16_t softwareVersion;

ReturnOnFailure(ConfigurationMgr().GetSoftwareVersion(softwareVersion));
platformManagerDelegate->OnStartUp(softwareVersion);
}
}

Expand Down