15
15
* limitations under the License.
16
16
*/
17
17
18
+ #include " wifi-network-diagnostics-server.h"
18
19
#include < app-common/zap-generated/attributes/Accessors.h>
19
20
#include < app-common/zap-generated/cluster-objects.h>
20
21
#include < app-common/zap-generated/ids/Attributes.h>
26
27
#include < app/EventLogging.h>
27
28
#include < app/util/attribute-storage.h>
28
29
#include < lib/core/Optional.h>
29
- #include < platform/DiagnosticDataProvider.h>
30
30
#include < tracing/macros.h>
31
31
#include < tracing/metric_event.h>
32
32
@@ -240,70 +240,81 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPat
240
240
return CHIP_NO_ERROR;
241
241
}
242
242
243
- class WiFiDiagnosticsDelegate : public DeviceLayer ::WiFiDiagnosticsDelegate
243
+ } // anonymous namespace
244
+
245
+ namespace chip {
246
+ namespace app {
247
+ namespace Clusters {
248
+
249
+ WiFiDiagnosticsServer WiFiDiagnosticsServer::instance;
250
+
251
+ /* *********************************************************
252
+ * WiFiDiagnosticsServer Implementation
253
+ *********************************************************/
254
+
255
+ WiFiDiagnosticsServer & WiFiDiagnosticsServer::Instance ()
256
+ {
257
+ return instance;
258
+ }
259
+
260
+ void WiFiDiagnosticsServer::OnDisconnectionDetected (uint16_t reasonCode)
244
261
{
245
- // Gets called when the Node detects Node’s Wi-Fi connection has been disconnected.
246
- void OnDisconnectionDetected (uint16_t reasonCode) override
262
+ MATTER_TRACE_SCOPE (" OnDisconnectionDetected" , " WiFiDiagnosticsDelegate" );
263
+ ChipLogProgress (Zcl, " WiFiDiagnosticsDelegate: OnDisconnectionDetected" );
264
+
265
+ for (auto endpoint : EnabledEndpointsWithServerCluster (WiFiNetworkDiagnostics::Id))
247
266
{
248
- MATTER_TRACE_SCOPE (" OnDisconnectionDetected" , " WiFiDiagnosticsDelegate" );
249
- ChipLogProgress (Zcl, " WiFiDiagnosticsDelegate: OnDisconnectionDetected" );
267
+ // If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
268
+ Events::Disconnection::Type event{ reasonCode };
269
+ EventNumber eventNumber;
250
270
251
- for ( auto endpoint : EnabledEndpointsWithServerCluster (WiFiNetworkDiagnostics::Id ))
271
+ if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber ))
252
272
{
253
- // If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
254
- Events::Disconnection::Type event{ reasonCode };
255
- EventNumber eventNumber;
256
-
257
- if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
258
- {
259
- ChipLogError (Zcl, " WiFiDiagnosticsDelegate: Failed to record Disconnection event" );
260
- }
273
+ ChipLogError (Zcl, " WiFiDiagnosticsDelegate: Failed to record Disconnection event" );
261
274
}
262
275
}
276
+ }
263
277
264
- // Gets called when the Node fails to associate or authenticate an access point.
265
- void OnAssociationFailureDetected (uint8_t associationFailureCause, uint16_t status) override
266
- {
267
- MATTER_TRACE_SCOPE (" OnAssociationFailureDetected" , " WiFiDiagnosticsDelegate" );
268
- ChipLogProgress (Zcl, " WiFiDiagnosticsDelegate: OnAssociationFailureDetected" );
278
+ void WiFiDiagnosticsServer::OnAssociationFailureDetected (uint8_t associationFailureCause, uint16_t status)
279
+ {
280
+ MATTER_TRACE_SCOPE (" OnAssociationFailureDetected" , " WiFiDiagnosticsDelegate" );
281
+ ChipLogProgress (Zcl, " WiFiDiagnosticsDelegate: OnAssociationFailureDetected" );
269
282
270
- Events::AssociationFailure::Type event{ static_cast <AssociationFailureCauseEnum>(associationFailureCause), status };
283
+ Events::AssociationFailure::Type event{ static_cast <AssociationFailureCauseEnum>(associationFailureCause), status };
271
284
272
- for (auto endpoint : EnabledEndpointsWithServerCluster (WiFiNetworkDiagnostics::Id))
273
- {
274
- // If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
275
- EventNumber eventNumber;
285
+ for (auto endpoint : EnabledEndpointsWithServerCluster (WiFiNetworkDiagnostics::Id))
286
+ {
287
+ // If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
288
+ EventNumber eventNumber;
276
289
277
- if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
278
- {
279
- ChipLogError (Zcl, " WiFiDiagnosticsDelegate: Failed to record AssociationFailure event" );
280
- }
290
+ if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
291
+ {
292
+ ChipLogError (Zcl, " WiFiDiagnosticsDelegate: Failed to record AssociationFailure event" );
281
293
}
282
294
}
295
+ }
296
+
297
+ void WiFiDiagnosticsServer::OnConnectionStatusChanged (uint8_t connectionStatus)
298
+ {
299
+ MATTER_TRACE_SCOPE (" OnConnectionStatusChanged" , " WiFiDiagnosticsDelegate" );
300
+ ChipLogProgress (Zcl, " WiFiDiagnosticsDelegate: OnConnectionStatusChanged" );
283
301
284
- // Gets when the Node’s connection status to a Wi-Fi network has changed.
285
- void OnConnectionStatusChanged ( uint8_t connectionStatus) override
302
+ Events::ConnectionStatus::Type event{ static_cast <ConnectionStatusEnum>(connectionStatus) };
303
+ for ( auto endpoint : EnabledEndpointsWithServerCluster (WiFiNetworkDiagnostics::Id))
286
304
{
287
- MATTER_TRACE_SCOPE ( " OnConnectionStatusChanged " , " WiFiDiagnosticsDelegate " );
288
- ChipLogProgress (Zcl, " WiFiDiagnosticsDelegate: OnConnectionStatusChanged " ) ;
305
+ // If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
306
+ EventNumber eventNumber ;
289
307
290
- Events::ConnectionStatus::Type event{ static_cast <ConnectionStatusEnum>(connectionStatus) };
291
- for (auto endpoint : EnabledEndpointsWithServerCluster (WiFiNetworkDiagnostics::Id))
308
+ if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
292
309
{
293
- // If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
294
- EventNumber eventNumber;
295
-
296
- if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
297
- {
298
- ChipLogError (Zcl, " WiFiDiagnosticsDelegate: Failed to record ConnectionStatus event" );
299
- }
310
+ ChipLogError (Zcl, " WiFiDiagnosticsDelegate: Failed to record ConnectionStatus event" );
300
311
}
301
312
}
302
- };
303
-
304
- WiFiDiagnosticsDelegate gDiagnosticDelegate ;
313
+ }
305
314
306
- } // anonymous namespace
315
+ } // namespace Clusters
316
+ } // namespace app
317
+ } // namespace chip
307
318
308
319
bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback (app::CommandHandler * commandObj,
309
320
const app::ConcreteCommandPath & commandPath,
@@ -318,5 +329,5 @@ bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler
318
329
void MatterWiFiNetworkDiagnosticsPluginServerInitCallback ()
319
330
{
320
331
AttributeAccessInterfaceRegistry::Instance ().Register (&gAttrAccess );
321
- GetDiagnosticDataProvider ().SetWiFiDiagnosticsDelegate (&gDiagnosticDelegate );
332
+ GetDiagnosticDataProvider ().SetWiFiDiagnosticsDelegate (&WiFiDiagnosticsServer::Instance () );
322
333
}
0 commit comments