Skip to content

Commit 1ca9f99

Browse files
yufengwangcapull[bot]
authored andcommitted
Add diagnostic delegate interfaces for event support (#12451)
1 parent 88876ef commit 1ca9f99

File tree

6 files changed

+144
-20
lines changed

6 files changed

+144
-20
lines changed

src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & a
167167
return CHIP_NO_ERROR;
168168
}
169169

170-
class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegate, public DeviceLayer::DiagnosticsDelegate
170+
class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelegate, public DeviceLayer::GeneralDiagnosticsDelegate
171171
{
172172

173173
// Gets called when any network interface on the Node is updated.
174174
void OnNetworkInfoChanged() override
175175
{
176-
ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnNetworkInfoChanged");
176+
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnNetworkInfoChanged");
177177

178178
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
179179
{
@@ -194,7 +194,7 @@ class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegat
194194
// Gets called when the device has been rebooted.
195195
void OnDeviceRebooted() override
196196
{
197-
ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnDeviceRebooted");
197+
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnDeviceRebooted");
198198

199199
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
200200
{
@@ -217,7 +217,7 @@ class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegat
217217
// Get called when the Node detects a hardware fault has been raised.
218218
void OnHardwareFaultsDetected() override
219219
{
220-
ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnHardwareFaultsDetected");
220+
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
221221

222222
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
223223
{
@@ -238,7 +238,7 @@ class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegat
238238
// Get called when the Node detects a radio fault has been raised.
239239
void OnRadioFaultsDetected() override
240240
{
241-
ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnHardwareFaultsDetected");
241+
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
242242

243243
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
244244
{
@@ -259,7 +259,7 @@ class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegat
259259
// Get called when the Node detects a network fault has been raised.
260260
void OnNetworkFaultsDetected() override
261261
{
262-
ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnHardwareFaultsDetected");
262+
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
263263

264264
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
265265
{
@@ -278,14 +278,14 @@ class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegat
278278
}
279279
};
280280

281-
GeneralDiagnosticDelegate gDiagnosticDelegate;
281+
GeneralDiagnosticsDelegate gDiagnosticDelegate;
282282

283283
} // anonymous namespace
284284

285285
void MatterGeneralDiagnosticsPluginServerInitCallback()
286286
{
287287
registerAttributeAccessOverride(&gAttrAccess);
288288

289-
GetDiagnosticDataProvider().SetDelegate(&gDiagnosticDelegate);
290289
ConnectivityMgr().SetDelegate(&gDiagnosticDelegate);
290+
GetDiagnosticDataProvider().SetGeneralDiagnosticsDelegate(&gDiagnosticDelegate);
291291
}

src/app/clusters/software_diagnostics_server/software_diagnostics_server.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ using namespace chip::app::Clusters;
3333
using namespace chip::app::Clusters::SoftwareDiagnostics;
3434
using namespace chip::app::Clusters::SoftwareDiagnostics::Attributes;
3535
using chip::DeviceLayer::DiagnosticDataProvider;
36+
using chip::DeviceLayer::GetDiagnosticDataProvider;
3637

3738
namespace {
3839

@@ -122,6 +123,15 @@ CHIP_ERROR SoftwareDiagosticsAttrAccess::ReadThreadMetrics(AttributeValueEncoder
122123

123124
return err;
124125
}
126+
127+
class SoftwareDiagnosticsDelegate : public DeviceLayer::SoftwareDiagnosticsDelegate
128+
{
129+
// Gets called when a software fault that has taken place on the Node.
130+
void OnSoftwareFaultDetected() override { ChipLogProgress(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected"); }
131+
};
132+
133+
SoftwareDiagnosticsDelegate gDiagnosticDelegate;
134+
125135
} // anonymous namespace
126136

127137
bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandler * commandObj,
@@ -151,4 +161,5 @@ bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandle
151161
void MatterSoftwareDiagnosticsPluginServerInitCallback()
152162
{
153163
registerAttributeAccessOverride(&gAttrAccess);
164+
GetDiagnosticDataProvider().SetSoftwareDiagnosticsDelegate(&gDiagnosticDelegate);
154165
}

src/app/clusters/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ using namespace chip::app::Clusters;
3333
using namespace chip::app::Clusters::WiFiNetworkDiagnostics;
3434
using namespace chip::app::Clusters::WiFiNetworkDiagnostics::Attributes;
3535
using chip::DeviceLayer::DiagnosticDataProvider;
36+
using chip::DeviceLayer::GetDiagnosticDataProvider;
3637

3738
namespace {
3839

@@ -144,6 +145,21 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPat
144145
}
145146
return CHIP_NO_ERROR;
146147
}
148+
149+
class WiFiDiagnosticsDelegate : public DeviceLayer::WiFiDiagnosticsDelegate
150+
{
151+
// Gets called when the Node detects Node’s Wi-Fi connection has been disconnected.
152+
void OnDisconnectionDetected() override { ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnDisconnectionDetected"); }
153+
154+
// Gets called when the Node fails to associate or authenticate an access point.
155+
void OnAssociationFailureDetected() override { ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnAssociationFailureDetected"); }
156+
157+
// Gets when the Node’s connection status to a Wi-Fi network has changed.
158+
void OnConnectionStatusChanged() override { ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnConnectionStatusChanged"); }
159+
};
160+
161+
WiFiDiagnosticsDelegate gDiagnosticDelegate;
162+
147163
} // anonymous namespace
148164

149165
bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler * commandObj,
@@ -186,4 +202,5 @@ bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler
186202
void MatterWiFiNetworkDiagnosticsPluginServerInitCallback()
187203
{
188204
registerAttributeAccessOverride(&gAttrAccess);
205+
GetDiagnosticDataProvider().SetWiFiDiagnosticsDelegate(&gDiagnosticDelegate);
189206
}

src/include/platform/DiagnosticDataProvider.h

+56-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ struct NetworkInterface : public app::Clusters::GeneralDiagnostics::Structs::Net
5050
};
5151

5252
/**
53-
* Defines the delegate class of Platform Manager to notify platform updates.
53+
* Defines the General Diagnostics Delegate class to notify platform events.
5454
*/
55-
class DiagnosticsDelegate
55+
class GeneralDiagnosticsDelegate
5656
{
5757
public:
58-
virtual ~DiagnosticsDelegate() {}
58+
virtual ~GeneralDiagnosticsDelegate() {}
5959

6060
/**
6161
* @brief
@@ -82,14 +82,62 @@ class DiagnosticsDelegate
8282
virtual void OnNetworkFaultsDetected() {}
8383
};
8484

85+
/**
86+
* Defines the Software Diagnostics Delegate class to notify software events.
87+
*/
88+
class SoftwareDiagnosticsDelegate
89+
{
90+
public:
91+
virtual ~SoftwareDiagnosticsDelegate() {}
92+
93+
/**
94+
* @brief
95+
* Called when a software fault that has taken place on the Node.
96+
*/
97+
virtual void OnSoftwareFaultDetected() {}
98+
};
99+
100+
/**
101+
* Defines the WiFi Diagnostics Delegate class to notify WiFi network events.
102+
*/
103+
class WiFiDiagnosticsDelegate
104+
{
105+
public:
106+
virtual ~WiFiDiagnosticsDelegate() {}
107+
108+
/**
109+
* @brief
110+
* Called when the Node detects Node’s Wi-Fi connection has been disconnected.
111+
*/
112+
virtual void OnDisconnectionDetected() {}
113+
114+
/**
115+
* @brief
116+
* Called when the Node fails to associate or authenticate an access point.
117+
*/
118+
virtual void OnAssociationFailureDetected() {}
119+
120+
/**
121+
* @brief
122+
* Called when the Node’s connection status to a Wi-Fi network has changed.
123+
*/
124+
virtual void OnConnectionStatusChanged() {}
125+
};
126+
85127
/**
86128
* Provides access to runtime and build-time configuration information for a chip device.
87129
*/
88130
class DiagnosticDataProvider
89131
{
90132
public:
91-
void SetDelegate(DiagnosticsDelegate * delegate) { mDelegate = delegate; }
92-
DiagnosticsDelegate * GetDelegate() const { return mDelegate; }
133+
void SetGeneralDiagnosticsDelegate(GeneralDiagnosticsDelegate * delegate) { mGeneralDiagnosticsDelegate = delegate; }
134+
GeneralDiagnosticsDelegate * GetGeneralDiagnosticsDelegate() const { return mGeneralDiagnosticsDelegate; }
135+
136+
void SetSoftwareDiagnosticsDelegate(SoftwareDiagnosticsDelegate * delegate) { mSoftwareDiagnosticsDelegate = delegate; }
137+
SoftwareDiagnosticsDelegate * GetSoftwareDiagnosticsDelegate() const { return mSoftwareDiagnosticsDelegate; }
138+
139+
void SetWiFiDiagnosticsDelegate(WiFiDiagnosticsDelegate * delegate) { mWiFiDiagnosticsDelegate = delegate; }
140+
WiFiDiagnosticsDelegate * GetWiFiDiagnosticsDelegate() const { return mWiFiDiagnosticsDelegate; }
93141

94142
/**
95143
* General Diagnostics methods.
@@ -163,7 +211,9 @@ class DiagnosticDataProvider
163211
virtual ~DiagnosticDataProvider() = default;
164212

165213
private:
166-
DiagnosticsDelegate * mDelegate = nullptr;
214+
GeneralDiagnosticsDelegate * mGeneralDiagnosticsDelegate = nullptr;
215+
SoftwareDiagnosticsDelegate * mSoftwareDiagnosticsDelegate = nullptr;
216+
WiFiDiagnosticsDelegate * mWiFiDiagnosticsDelegate = nullptr;
167217

168218
// No copy, move or assignment.
169219
DiagnosticDataProvider(const DiagnosticDataProvider &) = delete;

src/platform/Linux/PlatformManagerImpl.cpp

+49-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <signal.h>
4343
#include <unistd.h>
4444

45+
using namespace ::chip::app::Clusters;
46+
4547
namespace chip {
4648
namespace DeviceLayer {
4749

@@ -84,19 +86,27 @@ void SignalHandler(int signum)
8486
ConfigurationMgr().StoreBootReason(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_UPDATE_COMPLETED);
8587
err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED;
8688
break;
89+
case SIGTRAP:
90+
PlatformMgrImpl().HandleSoftwareFault(SoftwareDiagnostics::Events::SoftwareFault::kEventId);
91+
break;
92+
case SIGILL:
93+
PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::HardwareFaultChange::kEventId);
94+
break;
95+
case SIGALRM:
96+
PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::RadioFaultChange::kEventId);
97+
break;
98+
case SIGVTALRM:
99+
PlatformMgrImpl().HandleGeneralFault(GeneralDiagnostics::Events::NetworkFaultChange::kEventId);
100+
break;
87101
default:
88102
break;
89103
}
90104

91-
if (err != CHIP_NO_ERROR)
105+
if (err == CHIP_ERROR_REBOOT_SIGNAL_RECEIVED)
92106
{
93107
PlatformMgr().Shutdown();
94108
exit(EXIT_FAILURE);
95109
}
96-
else
97-
{
98-
ChipLogDetail(DeviceLayer, "Ignore signal %d", signum);
99-
}
100110
}
101111

102112
#if CHIP_WITH_GIO
@@ -253,14 +263,47 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown()
253263

254264
void PlatformManagerImpl::HandleDeviceRebooted(intptr_t arg)
255265
{
256-
DiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetDelegate();
266+
GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();
257267

258268
if (delegate != nullptr)
259269
{
260270
delegate->OnDeviceRebooted();
261271
}
262272
}
263273

274+
void PlatformManagerImpl::HandleGeneralFault(uint32_t EventId)
275+
{
276+
GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();
277+
278+
if (delegate != nullptr)
279+
{
280+
switch (EventId)
281+
{
282+
case GeneralDiagnostics::Events::HardwareFaultChange::kEventId:
283+
delegate->OnHardwareFaultsDetected();
284+
break;
285+
case GeneralDiagnostics::Events::RadioFaultChange::kEventId:
286+
delegate->OnRadioFaultsDetected();
287+
break;
288+
case GeneralDiagnostics::Events::NetworkFaultChange::kEventId:
289+
delegate->OnNetworkFaultsDetected();
290+
break;
291+
default:
292+
break;
293+
}
294+
}
295+
}
296+
297+
void PlatformManagerImpl::HandleSoftwareFault(uint32_t EventId)
298+
{
299+
SoftwareDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetSoftwareDiagnosticsDelegate();
300+
301+
if (delegate != nullptr)
302+
{
303+
delegate->OnSoftwareFaultDetected();
304+
}
305+
}
306+
264307
#if CHIP_WITH_GIO
265308
GDBusConnection * PlatformManagerImpl::GetGDBusConnection()
266309
{

src/platform/Linux/PlatformManagerImpl.h

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
5656

5757
System::Clock::Timestamp GetStartTime() { return mStartTime; }
5858

59+
void HandleGeneralFault(uint32_t EventId);
60+
void HandleSoftwareFault(uint32_t EventId);
61+
5962
private:
6063
// ===== Methods that implement the PlatformManager abstract interface.
6164

0 commit comments

Comments
 (0)