Skip to content

Commit

Permalink
We should not call SetDiagnosticDataProvider within PaltformMgr on ea… (
Browse files Browse the repository at this point in the history
#20806)

* We should not call SetDiagnosticDataProvider within PaltformMgr on each platfrom

* Update src/include/platform/DiagnosticDataProvider.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Allow app to overwrite the default implantation of DiagnosticDataProvider

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 1, 2023
1 parent 6dd0178 commit 0331547
Show file tree
Hide file tree
Showing 58 changed files with 267 additions and 22 deletions.
15 changes: 13 additions & 2 deletions src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct NetworkInterface : public app::Clusters::GeneralDiagnostics::Structs::Net
NetworkInterface * Next; /* Pointer to the next structure. */
};

class DiagnosticDataProviderImpl;

/**
* Defines the WiFi Diagnostics Delegate class to notify WiFi network events.
*/
Expand Down Expand Up @@ -184,12 +186,21 @@ class DiagnosticDataProvider
};

/**
* Returns a reference to a DiagnosticDataProvider object.
* Returns a reference to the public interface of the DiagnosticDataProvider singleton object.
*
* Applications should use this to access the features of the DiagnosticDataProvider.
* Applications should use this to access features of the DiagnosticDataProvider object
* that are common to all platforms.
*/
DiagnosticDataProvider & GetDiagnosticDataProvider();

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
extern DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

/**
* Sets a reference to a DiagnosticDataProvider object.
*
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Ameba/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts()
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Ameba/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
#endif
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Ameba/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
CHIP_ERROR err;

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

// Make sure the LwIP core lock has been initialized
err = Internal::InitLwIPCoreLock();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/CYW30739/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,10 @@ void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * net
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/CYW30739/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/CYW30739/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
SuccessOrExit(err);

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

/* Create the thread object. */
mThread = wiced_rtos_create_thread();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Darwin/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()
return CHIP_NO_ERROR;
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Darwin/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
CHIP_ERROR ResetWatermarks() override;
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Darwin/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());
#endif // CHIP_DISABLE_PLATFORM_KVS
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

mRunLoopSem = dispatch_semaphore_create(0);

Expand Down
9 changes: 7 additions & 2 deletions src/platform/DiagnosticDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <lib/support/CodeUtils.h>
#include <platform/DiagnosticDataProvider.h>

namespace chip {
namespace DeviceLayer {
Expand All @@ -37,8 +38,12 @@ DiagnosticDataProvider * gInstance = nullptr;

DiagnosticDataProvider & GetDiagnosticDataProvider()
{
VerifyOrDie(gInstance != nullptr);
return *gInstance;
if (gInstance != nullptr)
{
return *gInstance;
}

return GetDiagnosticDataProviderImpl();
}

void SetDiagnosticDataProvider(DiagnosticDataProvider * diagnosticDataProvider)
Expand Down
5 changes: 5 additions & 0 deletions src/platform/EFR32/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts()
}
#endif // SL_WIFI

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/EFR32/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
#endif // SL_WIFI
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/EFR32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
SuccessOrExit(err);

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

#if CHIP_SYSTEM_CONFIG_USE_LWIP
// Initialize LwIP.
Expand Down
5 changes: 5 additions & 0 deletions src/platform/ESP32/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWiFiNetworkDiagnosticsCounts()
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/ESP32/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/ESP32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s
CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());
SetDeviceInfoProvider(&DeviceInfoProviderImpl::GetDefaultInstance());

esp_err_t err;
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Linux/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,5 +826,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiSecurityType(uint8_t & securityTyp
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Linux/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
#endif
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
// Initialize the configuration system.
ReturnErrorOnFailure(Internal::PosixConfig::Init());
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());

// Call _InitChipStack() on the generic implementation base class
Expand Down
5 changes: 5 additions & 0 deletions src/platform/P6/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,5 +543,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::WiFiCounters(WiFiStatsCountType type, uin
return err;
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/P6/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
app::DataModel::Nullable<bool> mipv6_offpremise;
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/P6/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
CHIP_ERROR err;

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

// Make sure the LwIP core lock has been initialized
err = Internal::InitLwIPCoreLock();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Tizen/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance()
return sInstance;
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Tizen/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
static DiagnosticDataProviderImpl & GetDefaultInstance();
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Tizen/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
ReturnErrorOnFailure(Internal::PosixConfig::Init());
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());

return Internal::GenericPlatformManagerImpl_POSIX<PlatformManagerImpl>::_InitChipStack();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,10 @@ void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * net
}
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Zephyr/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
const BootReasonType mBootReason;
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Zephyr/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
err = Internal::ZephyrConfig::Init();
SuccessOrExit(err);
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

#if !CONFIG_NORDIC_SECURITY_BACKEND
// Add entropy source based on Zephyr entropy driver
Expand Down
5 changes: 5 additions & 0 deletions src/platform/android/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,10 @@ void DiagnosticDataProviderImpl::ReleaseNetworkInterfaces(NetworkInterface * net
}
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/android/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
jmethodID mGetNifMethod = nullptr;
};

/**
* Returns the platform-specific implementation of the DiagnosticDataProvider singleton object.
*
* Applications can use this to gain access to features of the DiagnosticDataProvider
* that are specific to the selected platform.
*/
DiagnosticDataProvider & GetDiagnosticDataProviderImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/android/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
err = Internal::AndroidConfig::Init();
SuccessOrExit(err);
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());

// Call _InitChipStack() on the generic implementation base class
Expand Down
5 changes: 5 additions & 0 deletions src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,10 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason
return err;
}

DiagnosticDataProvider & GetDiagnosticDataProviderImpl()
{
return DiagnosticDataProviderImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
Loading

0 comments on commit 0331547

Please sign in to comment.