mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
cscore: Add Shutdown() function
This allows ordered shutdown / destruction of sources and sinks prior to global singleton destruction.
This commit is contained in:
@@ -45,8 +45,17 @@ Instance::Instance() : telemetry(notifier), networkListener(logger, notifier) {
|
||||
Instance::~Instance() {}
|
||||
|
||||
Instance& Instance::GetInstance() {
|
||||
static Instance inst;
|
||||
return inst;
|
||||
static Instance* inst = new Instance;
|
||||
return *inst;
|
||||
}
|
||||
|
||||
void Instance::Shutdown() {
|
||||
eventLoop.Stop();
|
||||
m_sinks.FreeAll();
|
||||
m_sources.FreeAll();
|
||||
networkListener.Stop();
|
||||
telemetry.Stop();
|
||||
notifier.Stop();
|
||||
}
|
||||
|
||||
void Instance::SetDefaultLogger() { logger.SetLogger(def_log_func); }
|
||||
|
||||
@@ -51,6 +51,8 @@ class Instance {
|
||||
|
||||
static Instance& GetInstance();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
wpi::Logger logger;
|
||||
Notifier notifier;
|
||||
Telemetry telemetry;
|
||||
|
||||
@@ -348,6 +348,8 @@ void CS_SetDefaultLogger(unsigned int min_level) {
|
||||
cs::SetDefaultLogger(min_level);
|
||||
}
|
||||
|
||||
void CS_Shutdown(void) { cs::Shutdown(); }
|
||||
|
||||
CS_Source* CS_EnumerateSources(int* count, CS_Status* status) {
|
||||
wpi::SmallVector<CS_Source, 32> buf;
|
||||
auto handles = cs::EnumerateSourceHandles(buf, status);
|
||||
|
||||
@@ -665,6 +665,11 @@ void SetDefaultLogger(unsigned int min_level) {
|
||||
inst.logger.set_min_level(min_level);
|
||||
}
|
||||
|
||||
//
|
||||
// Shutdown Function
|
||||
//
|
||||
void Shutdown() { Instance::GetInstance().Shutdown(); }
|
||||
|
||||
//
|
||||
// Utility Functions
|
||||
//
|
||||
|
||||
@@ -87,6 +87,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||||
cs::Shutdown();
|
||||
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
|
||||
return;
|
||||
|
||||
@@ -440,6 +440,13 @@ void CS_SetLogger(CS_LogFunc func, unsigned int min_level);
|
||||
void CS_SetDefaultLogger(unsigned int min_level);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_shutdown_cfunc Library Shutdown Function
|
||||
* @{
|
||||
*/
|
||||
void CS_Shutdown(void);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_utility_cfunc Utility Functions
|
||||
* @{
|
||||
|
||||
@@ -377,6 +377,13 @@ void SetLogger(LogFunc func, unsigned int min_level);
|
||||
void SetDefaultLogger(unsigned int min_level);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_shutdown_func Library Shutdown Function
|
||||
* @{
|
||||
*/
|
||||
void Shutdown();
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_utility_func Utility Functions
|
||||
* @{
|
||||
|
||||
Reference in New Issue
Block a user