diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2016-11-25 13:45:36 +0100 |
---|---|---|
committer | Robert Griebl <robert.griebl@pelagicore.com> | 2016-11-29 23:24:08 +0000 |
commit | 1163c5e8e269d73b4e422a12e47f7db34285c4a0 (patch) | |
tree | d0184f5a63d94de189825de84cfe496ba11071ba /src/geniviextras/qdltregistration.cpp | |
parent | 465f64cdd9a6f97893e77c9b46bfd1a2f830084d (diff) |
Make it possible to change the DLT appID and description once registered
By unregistering and registering the app with the new appID it is
possible to enforce a change of the appID. This is useful for
applications/libraries which act as launchers where it is not clear
what will be the final appID at compile-time.
Change-Id: Id6dc8192e199e6366aa912dd37171ce3f7a698ef
Reviewed-by: Johan Thelin <johan.thelin@pelagicore.com>
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src/geniviextras/qdltregistration.cpp')
-rw-r--r-- | src/geniviextras/qdltregistration.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/geniviextras/qdltregistration.cpp b/src/geniviextras/qdltregistration.cpp index 6f61eac..65536cb 100644 --- a/src/geniviextras/qdltregistration.cpp +++ b/src/geniviextras/qdltregistration.cpp @@ -206,14 +206,39 @@ QDltRegistration::~QDltRegistration() /*! Registers this application with the dlt-daemon using \a dltAppID and \a dltAppDescription. - This function shouldn't be used directly, instead use the convenience macro. + Per process only one application can be registered. Calling this function after an + application is already registered, will register the application under the new \a dltAppID + and \a dltAppDescription and also populating the already registered dlt contexts under this + application. Calling the method with an empty \a dltAppID will update just the description + if the app was already registered before. + \sa QDLT_REGISTER_APPLICATION */ void QDltRegistration::registerApplication(const char *dltAppID, const char *dltAppDescription) { Q_D(QDltRegistration); - d->m_dltAppID = QString::fromLatin1(dltAppID); - DLT_REGISTER_APP(dltAppID, dltAppDescription); + bool registerCategories = false; + if (!d->m_dltAppID.isEmpty()) { + DLT_UNREGISTER_APP(); + registerCategories = true; + } + + if (dltAppID) + d->m_dltAppID = QString::fromLatin1(dltAppID); + + Q_ASSERT_X(!d->m_dltAppID.isEmpty(), "registerApplication", "dltAppID needs to be a valid char * on the first call."); + + DLT_REGISTER_APP(d->m_dltAppID.toLocal8Bit(), dltAppDescription); + + //Register all Contexts which already have been registered again under the new application + if (registerCategories) { + for (auto it = d->m_categoryInfoHash.cbegin(); it != d->m_categoryInfoHash.cend(); ++it) { + if (it.value().m_registered) { + DLT_REGISTER_CONTEXT_LL_TS(*it.value().m_context, it.value().m_ctxName, it.value().m_ctxDescription, d->category2dltLevel(it.value().m_category), DLT_TRACE_STATUS_DEFAULT); + DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(*it.value().m_context, &qtGeniviLogLevelChangedHandler); + } + } + } } /*! @@ -263,6 +288,7 @@ void QDltRegistration::registerUnregisteredContexts() for (auto it = d->m_categoryInfoHash.begin(); it != d->m_categoryInfoHash.end(); ++it) { if (!it.value().m_registered) { DLT_REGISTER_CONTEXT_LL_TS(*it.value().m_context, it.value().m_ctxName, it.value().m_ctxDescription, d->category2dltLevel(it.value().m_category), DLT_TRACE_STATUS_DEFAULT); + DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(*it.value().m_context, &qtGeniviLogLevelChangedHandler); it.value().m_registered = true; } } |