diff options
-rw-r--r-- | src/geniviextras/qdltregistration.cpp | 75 | ||||
-rw-r--r-- | src/geniviextras/qdltregistration_p.h | 7 | ||||
-rw-r--r-- | src/ivicore/qivipendingreply.h | 8 | ||||
-rw-r--r-- | src/ivicore/qivisimulationproxy.h | 4 |
4 files changed, 65 insertions, 29 deletions
diff --git a/src/geniviextras/qdltregistration.cpp b/src/geniviextras/qdltregistration.cpp index a82e173..47abe21 100644 --- a/src/geniviextras/qdltregistration.cpp +++ b/src/geniviextras/qdltregistration.cpp @@ -55,7 +55,13 @@ QT_BEGIN_NAMESPACE void qtGeniviLogLevelChangedHandler(char context_id[], uint8_t log_level, uint8_t trace_status) { - globalDltRegistration()->d_ptr->dltLogLevelChanged(context_id, log_level, trace_status); + auto d = globalDltRegistration()->d_ptr; + d->m_mutex.lock(); + const QLoggingCategory *category = d->dltLogLevelChanged(context_id, log_level, trace_status); + d->m_mutex.unlock(); + + if (category) + emit globalDltRegistration()->logLevelChanged(category); } Q_GLOBAL_STATIC(QDltRegistration, dltRegistration) @@ -112,6 +118,14 @@ void QDltRegistrationPrivate::registerApplication() m_dltAppRegistered = true; } +void QDltRegistrationPrivate::unregisterApplication() +{ + if (m_dltAppRegistered) + DLT_UNREGISTER_APP(); + + m_dltAppRegistered = false; +} + void QDltRegistrationPrivate::setDefaultCategory(const QString &category) { Q_ASSERT_X(m_categoryInfoHash.contains(category), "setDefaultContext", "The category needs to be registered as a dlt logging category before it can be set as a default context"); @@ -134,11 +148,12 @@ DltContext *QDltRegistrationPrivate::context(const char *categoryName) return info.m_context; } -void QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_level, uint8_t trace_status) +const QLoggingCategory * QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_level, uint8_t trace_status) { - Q_Q(QDltRegistration); Q_UNUSED(trace_status) + const QLoggingCategory *changedCategory = nullptr; + for (auto it = m_categoryInfoHash.begin(); it != m_categoryInfoHash.end(); ++it) { if (it.value().m_ctxName != context_id) continue; @@ -181,10 +196,13 @@ void QDltRegistrationPrivate::dltLogLevelChanged(char context_id[], uint8_t log_ QLoggingCategory* category = it.value().m_category; if (category->isEnabled(type) != enabled) { category->setEnabled(type, enabled); - emit q->logLevelChanged(category); + changedCategory = category; } } + break; } + + return changedCategory; } DltLogLevelType QDltRegistrationPrivate::category2dltLevel(const QLoggingCategory *category) @@ -205,6 +223,20 @@ DltLogLevelType QDltRegistrationPrivate::category2dltLevel(const QLoggingCategor return logLevel; } +DltLogLevelType QDltRegistrationPrivate::severity2dltLevel(QtMsgType type) +{ + switch (type) { + case QtDebugMsg: return DLT_LOG_DEBUG; +#if QT_VERSION >= 0x050500 + case QtInfoMsg: return DLT_LOG_INFO; +#endif + case QtWarningMsg: return DLT_LOG_WARN; + case QtCriticalMsg: return DLT_LOG_ERROR; + case QtFatalMsg: return DLT_LOG_FATAL; + } + return DLT_LOG_OFF; +} + /*! \class QDltRegistration \inmodule QtGeniviExtras @@ -243,8 +275,10 @@ void QDltRegistration::registerApplication(const char *dltAppID, const char *dlt { Q_D(QDltRegistration); bool registerCategories = false; + QMutexLocker l(&d->m_mutex); + if (d->m_dltAppRegistered) { - unregisterApplication(); + d->unregisterApplication(); registerCategories = true; } @@ -275,6 +309,7 @@ void QDltRegistration::registerCategory(const QLoggingCategory *category, const Q_D(QDltRegistration); Q_ASSERT(category); Q_ASSERT(strlen(category->categoryName()) != 0); + QMutexLocker l(&d->m_mutex); d->registerCategory(category, new DltContext, dltCtxName, dltCtxDescription); } @@ -290,6 +325,7 @@ void QDltRegistration::registerCategory(const QLoggingCategory *category, const void QDltRegistration::setDefaultContext(const char *categoryName) { Q_D(QDltRegistration); + QMutexLocker l(&d->m_mutex); d->setDefaultCategory(QString::fromLatin1(categoryName)); } @@ -305,6 +341,7 @@ void QDltRegistration::setDefaultContext(const char *categoryName) void QDltRegistration::setRegisterContextOnFirstUseEnabled(bool enabled) { Q_D(QDltRegistration); + QMutexLocker l(&d->m_mutex); d->m_registerOnFirstUse = enabled; } @@ -323,6 +360,7 @@ void QDltRegistration::registerUnregisteredContexts() std::cout << "REGISTERING UNREGISTERED CONTEXTS" << std::endl; #endif Q_D(QDltRegistration); + QMutexLocker l(&d->m_mutex); if (!d->m_dltAppRegistered) d->registerApplication(); for (auto it = d->m_categoryInfoHash.begin(); it != d->m_categoryInfoHash.end(); ++it) { @@ -339,10 +377,8 @@ void QDltRegistration::registerUnregisteredContexts() void QDltRegistration::unregisterApplication() { Q_D(QDltRegistration); - if (d->m_dltAppRegistered) - DLT_UNREGISTER_APP(); - - d->m_dltAppRegistered = false; + QMutexLocker l(&d->m_mutex); + d->unregisterApplication(); } /*! @@ -359,25 +395,20 @@ void QDltRegistration::unregisterApplication() qInstallMessageHandler(QDltRegistration::messageHandler); \endcode */ -void QDltRegistration::messageHandler(QtMsgType msgTypes, const QMessageLogContext &msgCtx, const QString &msg) +void QDltRegistration::messageHandler(QtMsgType msgType, const QMessageLogContext &msgCtx, const QString &msg) { + if (!globalDltRegistration()) + return; + + QMutexLocker l(&globalDltRegistration()->d_ptr->m_mutex); + DltContext *dltCtx = globalDltRegistration()->d_ptr->context(msgCtx.category); if (!dltCtx) return; - DltLogLevelType logLevel = DLT_LOG_OFF; - - switch (msgTypes) { - case QtDebugMsg: logLevel = DLT_LOG_DEBUG; break; -#if QT_VERSION >= 0x050500 - case QtInfoMsg: logLevel = DLT_LOG_INFO; break; -#endif - case QtWarningMsg: logLevel = DLT_LOG_WARN; break; - case QtCriticalMsg: logLevel = DLT_LOG_ERROR; break; - case QtFatalMsg: logLevel = DLT_LOG_FATAL; break; - } + DltLogLevelType logLevel = globalDltRegistration()->d_ptr->severity2dltLevel(msgType); - DLT_LOG(*dltCtx, logLevel, DLT_STRING(qPrintable(qFormatLogMessage(msgTypes, msgCtx, msg)))); + DLT_LOG(*dltCtx, logLevel, DLT_STRING(qPrintable(qFormatLogMessage(msgType, msgCtx, msg)))); } /*! diff --git a/src/geniviextras/qdltregistration_p.h b/src/geniviextras/qdltregistration_p.h index 93f178a..f03dda5 100644 --- a/src/geniviextras/qdltregistration_p.h +++ b/src/geniviextras/qdltregistration_p.h @@ -43,6 +43,7 @@ #include <private/qgeniviextrasglobal_p.h> #include <QString> #include <QHash> +#include <QMutex> #include <dlt.h> @@ -82,15 +83,17 @@ public: void registerCategory(const QLoggingCategory *category, DltContext *dltContext, const char *dltCtxName, const char *dltCtxDescription); void registerCategory(CategoryInfo &info); void registerApplication(); + void unregisterApplication(); void setDefaultCategory(const QString &category); DltContext *context(const char *categoryName); - void dltLogLevelChanged(char context_id[], uint8_t log_level, uint8_t trace_status); + const QLoggingCategory *dltLogLevelChanged(char context_id[], uint8_t log_level, uint8_t trace_status); static DltLogLevelType category2dltLevel(const QLoggingCategory *category); static DltLogLevelType severity2dltLevel(QtMsgType type); private: + mutable QMutex m_mutex; QDltRegistration *const q_ptr; Q_DECLARE_PUBLIC(QDltRegistration) QString m_dltAppID; @@ -99,6 +102,8 @@ private: QString m_defaultCategory; QHash<QString, CategoryInfo> m_categoryInfoHash; bool m_registerOnFirstUse; + + friend void qtGeniviLogLevelChangedHandler(char context_id[], uint8_t log_level, uint8_t trace_status); }; QT_END_NAMESPACE diff --git a/src/ivicore/qivipendingreply.h b/src/ivicore/qivipendingreply.h index 45cb5b6..5536e75 100644 --- a/src/ivicore/qivipendingreply.h +++ b/src/ivicore/qivipendingreply.h @@ -130,9 +130,9 @@ public: using QIviPendingReplyBase::setSuccess; - void setSuccess(const T &value) + void setSuccess(const T &val) { - setSuccessNoCheck(QVariant::fromValue(value)); + setSuccessNoCheck(QVariant::fromValue(val)); } T reply() const { return m_watcher->value().template value<T>(); } @@ -181,9 +181,9 @@ public: : QIviPendingReplyBase(qMetaTypeId<QVariant>()) {} - void setSuccess(const QVariant &value) + void setSuccess(const QVariant &val) { - setSuccessNoCheck(value); + setSuccessNoCheck(val); } QVariant reply() const { return m_watcher->value(); } diff --git a/src/ivicore/qivisimulationproxy.h b/src/ivicore/qivisimulationproxy.h index 3930ce7..99cfc6a 100644 --- a/src/ivicore/qivisimulationproxy.h +++ b/src/ivicore/qivisimulationproxy.h @@ -127,8 +127,8 @@ namespace qtivi_private { template <typename T> class QIviSimulationProxy: public QIviSimulationProxyBase { public: - QIviSimulationProxy(QObject *parent=nullptr) - : QIviSimulationProxyBase(&staticMetaObject, m_instance, methodMap(), parent) + QIviSimulationProxy(QObject *p=nullptr) + : QIviSimulationProxyBase(&staticMetaObject, m_instance, methodMap(), p) { Q_ASSERT_X(m_instance, "QIviSimulationProxy()", "QIviSimulationProxy::registerInstance needs to be called first"); } |