From 6dbb252ce1001fa6ab7c8281ff8a9e2c48acf91c Mon Sep 17 00:00:00 2001 From: Bernd Weimer Date: Fri, 6 Mar 2020 11:32:55 +0100 Subject: Add API to unregister all DLT contexts The new API unregisters all logging categories and their associated DLT context Ids. This can be used to change log levels: set new rules and unregister all contexts. Change-Id: I1a21dd49d3e3b21fd6f58a2316c60a6f25b29586 Reviewed-by: Dominik Holland --- src/geniviextras/qdltregistration.cpp | 26 +++++++++++++++++++++++++- src/geniviextras/qdltregistration.h | 1 + src/geniviextras/qdltregistration_p.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/geniviextras/qdltregistration.cpp b/src/geniviextras/qdltregistration.cpp index bef94d1..4ba638a 100644 --- a/src/geniviextras/qdltregistration.cpp +++ b/src/geniviextras/qdltregistration.cpp @@ -151,6 +151,16 @@ void QDltRegistrationPrivate::registerCategory(CategoryInfo &info) info.m_registered = true; } +void QDltRegistrationPrivate::unregisterCategories() +{ + for (auto it = m_categoryInfoHash.begin(); it != m_categoryInfoHash.end(); ++it) { + if (it.value().m_registered) { + DLT_UNREGISTER_CONTEXT(*it.value().m_context); + it.value().m_registered = false; + } + } +} + void QDltRegistrationPrivate::registerApplication() { Q_ASSERT_X(!m_dltAppID.isEmpty(), "registerApplication", "dltAppID needs to be a valid char * on the first call."); @@ -431,7 +441,7 @@ void QDltRegistration::registerUnregisteredContexts() for (auto it = d->m_categoryInfoHash.begin(); it != d->m_categoryInfoHash.end(); ++it) { if (!it.value().m_registered) { d->registerCategory(it.value()); - } + } } } @@ -458,6 +468,20 @@ void QDltRegistration::unregisterApplication() d->unregisterApplication(); } +/*! + Unregisters all categories and their associated context Ids from the dlt-daemon. + + One application of this function could be to update the log level: after this function has been + called, all cetegories will be registered again (with new log level), when they are used next + time. +*/ +void QDltRegistration::unregisterCategories() +{ + Q_D(QDltRegistration); + QMutexLocker l(&d->m_mutex); + d->unregisterCategories(); +} + /*! The Qt message handler which forwards all the logging messages to the dlt-daemon. diff --git a/src/geniviextras/qdltregistration.h b/src/geniviextras/qdltregistration.h index 931d164..5afcddc 100644 --- a/src/geniviextras/qdltregistration.h +++ b/src/geniviextras/qdltregistration.h @@ -75,6 +75,7 @@ public: void unregisterApplication(); void registerCategory(const QLoggingCategory *category, const char *dltCtxName, const char *dltCtxDescription); + void unregisterCategories(); void setDefaultContext(const char *categoryName); void setRegisterContextOnFirstUseEnabled(bool enabled); diff --git a/src/geniviextras/qdltregistration_p.h b/src/geniviextras/qdltregistration_p.h index 98542f4..72a12f6 100644 --- a/src/geniviextras/qdltregistration_p.h +++ b/src/geniviextras/qdltregistration_p.h @@ -81,6 +81,7 @@ public: void registerCategory(const QLoggingCategory *category, DltContext *dltContext, const char *dltCtxName, const char *dltCtxDescription); void registerCategory(CategoryInfo &info); + void unregisterCategories(); void registerApplication(); void unregisterApplication(); void setDefaultCategory(const QString &category); -- cgit v1.2.3