Skip to content

Commit

Permalink
Trigger StartUp & ShutDown event on all platforms uniformly
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Feb 3, 2022
1 parent 974a6eb commit ff86b92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
32 changes: 32 additions & 0 deletions src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <inttypes.h>
#include <new>
#include <platform/DiagnosticDataProvider.h>
#include <platform/PlatformManager.h>
#include <platform/internal/BLEManager.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
Expand Down Expand Up @@ -122,6 +123,8 @@ CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_InitChipStack()

// TODO Initialize the Software Update Manager object.

_ScheduleWork(HandleDeviceRebooted, 0);

exit:
return err;
}
Expand All @@ -130,6 +133,14 @@ template <class ImplClass>
CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_Shutdown()
{
CHIP_ERROR err;
PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate();

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

ChipLogError(DeviceLayer, "Inet Layer shutdown");
err = UDPEndPointManager()->Shutdown();

Expand Down Expand Up @@ -288,6 +299,27 @@ void GenericPlatformManagerImpl<ImplClass>::HandleMessageLayerActivityChanged(bo
}
}

template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::HandleDeviceRebooted(intptr_t arg)
{
PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate();
GeneralDiagnosticsDelegate * generalDiagnosticsDelegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();

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

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

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

// Fully instantiate the generic implementation class in whatever compilation unit includes this file.
template class GenericPlatformManagerImpl<PlatformManagerImpl>;

Expand Down
1 change: 1 addition & 0 deletions src/include/platform/internal/GenericPlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GenericPlatformManagerImpl
private:
bool mMsgLayerWasActive;

static void HandleDeviceRebooted(intptr_t arg);
ImplClass * Impl() { return static_cast<ImplClass *>(this); }
};

Expand Down
31 changes: 1 addition & 30 deletions src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,13 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()

mStartTime = System::SystemClock().GetMonotonicTimestamp();

ScheduleWork(HandleDeviceRebooted, 0);

exit:
return err;
}

CHIP_ERROR PlatformManagerImpl::_Shutdown()
{
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();
}
uint64_t upTime = 0;

if (GetDiagnosticDataProvider().GetUpTime(upTime) == CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -382,26 +373,6 @@ PlatformManagerImpl::_GetSupportedCalendarTypes(
return CHIP_NO_ERROR;
}

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

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

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

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

void PlatformManagerImpl::HandleGeneralFault(uint32_t EventId)
{
GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();
Expand Down
1 change: 0 additions & 1 deletion src/platform/Linux/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
// The temporary hack for getting IP address change on linux for network provisioning in the rendezvous session.
// This should be removed or find a better place once we depercate the rendezvous session.
static void WiFIIPChangeListener();
static void HandleDeviceRebooted(intptr_t arg);

#if CHIP_WITH_GIO
struct GDBusConnectionDeleter
Expand Down

0 comments on commit ff86b92

Please sign in to comment.