From c868f81c6014017ccbe20d64ab43682db9ea1fa0 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 7 Jun 2022 13:31:01 -0700 Subject: [PATCH] Fix SoftwareFault and GeneralFault events are missed randomly (#19064) * Fix SoftwareFault and GeneralFault events are missed randomly * Remove GeneralDiagnosticsDelegate and implement event API in cluster server * Refactor new APIs from Server into cluster server * Address review comments * Update examples/all-clusters-app/linux/main-common.cpp Co-authored-by: Boris Zbarsky * Rename Server to GeneralDiagnosticsServer to avoid namespace conflict Co-authored-by: Boris Zbarsky --- .../all-clusters-app/linux/main-common.cpp | 204 ++++++++++++++++++ examples/platform/linux/AppMain.cpp | 59 ----- .../general-diagnostics-server.cpp | 198 +++++++++-------- .../general-diagnostics-server.h | 72 +++++++ .../software-diagnostics-server.cpp | 50 +++-- .../software-diagnostics-server.h | 50 +++++ src/include/platform/DiagnosticDataProvider.h | 61 +----- src/include/platform/GeneralFaults.h | 2 +- .../internal/GenericPlatformManagerImpl.ipp | 9 - src/platform/Linux/PlatformManagerImpl.cpp | 118 ---------- src/platform/Linux/PlatformManagerImpl.h | 3 - src/platform/webos/PlatformManagerImpl.cpp | 120 ----------- src/platform/webos/PlatformManagerImpl.h | 3 - 13 files changed, 473 insertions(+), 476 deletions(-) create mode 100644 src/app/clusters/general-diagnostics-server/general-diagnostics-server.h create mode 100644 src/app/clusters/software-diagnostics-server/software-diagnostics-server.h diff --git a/examples/all-clusters-app/linux/main-common.cpp b/examples/all-clusters-app/linux/main-common.cpp index 7829f3a6c1894a..129180f7ac1be5 100644 --- a/examples/all-clusters-app/linux/main-common.cpp +++ b/examples/all-clusters-app/linux/main-common.cpp @@ -21,12 +21,15 @@ #include #include #include +#include #include #include +#include #include #include #include #include +#include #include #include #include @@ -41,6 +44,203 @@ using namespace chip::DeviceLayer; namespace { static LowPowerManager lowPowerManager; + +bool IsClusterPresentOnAnyEndpoint(ClusterId clusterId) +{ + bool retval = false; + + for (auto endpointId : EnabledEndpointsWithServerCluster(clusterId)) + { + IgnoreUnusedVariable(endpointId); + retval = true; + } + + return retval; +} + +/** + * Should be called when a software fault takes place on the Node. + */ +void HandleSoftwareFaultEvent(intptr_t arg) +{ + if (!IsClusterPresentOnAnyEndpoint(Clusters::SoftwareDiagnostics::Id)) + return; + + Clusters::SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type softwareFault; + char threadName[kMaxThreadNameLength + 1]; + + softwareFault.id = static_cast(getpid()); + Platform::CopyString(threadName, std::to_string(softwareFault.id).c_str()); + + softwareFault.name = CharSpan::fromCharString(threadName); + + std::time_t result = std::time(nullptr); + char * asctime = std::asctime(std::localtime(&result)); + softwareFault.faultRecording = ByteSpan(Uint8::from_const_char(asctime), strlen(asctime)); + + Clusters::SoftwareDiagnosticsServer::Instance().OnSoftwareFaultDetect(softwareFault); +} + +/** + * Should be called when a general fault takes place on the Node. + */ +void HandleGeneralFaultEvent(intptr_t arg) +{ + uint32_t eventId = static_cast(arg); + + if (!IsClusterPresentOnAnyEndpoint(Clusters::GeneralDiagnostics::Id)) + return; + + if (eventId == Clusters::GeneralDiagnostics::Events::HardwareFaultChange::Id) + { + GeneralFaults previous; + GeneralFaults current; + +#if CHIP_CONFIG_TEST + // On Linux Simulation, set following hardware faults statically. + ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); + ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); + + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_SENSOR)); + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_USER_INTERFACE_FAULT)); +#endif + Clusters::GeneralDiagnosticsServer::Instance().OnHardwareFaultsDetect(previous, current); + } + else if (eventId == Clusters::GeneralDiagnostics::Events::RadioFaultChange::Id) + { + GeneralFaults previous; + GeneralFaults current; + +#if CHIP_CONFIG_TEST + // On Linux Simulation, set following radio faults statically. + ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); + ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); + + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_CELLULAR_FAULT)); + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_NFC_FAULT)); +#endif + Clusters::GeneralDiagnosticsServer::Instance().OnRadioFaultsDetect(previous, current); + } + else if (eventId == Clusters::GeneralDiagnostics::Events::NetworkFaultChange::Id) + { + GeneralFaults previous; + GeneralFaults current; + +#if CHIP_CONFIG_TEST + // On Linux Simulation, set following radio faults statically. + ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); + ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); + + ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); + ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); + ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_CONNECTION_FAILED)); +#endif + Clusters::GeneralDiagnosticsServer::Instance().OnNetworkFaultsDetect(previous, current); + } + else + { + ChipLogError(DeviceLayer, "Unknow event ID:%d", eventId); + } +} + +// when the shell is enabled, don't intercept signals since it prevents the user from +// using expected commands like CTRL-C to quit the application. (see issue #17845) +// We should stop using signals for those faults, and move to a different notification +// means, like a pipe. (see issue #19114) +#if !defined(ENABLE_CHIP_SHELL) +void OnRebootSignalHandler(int signum) +{ + ChipLogDetail(DeviceLayer, "Caught signal %d", signum); + + // The BootReason attribute SHALL indicate the reason for the Node’s most recent boot, the real usecase + // for this attribute is embedded system. In Linux simulation, we use different signals to tell the current + // running process to terminate with different reasons. + BootReasonType bootReason = BootReasonType::kUnspecified; + switch (signum) + { + case SIGVTALRM: + bootReason = BootReasonType::kPowerOnReboot; + break; + case SIGALRM: + bootReason = BootReasonType::kBrownOutReset; + break; + case SIGILL: + bootReason = BootReasonType::kSoftwareWatchdogReset; + break; + case SIGTRAP: + bootReason = BootReasonType::kHardwareWatchdogReset; + break; + case SIGIO: + bootReason = BootReasonType::kSoftwareUpdateCompleted; + break; + case SIGINT: + bootReason = BootReasonType::kSoftwareReset; + break; + default: + IgnoreUnusedVariable(bootReason); + ChipLogError(NotSpecified, "Unhandled signal: Should never happens"); + chipDie(); + break; + } + + Server::GetInstance().DispatchShutDownAndStopEventLoop(); +} + +void OnSoftwareFaultSignalHandler(int signum) +{ + ChipLogDetail(DeviceLayer, "Caught signal %d", signum); + + VerifyOrDie(signum == SIGUSR1); + PlatformMgr().ScheduleWork(HandleSoftwareFaultEvent); +} + +void OnGeneralFaultSignalHandler(int signum) +{ + ChipLogDetail(DeviceLayer, "Caught signal %d", signum); + + uint32_t eventId; + switch (signum) + { + case SIGUSR2: + eventId = Clusters::GeneralDiagnostics::Events::HardwareFaultChange::Id; + break; + case SIGHUP: + eventId = Clusters::GeneralDiagnostics::Events::RadioFaultChange::Id; + break; + case SIGTTIN: + eventId = Clusters::GeneralDiagnostics::Events::NetworkFaultChange::Id; + break; + default: + ChipLogError(NotSpecified, "Unhandled signal: Should never happens"); + chipDie(); + break; + } + + PlatformMgr().ScheduleWork(HandleGeneralFaultEvent, static_cast(eventId)); +} + +void SetupSignalHandlers() +{ + // sigaction is not used here because Tsan interceptors seems to + // never dispatch the signals on darwin. + signal(SIGALRM, OnRebootSignalHandler); + signal(SIGVTALRM, OnRebootSignalHandler); + signal(SIGILL, OnRebootSignalHandler); + signal(SIGTRAP, OnRebootSignalHandler); + signal(SIGTERM, OnRebootSignalHandler); + signal(SIGIO, OnRebootSignalHandler); + signal(SIGINT, OnRebootSignalHandler); + signal(SIGUSR1, OnSoftwareFaultSignalHandler); + signal(SIGUSR2, OnGeneralFaultSignalHandler); + signal(SIGHUP, OnGeneralFaultSignalHandler); + signal(SIGTTIN, OnGeneralFaultSignalHandler); +} +#endif // !defined(ENABLE_CHIP_SHELL) + } // namespace bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * commandObj) @@ -118,6 +318,10 @@ Clusters::NetworkCommissioning::Instance sNullNetworkCommissioningInstance(kNetw void ApplicationInit() { +#if !defined(ENABLE_CHIP_SHELL) + SetupSignalHandlers(); +#endif // !defined(ENABLE_CHIP_SHELL) + (void) kNetworkCommissioningEndpointMain; // Enable secondary endpoint only when we need it, this should be applied to all platforms. emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index eac14aa7223b1f..bfbc9cab2727a5 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -110,61 +110,6 @@ void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg) } } -// when the shell is enabled, don't intercept signals since it prevents the user from -// using expected commands like CTRL-C to quit the application. (see issue #17845) -#if !defined(ENABLE_CHIP_SHELL) -void OnSignalHandler(int signum) -{ - ChipLogDetail(DeviceLayer, "Caught signal %d", signum); - - // The BootReason attribute SHALL indicate the reason for the Node’s most recent boot, the real usecase - // for this attribute is embedded system. In Linux simulation, we use different signals to tell the current - // running process to terminate with different reasons. - BootReasonType bootReason = BootReasonType::kUnspecified; - switch (signum) - { - case SIGVTALRM: - bootReason = BootReasonType::kPowerOnReboot; - break; - case SIGALRM: - bootReason = BootReasonType::kBrownOutReset; - break; - case SIGILL: - bootReason = BootReasonType::kSoftwareWatchdogReset; - break; - case SIGTRAP: - bootReason = BootReasonType::kHardwareWatchdogReset; - break; - case SIGIO: - bootReason = BootReasonType::kSoftwareUpdateCompleted; - break; - case SIGINT: - bootReason = BootReasonType::kSoftwareReset; - break; - default: - IgnoreUnusedVariable(bootReason); - ChipLogError(NotSpecified, "Unhandled signal: Should never happens"); - chipDie(); - break; - } - - Server::GetInstance().DispatchShutDownAndStopEventLoop(); -} - -void SetupSignalHandlers() -{ - // sigaction is not used here because Tsan interceptors seems to - // never dispatch the signals on darwin. - signal(SIGALRM, OnSignalHandler); - signal(SIGVTALRM, OnSignalHandler); - signal(SIGILL, OnSignalHandler); - signal(SIGTRAP, OnSignalHandler); - signal(SIGTERM, OnSignalHandler); - signal(SIGIO, OnSignalHandler); - signal(SIGINT, OnSignalHandler); -} -#endif // !defined(ENABLE_CHIP_SHELL) - void Cleanup() { #if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED @@ -375,10 +320,6 @@ void ChipLinuxAppMainLoop() #endif // defined(ENABLE_CHIP_SHELL) #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE -#if !defined(ENABLE_CHIP_SHELL) - SetupSignalHandlers(); -#endif // !defined(ENABLE_CHIP_SHELL) - ApplicationInit(); DeviceLayer::PlatformMgr().RunEventLoop(); diff --git a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp index 7cfb5c0f977c54..0ab14a94540115 100644 --- a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp +++ b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#include "general-diagnostics-server.h" #include "app/server/Server.h" #include #include @@ -42,7 +43,7 @@ namespace { bool IsTestEventTriggerEnabled() { - auto * triggerDelegate = Server::GetInstance().GetTestEventTriggerDelegate(); + auto * triggerDelegate = chip::Server::GetInstance().GetTestEventTriggerDelegate(); if (triggerDelegate == nullptr) { return false; @@ -67,6 +68,14 @@ bool IsByteSpanAllZeros(const ByteSpan & byteSpan) return true; } +void ReportAttributeOnAllEndpoints(AttributeId attribute) +{ + for (auto endpoint : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) + { + MatterReportingAttributeChangeCallback(endpoint, GeneralDiagnostics::Id, attribute); + } +} + class GeneralDiagosticsAttrAccess : public AttributeAccessInterface { public: @@ -202,16 +211,8 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & a return CHIP_NO_ERROR; } -class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelegate, public DeviceLayer::GeneralDiagnosticsDelegate +class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelegate { - static void ReportAttributeOnAllEndpoints(AttributeId attribute) - { - for (auto endpoint : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) - { - MatterReportingAttributeChangeCallback(endpoint, GeneralDiagnostics::Id, attribute); - } - } - // Gets called when any network interface on the Node is updated. void OnNetworkInfoChanged() override { @@ -219,109 +220,131 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::NetworkInterfaces::Id); } +}; - // Gets called when the device has been rebooted. - void OnDeviceRebooted(BootReasonType bootReason) override - { - ChipLogDetail(Zcl, "GeneralDiagnosticsDelegate: OnDeviceRebooted"); +GeneralDiagnosticsDelegate gDiagnosticDelegate; - ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::BootReasons::Id); +} // anonymous namespace - // GeneralDiagnostics cluster should exist only for endpoint 0. +namespace chip { +namespace app { +namespace Clusters { +GeneralDiagnosticsServer GeneralDiagnosticsServer::instance; + +/********************************************************** + * GeneralDiagnosticsServer Implementation + *********************************************************/ + +GeneralDiagnosticsServer & GeneralDiagnosticsServer::Instance() +{ + return instance; +} + +// Gets called when the device has been rebooted. +void GeneralDiagnosticsServer::OnDeviceReboot(BootReasonType bootReason) +{ + ChipLogDetail(Zcl, "GeneralDiagnostics: OnDeviceReboot"); + + ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::BootReasons::Id); + + // GeneralDiagnostics cluster should exist only for endpoint 0. + if (emberAfContainsServer(0, GeneralDiagnostics::Id)) + { Events::BootReason::Type event{ bootReason }; EventNumber eventNumber; CHIP_ERROR err = LogEvent(event, 0, eventNumber); if (CHIP_NO_ERROR != err) { - ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record BootReason event: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(Zcl, "GeneralDiagnostics: Failed to record BootReason event: %" CHIP_ERROR_FORMAT, err.Format()); } } +} - // Get called when the Node detects a hardware fault has been raised. - void OnHardwareFaultsDetected(GeneralFaults & previous, - GeneralFaults & current) override +// Get called when the Node detects a hardware fault has been raised. +void GeneralDiagnosticsServer::OnHardwareFaultsDetect(const GeneralFaults & previous, + const GeneralFaults & current) +{ + ChipLogDetail(Zcl, "GeneralDiagnostics: OnHardwareFaultsDetect"); + + for (auto endpointId : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) { - ChipLogDetail(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected"); + // If General Diagnostics cluster is implemented on this endpoint + MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, + GeneralDiagnostics::Attributes::ActiveHardwareFaults::Id); + + // Record HardwareFault event + EventNumber eventNumber; + DataModel::List currentList(reinterpret_cast(current.data()), + current.size()); + DataModel::List previousList(reinterpret_cast(previous.data()), + previous.size()); + Events::HardwareFaultChange::Type event{ currentList, previousList }; - for (auto endpointId : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) + if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber)) { - // If General Diagnostics cluster is implemented on this endpoint - MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, - GeneralDiagnostics::Attributes::ActiveHardwareFaults::Id); - - // Record HardwareFault event - EventNumber eventNumber; - DataModel::List currentList = DataModel::List( - reinterpret_cast(current.data()), current.size()); - DataModel::List previousList = DataModel::List( - reinterpret_cast(previous.data()), previous.size()); - Events::HardwareFaultChange::Type event{ currentList, previousList }; - - if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber)) - { - ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record HardwareFault event"); - } + ChipLogError(Zcl, "GeneralDiagnostics: Failed to record HardwareFault event"); } } +} - // Get called when the Node detects a radio fault has been raised. - void OnRadioFaultsDetected(GeneralFaults & previous, GeneralFaults & current) override +// Get called when the Node detects a radio fault has been raised. +void GeneralDiagnosticsServer::OnRadioFaultsDetect(const GeneralFaults & previous, + const GeneralFaults & current) +{ + ChipLogDetail(Zcl, "GeneralDiagnostics: OnRadioFaultsDetect"); + + for (auto endpointId : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) { - ChipLogDetail(Zcl, "GeneralDiagnosticsDelegate: OnRadioFaultsDetected"); + // If General Diagnostics cluster is implemented on this endpoint + MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, + GeneralDiagnostics::Attributes::ActiveRadioFaults::Id); + + // Record RadioFault event + EventNumber eventNumber; + DataModel::List currentList(reinterpret_cast(current.data()), current.size()); + DataModel::List previousList(reinterpret_cast(previous.data()), + previous.size()); + Events::RadioFaultChange::Type event{ currentList, previousList }; - for (auto endpointId : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) + if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber)) { - // If General Diagnostics cluster is implemented on this endpoint - MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, - GeneralDiagnostics::Attributes::ActiveRadioFaults::Id); - - // Record RadioFault event - EventNumber eventNumber; - DataModel::List currentList = - DataModel::List(reinterpret_cast(current.data()), current.size()); - DataModel::List previousList = - DataModel::List(reinterpret_cast(previous.data()), previous.size()); - Events::RadioFaultChange::Type event{ currentList, previousList }; - - if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber)) - { - ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record RadioFault event"); - } + ChipLogError(Zcl, "GeneralDiagnostics: Failed to record RadioFault event"); } } +} - // Get called when the Node detects a network fault has been raised. - void OnNetworkFaultsDetected(GeneralFaults & previous, GeneralFaults & current) override +// Get called when the Node detects a network fault has been raised. +void GeneralDiagnosticsServer::OnNetworkFaultsDetect(const GeneralFaults & previous, + const GeneralFaults & current) +{ + ChipLogDetail(Zcl, "GeneralDiagnostics: OnNetworkFaultsDetect"); + + for (auto endpointId : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) { - ChipLogDetail(Zcl, "GeneralDiagnosticsDelegate: OnNetworkFaultsDetected"); + // If General Diagnostics cluster is implemented on this endpoint + MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, + GeneralDiagnostics::Attributes::ActiveNetworkFaults::Id); - for (auto endpointId : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id)) + // Record NetworkFault event + EventNumber eventNumber; + DataModel::List currentList(reinterpret_cast(current.data()), + current.size()); + DataModel::List previousList(reinterpret_cast(previous.data()), + previous.size()); + Events::NetworkFaultChange::Type event{ currentList, previousList }; + + if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber)) { - // If General Diagnostics cluster is implemented on this endpoint - MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, - GeneralDiagnostics::Attributes::ActiveNetworkFaults::Id); - - // Record NetworkFault event - EventNumber eventNumber; - DataModel::List currentList = - DataModel::List(reinterpret_cast(current.data()), current.size()); - DataModel::List previousList = DataModel::List( - reinterpret_cast(previous.data()), previous.size()); - Events::NetworkFaultChange::Type event{ currentList, previousList }; - - if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber)) - { - ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record NetworkFault event"); - } + ChipLogError(Zcl, "GeneralDiagnostics: Failed to record NetworkFault event"); } } -}; +} -GeneralDiagnosticsDelegate gDiagnosticDelegate; - -} // anonymous namespace +} // namespace Clusters +} // namespace app +} // namespace chip bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const Commands::TestEventTrigger::DecodableType & commandData) @@ -339,7 +362,7 @@ bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * c return true; } - auto * triggerDelegate = Server::GetInstance().GetTestEventTriggerDelegate(); + auto * triggerDelegate = chip::Server::GetInstance().GetTestEventTriggerDelegate(); if (triggerDelegate == nullptr || !triggerDelegate->DoesEnableKeyMatch(commandData.enableKey)) { @@ -363,8 +386,13 @@ bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * c void MatterGeneralDiagnosticsPluginServerInitCallback() { - registerAttributeAccessOverride(&gAttrAccess); + BootReasonType bootReason; + registerAttributeAccessOverride(&gAttrAccess); ConnectivityMgr().SetDelegate(&gDiagnosticDelegate); - GetDiagnosticDataProvider().SetGeneralDiagnosticsDelegate(&gDiagnosticDelegate); + + if (GetDiagnosticDataProvider().GetBootReason(bootReason) == CHIP_NO_ERROR) + { + GeneralDiagnosticsServer::Instance().OnDeviceReboot(bootReason); + } } diff --git a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.h b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.h new file mode 100644 index 00000000000000..ee0ac70b3473a8 --- /dev/null +++ b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.h @@ -0,0 +1,72 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace chip { +namespace app { +namespace Clusters { + +/** + * @brief general-diagnostics-server class + */ +class GeneralDiagnosticsServer +{ +public: + static GeneralDiagnosticsServer & Instance(); + + /** + * @brief + * Called after the current device is rebooted. + */ + void OnDeviceReboot(GeneralDiagnostics::BootReasonType bootReason); + + /** + * @brief + * Called when the Node detects a hardware fault has been raised. + */ + void OnHardwareFaultsDetect(const DeviceLayer::GeneralFaults & previous, + const DeviceLayer::GeneralFaults & current); + + /** + * @brief + * Called when the Node detects a radio fault has been raised. + */ + void OnRadioFaultsDetect(const DeviceLayer::GeneralFaults & previous, + const DeviceLayer::GeneralFaults & current); + + /** + * @brief + * Called when the Node detects a network fault has been raised. + */ + void OnNetworkFaultsDetect(const DeviceLayer::GeneralFaults & previous, + const DeviceLayer::GeneralFaults & current); + +private: + static GeneralDiagnosticsServer instance; +}; + +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp b/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp index 21298d2975857e..ed89554fef6cab 100644 --- a/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp +++ b/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#include "software-diagnostics-server.h" #include #include #include @@ -130,30 +131,44 @@ CHIP_ERROR SoftwareDiagosticsAttrAccess::ReadThreadMetrics(AttributeValueEncoder return err; } -class SoftwareDiagnosticsDelegate : public DeviceLayer::SoftwareDiagnosticsDelegate +} // anonymous namespace + +namespace chip { +namespace app { +namespace Clusters { + +SoftwareDiagnosticsServer SoftwareDiagnosticsServer::instance; + +/********************************************************** + * SoftwareDiagnosticsServer Implementation + *********************************************************/ + +SoftwareDiagnosticsServer & SoftwareDiagnosticsServer::Instance() +{ + return instance; +} + +// Gets called when a software fault that has taken place on the Node. +void SoftwareDiagnosticsServer::OnSoftwareFaultDetect(const SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault) { - // Gets called when a software fault that has taken place on the Node. - void OnSoftwareFaultDetected(SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault) override + ChipLogDetail(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected"); + + for (auto endpoint : EnabledEndpointsWithServerCluster(SoftwareDiagnostics::Id)) { - ChipLogDetail(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected"); + // If Software Diagnostics cluster is implemented on this endpoint + EventNumber eventNumber; + Events::SoftwareFault::Type event{ softwareFault }; - for (auto endpoint : EnabledEndpointsWithServerCluster(SoftwareDiagnostics::Id)) + if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber)) { - // If Software Diagnostics cluster is implemented on this endpoint - EventNumber eventNumber; - Events::SoftwareFault::Type event{ softwareFault }; - - if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber)) - { - ChipLogError(Zcl, "SoftwareDiagnosticsDelegate: Failed to record SoftwareFault event"); - } + ChipLogError(Zcl, "SoftwareDiagnosticsDelegate: Failed to record SoftwareFault event"); } } -}; - -SoftwareDiagnosticsDelegate gDiagnosticDelegate; +} -} // anonymous namespace +} // namespace Clusters +} // namespace app +} // namespace chip bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, @@ -176,5 +191,4 @@ bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandle void MatterSoftwareDiagnosticsPluginServerInitCallback() { registerAttributeAccessOverride(&gAttrAccess); - GetDiagnosticDataProvider().SetSoftwareDiagnosticsDelegate(&gDiagnosticDelegate); } diff --git a/src/app/clusters/software-diagnostics-server/software-diagnostics-server.h b/src/app/clusters/software-diagnostics-server/software-diagnostics-server.h new file mode 100644 index 00000000000000..95fa51c03aed4b --- /dev/null +++ b/src/app/clusters/software-diagnostics-server/software-diagnostics-server.h @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +namespace chip { +namespace app { +namespace Clusters { + +/** + * @brief software-diagnostics-server class + */ +class SoftwareDiagnosticsServer +{ +public: + static SoftwareDiagnosticsServer & Instance(); + + /** + * @brief + * Called when a software fault that has taken place on the Node. + */ + void OnSoftwareFaultDetect(const chip::app::Clusters::SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault); + +private: + static SoftwareDiagnosticsServer instance; +}; + +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/include/platform/DiagnosticDataProvider.h b/src/include/platform/DiagnosticDataProvider.h index a23b6c252715c8..a53ee3d8979411 100644 --- a/src/include/platform/DiagnosticDataProvider.h +++ b/src/include/platform/DiagnosticDataProvider.h @@ -62,57 +62,6 @@ struct NetworkInterface : public app::Clusters::GeneralDiagnostics::Structs::Net NetworkInterface * Next; /* Pointer to the next structure. */ }; -/** - * Defines the General Diagnostics Delegate class to notify platform events. - */ -class GeneralDiagnosticsDelegate -{ -public: - virtual ~GeneralDiagnosticsDelegate() {} - - /** - * @brief - * Called after the current device is rebooted. - */ - virtual void OnDeviceRebooted(BootReasonType bootReason) {} - - /** - * @brief - * Called when the Node detects a hardware fault has been raised. - */ - virtual void OnHardwareFaultsDetected(GeneralFaults & previous, GeneralFaults & current) - {} - - /** - * @brief - * Called when the Node detects a radio fault has been raised. - */ - virtual void OnRadioFaultsDetected(GeneralFaults & previous, GeneralFaults & current) {} - - /** - * @brief - * Called when the Node detects a network fault has been raised. - */ - virtual void OnNetworkFaultsDetected(GeneralFaults & previous, GeneralFaults & current) {} -}; - -/** - * Defines the Software Diagnostics Delegate class to notify software events. - */ -class SoftwareDiagnosticsDelegate -{ -public: - virtual ~SoftwareDiagnosticsDelegate() {} - - /** - * @brief - * Called when a software fault that has taken place on the Node. - */ - virtual void - OnSoftwareFaultDetected(chip::app::Clusters::SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault) - {} -}; - /** * Defines the WiFi Diagnostics Delegate class to notify WiFi network events. */ @@ -146,12 +95,6 @@ class WiFiDiagnosticsDelegate class DiagnosticDataProvider { public: - void SetGeneralDiagnosticsDelegate(GeneralDiagnosticsDelegate * delegate) { mGeneralDiagnosticsDelegate = delegate; } - GeneralDiagnosticsDelegate * GetGeneralDiagnosticsDelegate() const { return mGeneralDiagnosticsDelegate; } - - void SetSoftwareDiagnosticsDelegate(SoftwareDiagnosticsDelegate * delegate) { mSoftwareDiagnosticsDelegate = delegate; } - SoftwareDiagnosticsDelegate * GetSoftwareDiagnosticsDelegate() const { return mSoftwareDiagnosticsDelegate; } - void SetWiFiDiagnosticsDelegate(WiFiDiagnosticsDelegate * delegate) { mWiFiDiagnosticsDelegate = delegate; } WiFiDiagnosticsDelegate * GetWiFiDiagnosticsDelegate() const { return mWiFiDiagnosticsDelegate; } @@ -232,9 +175,7 @@ class DiagnosticDataProvider virtual ~DiagnosticDataProvider() = default; private: - GeneralDiagnosticsDelegate * mGeneralDiagnosticsDelegate = nullptr; - SoftwareDiagnosticsDelegate * mSoftwareDiagnosticsDelegate = nullptr; - WiFiDiagnosticsDelegate * mWiFiDiagnosticsDelegate = nullptr; + WiFiDiagnosticsDelegate * mWiFiDiagnosticsDelegate = nullptr; // No copy, move or assignment. DiagnosticDataProvider(const DiagnosticDataProvider &) = delete; diff --git a/src/include/platform/GeneralFaults.h b/src/include/platform/GeneralFaults.h index 9994449e122416..182a4e32cbdefc 100644 --- a/src/include/platform/GeneralFaults.h +++ b/src/include/platform/GeneralFaults.h @@ -54,7 +54,7 @@ class GeneralFaults CHIP_ERROR add(const uint8_t value); - uint8_t * data() { return mData; } + const uint8_t * data() const { return mData; } size_t size() const; uint8_t operator[](int index) const; diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.ipp b/src/include/platform/internal/GenericPlatformManagerImpl.ipp index c3e2370748395c..66233710a595b2 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.ipp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.ipp @@ -195,7 +195,6 @@ template void GenericPlatformManagerImpl::_HandleServerStarted() { PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate(); - GeneralDiagnosticsDelegate * generalDiagnosticsDelegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate(); if (platformManagerDelegate != nullptr) { @@ -204,14 +203,6 @@ void GenericPlatformManagerImpl::_HandleServerStarted() if (ConfigurationMgr().GetSoftwareVersion(softwareVersion) == CHIP_NO_ERROR) platformManagerDelegate->OnStartUp(softwareVersion); } - - if (generalDiagnosticsDelegate != nullptr) - { - BootReasonType bootReason; - - if (GetDiagnosticDataProvider().GetBootReason(bootReason) == CHIP_NO_ERROR) - generalDiagnosticsDelegate->OnDeviceRebooted(bootReason); - } } template diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index 551b8dffff25f9..a4b8c432759487 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -59,29 +59,6 @@ PlatformManagerImpl PlatformManagerImpl::sInstance; namespace { -void SignalHandler(int signum) -{ - ChipLogDetail(DeviceLayer, "Caught signal %d", signum); - - switch (signum) - { - case SIGUSR1: - PlatformMgrImpl().HandleSoftwareFault(SoftwareDiagnostics::Events::SoftwareFault::Id); - break; - case SIGUSR2: - PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::HardwareFaultChange::Id); - break; - case SIGHUP: - PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::RadioFaultChange::Id); - break; - case SIGTTIN: - PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::NetworkFaultChange::Id); - break; - default: - break; - } -} - #if CHIP_WITH_GIO void GDBus_Thread() { @@ -175,16 +152,6 @@ void PlatformManagerImpl::WiFIIPChangeListener() CHIP_ERROR PlatformManagerImpl::_InitChipStack() { - struct sigaction action; - - memset(&action, 0, sizeof(action)); - action.sa_handler = SignalHandler; - sigaction(SIGHUP, &action, nullptr); - sigaction(SIGTTIN, &action, nullptr); - sigaction(SIGUSR1, &action, nullptr); - sigaction(SIGUSR2, &action, nullptr); - sigaction(SIGTSTP, &action, nullptr); - #if CHIP_WITH_GIO GError * error = nullptr; @@ -238,91 +205,6 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() return Internal::GenericPlatformManagerImpl_POSIX::_Shutdown(); } -void PlatformManagerImpl::HandleGeneralFault(uint32_t EventId) -{ - GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate(); - - if (delegate == nullptr) - { - ChipLogError(DeviceLayer, "No delegate registered to handle General Diagnostics event"); - return; - } - - if (EventId == GeneralDiagnostics::Events::HardwareFaultChange::Id) - { - GeneralFaults previous; - GeneralFaults current; - -#if CHIP_CONFIG_TEST - // On Linux Simulation, set following hardware faults statically. - ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); - ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); - - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_SENSOR)); - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_USER_INTERFACE_FAULT)); -#endif - delegate->OnHardwareFaultsDetected(previous, current); - } - else if (EventId == GeneralDiagnostics::Events::RadioFaultChange::Id) - { - GeneralFaults previous; - GeneralFaults current; - -#if CHIP_CONFIG_TEST - // On Linux Simulation, set following radio faults statically. - ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); - ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); - - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_CELLULAR_FAULT)); - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_NFC_FAULT)); -#endif - delegate->OnRadioFaultsDetected(previous, current); - } - else if (EventId == GeneralDiagnostics::Events::NetworkFaultChange::Id) - { - GeneralFaults previous; - GeneralFaults current; - -#if CHIP_CONFIG_TEST - // On Linux Simulation, set following radio faults statically. - ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); - ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); - - ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); - ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); - ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_CONNECTION_FAILED)); -#endif - delegate->OnNetworkFaultsDetected(previous, current); - } - else - { - ChipLogError(DeviceLayer, "Unknow event ID:%d", EventId); - } -} - -void PlatformManagerImpl::HandleSoftwareFault(uint32_t EventId) -{ - SoftwareDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetSoftwareDiagnosticsDelegate(); - - if (delegate != nullptr) - { - SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type softwareFault; - char threadName[kMaxThreadNameLength + 1]; - - softwareFault.id = gettid(); - strncpy(threadName, std::to_string(softwareFault.id).c_str(), kMaxThreadNameLength); - threadName[kMaxThreadNameLength] = '\0'; - softwareFault.name = CharSpan::fromCharString(threadName); - softwareFault.faultRecording = ByteSpan(Uint8::from_const_char("FaultRecording"), strlen("FaultRecording")); - - delegate->OnSoftwareFaultDetected(softwareFault); - } -} - #if CHIP_WITH_GIO GDBusConnection * PlatformManagerImpl::GetGDBusConnection() { diff --git a/src/platform/Linux/PlatformManagerImpl.h b/src/platform/Linux/PlatformManagerImpl.h index 37f7cce7edf5ca..591121d0a05e80 100644 --- a/src/platform/Linux/PlatformManagerImpl.h +++ b/src/platform/Linux/PlatformManagerImpl.h @@ -56,9 +56,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener System::Clock::Timestamp GetStartTime() { return mStartTime; } - void HandleGeneralFault(uint32_t EventId); - void HandleSoftwareFault(uint32_t EventId); - private: // ===== Methods that implement the PlatformManager abstract interface. diff --git a/src/platform/webos/PlatformManagerImpl.cpp b/src/platform/webos/PlatformManagerImpl.cpp index 6dfb507b10b6dc..a2e72542b6e58c 100644 --- a/src/platform/webos/PlatformManagerImpl.cpp +++ b/src/platform/webos/PlatformManagerImpl.cpp @@ -60,29 +60,6 @@ PlatformManagerImpl PlatformManagerImpl::sInstance; namespace { -void SignalHandler(int signum) -{ - ChipLogDetail(DeviceLayer, "Caught signal %d", signum); - - switch (signum) - { - case SIGUSR1: - PlatformMgrImpl().HandleSoftwareFault(SoftwareDiagnostics::Events::SoftwareFault::Id); - break; - case SIGUSR2: - PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::HardwareFaultChange::Id); - break; - case SIGHUP: - PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::RadioFaultChange::Id); - break; - case SIGTTIN: - PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::NetworkFaultChange::Id); - break; - default: - break; - } -} - #if CHIP_WITH_GIO void GDBus_Thread() { @@ -171,16 +148,6 @@ void PlatformManagerImpl::WiFIIPChangeListener() CHIP_ERROR PlatformManagerImpl::_InitChipStack() { - struct sigaction action; - - memset(&action, 0, sizeof(action)); - action.sa_handler = SignalHandler; - sigaction(SIGHUP, &action, nullptr); - sigaction(SIGTTIN, &action, nullptr); - sigaction(SIGUSR1, &action, nullptr); - sigaction(SIGUSR2, &action, nullptr); - sigaction(SIGTSTP, &action, nullptr); - #if CHIP_WITH_GIO GError * error = nullptr; @@ -235,93 +202,6 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() return Internal::GenericPlatformManagerImpl_POSIX::_Shutdown(); } -void PlatformManagerImpl::HandleGeneralFault(uint32_t EventId) -{ - GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate(); - - if (delegate == nullptr) - { - ChipLogError(DeviceLayer, "No delegate registered to handle General Diagnostics event"); - return; - } - - if (EventId == GeneralDiagnostics::Events::HardwareFaultChange::Id) - { - GeneralFaults previous; - GeneralFaults current; - -#if CHIP_CONFIG_TEST - // On Linux Simulation, set following hardware faults statically. - ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); - ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); - - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_SENSOR)); - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); - ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_USER_INTERFACE_FAULT)); -#endif - delegate->OnHardwareFaultsDetected(previous, current); - } - else if (EventId == GeneralDiagnostics::Events::RadioFaultChange::Id) - { - GeneralFaults previous; - GeneralFaults current; - -#if CHIP_CONFIG_TEST - // On Linux Simulation, set following radio faults statically. - ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); - ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); - - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_CELLULAR_FAULT)); - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); - ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_NFC_FAULT)); -#endif - delegate->OnRadioFaultsDetected(previous, current); - } - else if (EventId == GeneralDiagnostics::Events::NetworkFaultChange::Id) - { - GeneralFaults previous; - GeneralFaults current; - -#if CHIP_CONFIG_TEST - // On Linux Simulation, set following radio faults statically. - ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); - ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); - - ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); - ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); - ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_CONNECTION_FAILED)); -#endif - delegate->OnNetworkFaultsDetected(previous, current); - } - else - { - ChipLogError(DeviceLayer, "Unknow event ID:%d", EventId); - } -} - -void PlatformManagerImpl::HandleSoftwareFault(uint32_t EventId) -{ - SoftwareDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetSoftwareDiagnosticsDelegate(); - - if (delegate != nullptr) - { - SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type softwareFault; - char threadName[kMaxThreadNameLength + 1]; - - softwareFault.id = gettid(); - strncpy(threadName, std::to_string(softwareFault.id).c_str(), kMaxThreadNameLength); - threadName[kMaxThreadNameLength] = '\0'; - softwareFault.name = CharSpan::fromCharString(threadName); - softwareFault.faultRecording = ByteSpan(Uint8::from_const_char("FaultRecording"), strlen("FaultRecording")); - - delegate->OnSoftwareFaultDetected(softwareFault); - } -} - - - #if CHIP_WITH_GIO GDBusConnection * PlatformManagerImpl::GetGDBusConnection() { diff --git a/src/platform/webos/PlatformManagerImpl.h b/src/platform/webos/PlatformManagerImpl.h index c1808477627f77..bdb6f4dbd46390 100644 --- a/src/platform/webos/PlatformManagerImpl.h +++ b/src/platform/webos/PlatformManagerImpl.h @@ -56,9 +56,6 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener System::Clock::Timestamp GetStartTime() { return mStartTime; } - void HandleGeneralFault(uint32_t EventId); - void HandleSoftwareFault(uint32_t EventId); - private: // ===== Methods that implement the PlatformManager abstract interface.