Skip to content

Commit

Permalink
Trigger StartUp & ShutDown event on all platforms uniformly (project-…
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored Feb 5, 2022
1 parent e800530 commit 695b616
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
35 changes: 35 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,11 @@ CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_InitChipStack()

// TODO Initialize the Software Update Manager object.

// TODO: Attempt to diagnose Darwin CI, REMOVE ONCE FIXED
#if !CHIP_DEVICE_LAYER_TARGET_DARWIN
_ScheduleWork(HandleDeviceRebooted, 0);
#endif

exit:
return err;
}
Expand All @@ -130,6 +136,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 +302,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 @@ -247,22 +247,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 @@ -389,26 +380,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
12 changes: 0 additions & 12 deletions src/platform/Zephyr/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,9 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
k_timer_start(&sOperationalHoursSavingTimer, K_HOURS(CONFIG_CHIP_OPERATIONAL_TIME_SAVE_INTERVAL),
K_HOURS(CONFIG_CHIP_OPERATIONAL_TIME_SAVE_INTERVAL));

ScheduleWork(OnDeviceBoot, 0);

exit:
return err;
}

void PlatformManagerImpl::OnDeviceBoot(intptr_t arg)
{
GeneralDiagnosticsDelegate * generalDiagnosticsDelegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();

if (generalDiagnosticsDelegate)
{
generalDiagnosticsDelegate->OnDeviceRebooted();
}
}

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Zephyr/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener

static void OperationalHoursSavingTimerEventHandler(k_timer * timer);
static void UpdateOperationalHours(intptr_t arg);
static void OnDeviceBoot(intptr_t arg);

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

Expand Down

0 comments on commit 695b616

Please sign in to comment.