diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2015-06-08 19:59:29 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2015-06-08 19:59:29 +0200 |
commit | 1df246d40784d33ec6aef700c3b482cabc47b543 (patch) | |
tree | dcc0af983e8d9bba744febbeb0485facd5526977 | |
download | qtivi-1df246d40784d33ec6aef700c3b482cabc47b543.tar.gz |
First version of the QtGeniviExtras module
This version contains helper macros which makes it easy to map
QtLoggingCategories to DLT Categories and install a messagHandler
which logs all messages using libdlt
-rw-r--r-- | .gitattributes | 4 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .qmake.conf | 3 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | config.tests/dlt/dlt.pro | 12 | ||||
-rw-r--r-- | config.tests/dlt/main.cpp | 46 | ||||
-rw-r--r-- | examples/examples.pro | 2 | ||||
-rw-r--r-- | examples/geniviextras/geniviextras.pro | 2 | ||||
-rw-r--r-- | examples/geniviextras/qdlt/loggingcategories.cpp | 9 | ||||
-rw-r--r-- | examples/geniviextras/qdlt/loggingcategories.h | 9 | ||||
-rw-r--r-- | examples/geniviextras/qdlt/main.cpp | 25 | ||||
-rw-r--r-- | examples/geniviextras/qdlt/qdlt.pro | 15 | ||||
-rw-r--r-- | qtgeniviextras.pro | 16 | ||||
-rw-r--r-- | src/geniviextras/geniviextras.pro | 29 | ||||
-rw-r--r-- | src/geniviextras/qdlt.h | 44 | ||||
-rw-r--r-- | src/geniviextras/qdltregistration.cpp | 105 | ||||
-rw-r--r-- | src/geniviextras/qdltregistration.h | 40 | ||||
-rw-r--r-- | src/geniviextras/qdltregistration_p.h | 28 | ||||
-rw-r--r-- | src/geniviextras/qgeniviextrasglobal.h | 26 | ||||
-rw-r--r-- | src/src.pro | 6 | ||||
-rw-r--r-- | sync.profile | 9 |
21 files changed, 433 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1a045fa --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +.tag export-subst +.gitignore export-ignore +.gitattributes export-ignore +.commit-template export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0a97e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pro.user* +Makefile* diff --git a/.qmake.conf b/.qmake.conf new file mode 100644 index 0000000..66a0241 --- /dev/null +++ b/.qmake.conf @@ -0,0 +1,3 @@ +load(qt_build_config) + +MODULE_VERSION = 5.6.0 @@ -0,0 +1 @@ +Qt Genivi Extras: Platform specific components for Genivi diff --git a/config.tests/dlt/dlt.pro b/config.tests/dlt/dlt.pro new file mode 100644 index 0000000..b8f0208 --- /dev/null +++ b/config.tests/dlt/dlt.pro @@ -0,0 +1,12 @@ +TARGET = dlt +QT = core + +!contains(QT_CONFIG, no-pkg-config) { + CONFIG += link_pkgconfig + PKGCONFIG += automotive-dlt +} else { + LIBS += -ldlt +} + +# Input +SOURCES += main.cpp diff --git a/config.tests/dlt/main.cpp b/config.tests/dlt/main.cpp new file mode 100644 index 0000000..bddb026 --- /dev/null +++ b/config.tests/dlt/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <dlt.h> + +int main() +{ + return 0; +} diff --git a/examples/examples.pro b/examples/examples.pro new file mode 100644 index 0000000..2f47599 --- /dev/null +++ b/examples/examples.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += geniviextras diff --git a/examples/geniviextras/geniviextras.pro b/examples/geniviextras/geniviextras.pro new file mode 100644 index 0000000..3f97b89 --- /dev/null +++ b/examples/geniviextras/geniviextras.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += qdlt diff --git a/examples/geniviextras/qdlt/loggingcategories.cpp b/examples/geniviextras/qdlt/loggingcategories.cpp new file mode 100644 index 0000000..b628132 --- /dev/null +++ b/examples/geniviextras/qdlt/loggingcategories.cpp @@ -0,0 +1,9 @@ +#include "loggingcategories.h" +#include <QtGeniviExtras/QtDlt> + +QDLT_REGISTER_APPLICATION("APP1", "Description for APP") + +QDLT_LOGGING_CATEGORY(FOO, "com.pelagicore.foo", "FOO", "FOO CATEGORY") +QDLT_LOGGING_CATEGORY(BAR, "com.pelagicore.bar", "BAR", "BAR CATEGORY") + +QDLT_FALLBACK_CATEGORY(FOO) diff --git a/examples/geniviextras/qdlt/loggingcategories.h b/examples/geniviextras/qdlt/loggingcategories.h new file mode 100644 index 0000000..994b85d --- /dev/null +++ b/examples/geniviextras/qdlt/loggingcategories.h @@ -0,0 +1,9 @@ +#ifndef LOGGINGCATEGORIES_H +#define LOGGINGCATEGORIES_H + +#include <QLoggingCategory> + +Q_DECLARE_LOGGING_CATEGORY(FOO) +Q_DECLARE_LOGGING_CATEGORY(BAR) + +#endif // LOGGINGCATEGORIES_H diff --git a/examples/geniviextras/qdlt/main.cpp b/examples/geniviextras/qdlt/main.cpp new file mode 100644 index 0000000..d26e08d --- /dev/null +++ b/examples/geniviextras/qdlt/main.cpp @@ -0,0 +1,25 @@ +#include <QCoreApplication> +#include <QTimer> +#include <QtGeniviExtras/QtDlt> + +#include "loggingcategories.h" + +int main(int argc, char *argv[]) +{ + qInstallMessageHandler(QDltRegistration::messageHandler); + + QCoreApplication a(argc, argv); + + QTimer timer; + timer.connect(&timer, &QTimer::timeout, [] { + static int counter = 0; + counter++; + qCCritical(FOO) << "FOO CATEGORY"; + qCWarning(BAR) << "BAR CATEGORY"; + qCritical() << "FALLBACK"; + }); + timer.setInterval(1000); + timer.start(); + + return a.exec(); +} diff --git a/examples/geniviextras/qdlt/qdlt.pro b/examples/geniviextras/qdlt/qdlt.pro new file mode 100644 index 0000000..24153f1 --- /dev/null +++ b/examples/geniviextras/qdlt/qdlt.pro @@ -0,0 +1,15 @@ +QT += core geniviextras +QT -= gui + +TARGET = qdlt +CONFIG += console +CONFIG -= app_bundle +CONFIG += c++11 + +TEMPLATE = app + +SOURCES += main.cpp \ + loggingcategories.cpp \ + +HEADERS += \ + loggingcategories.h \ diff --git a/qtgeniviextras.pro b/qtgeniviextras.pro new file mode 100644 index 0000000..b624a19 --- /dev/null +++ b/qtgeniviextras.pro @@ -0,0 +1,16 @@ +enable-examples { + QTGENIVIEXTRAS_BUILD_PARTS = $$QT_BUILD_PARTS + QTGENIVIEXTRAS_BUILD_PARTS *= examples +} + +enable-tests { + QTGENIVIEXTRAS_BUILD_PARTS = $$QT_BUILD_PARTS + QTGENIVIEXTRAS_BUILD_PARTS *= tests +} + +load(configure) +qtCompileTest(dlt) + +load(qt_parts) + +OTHER_FILES += sync.profile diff --git a/src/geniviextras/geniviextras.pro b/src/geniviextras/geniviextras.pro new file mode 100644 index 0000000..b4cd24e --- /dev/null +++ b/src/geniviextras/geniviextras.pro @@ -0,0 +1,29 @@ +TARGET = QtGeniviExtras + +QT = core +CONFIG += c++11 +VERSION = 1.0.0 + +CONFIG += link_pkgconfig + +#QMAKE_DOCS = $$PWD/doc/qtgeniviextras.qdocconf +OTHER_FILES += $$PWD/doc/*.qdoc + +!contains(QT_CONFIG, no-pkg-config) { + PKGCONFIG += automotive-dlt +} else { + LIBS += -ldlt +} + +CMAKE_MODULE_TESTS = '-' + +HEADERS += \ + qdlt.h \ + qdltregistration.h \ + qdltregistration_p.h \ + qgeniviextrasglobal.h \ + +SOURCES += \ + qdltregistration.cpp \ + +load(qt_module) diff --git a/src/geniviextras/qdlt.h b/src/geniviextras/qdlt.h new file mode 100644 index 0000000..c42c8e4 --- /dev/null +++ b/src/geniviextras/qdlt.h @@ -0,0 +1,44 @@ +#ifndef QDLT_H +#define QDLT_H + +#include <QGlobalStatic> +/************************************************************************************************ + * Copyright (c) 2012-2015 Pelagicore AG. All rights reserved. + * + * This software, including documentation, is protected by copyright controlled by Pelagicore AG. + * All rights reserved. Copying, including reproducing, storing, adapting or translating, any or + * all of this material requires prior written consent of Pelagicore AG Corporation. This material + * also contains confidential information which may not be disclosed to others without the prior + * written consent of Pelagicore AG. + ************************************************************************************************/ + +#include <QtGlobal> + +#include "qdltregistration.h" + +#define QDLT_REGISTER_APPLICATION(APP, DESCRIPTION) \ +struct QDltAppRegistrator { \ + QDltAppRegistrator() { globalDltRegistration()->registerApplication(APP, DESCRIPTION); } \ +}; \ +static QDltAppRegistrator qdltAppRegistrator; \ + + +#define QDLT_LOGGING_CATEGORY(CATEGORY, CATEGORYNAME, DLT_CTX_NAME, DLT_CTX_DESCRIPTION) \ +Q_LOGGING_CATEGORY(CATEGORY, CATEGORYNAME) \ +QDLT_REGISTER_LOGGING_CATEGORY(CATEGORY, CATEGORYNAME, DLT_CTX_NAME, DLT_CTX_DESCRIPTION) \ + +#define QDLT_REGISTER_LOGGING_CATEGORY(CATEGORY, CATEGORYNAME, DLT_CTX_NAME, DLT_CTX_DESCRIPTION) \ +struct QDlt ## CATEGORY ## Registrator { \ + QDlt ## CATEGORY ## Registrator() { globalDltRegistration()->registerCategory(CATEGORYNAME , DLT_CTX_NAME, DLT_CTX_DESCRIPTION); } \ +}; \ +static QDlt ## CATEGORY ## Registrator qdlt ## CATEGORY ## registrator; \ + +#define QDLT_FALLBACK_CATEGORY(CATEGORY) \ +struct QDltDefaultRegistrator { \ + QDltDefaultRegistrator() { globalDltRegistration()->setDefaultContext(CATEGORY().categoryName()); } \ +}; \ +static QDltDefaultRegistrator qdltDefaultRegistrator; \ + + +#endif // QDLT_H + diff --git a/src/geniviextras/qdltregistration.cpp b/src/geniviextras/qdltregistration.cpp new file mode 100644 index 0000000..5a9feb9 --- /dev/null +++ b/src/geniviextras/qdltregistration.cpp @@ -0,0 +1,105 @@ +#include "qdltregistration.h" +/************************************************************************************************ + * Copyright (c) 2012-2015 Pelagicore AG. All rights reserved. + * + * This software, including documentation, is protected by copyright controlled by Pelagicore AG. + * All rights reserved. Copying, including reproducing, storing, adapting or translating, any or + * all of this material requires prior written consent of Pelagicore AG Corporation. This material + * also contains confidential information which may not be disclosed to others without the prior + * written consent of Pelagicore AG. + ************************************************************************************************/ + +#include "qdltregistration_p.h" + +#include <QDebug> + +Q_GLOBAL_STATIC(QDltRegistration, dltRegistration) + +QDltRegistration *globalDltRegistration() +{ + return dltRegistration(); +} + +QDltRegistrationPrivate::QDltRegistrationPrivate() + : m_defaultContext(nullptr) +{ +} + +void QDltRegistrationPrivate::registerCategory(const char *categoryName, DltContext *dltContext, const char *dltCtxName, const char *dltCtxDescription) +{ + DLT_REGISTER_CONTEXT(*dltContext, dltCtxName, dltCtxDescription); + m_map.insert(QString::fromLatin1(categoryName), dltContext); +} + +void QDltRegistrationPrivate::setDefaultContext(DltContext *dltContext) +{ + m_defaultContext = dltContext; +} + +DltContext *QDltRegistrationPrivate::context(const char *categoryName) +{ + const QString category = QString::fromLatin1(categoryName); + if (!m_map.contains(category) && m_defaultContext) + return m_defaultContext; + + return m_map.value(category); +} + + + +QDltRegistration::QDltRegistration() + : d_ptr(new QDltRegistrationPrivate()) +{ +} + +QDltRegistration::~QDltRegistration() +{ + unregisterApplication(); +} + +void QDltRegistration::registerApplication(const char *dltAppID, const char *dltAppDescription) +{ + Q_D(QDltRegistration); + d->m_dltAppID = QString::fromLatin1(dltAppID); + DLT_REGISTER_APP(dltAppID, dltAppDescription); +} + +void QDltRegistration::registerCategory(const char *categoryName, const char *dltCtxName, const char *dltCtxDescription) +{ + Q_D(QDltRegistration); + //TODO memory leak + d->registerCategory(categoryName, new DltContext, dltCtxName, dltCtxDescription); +} + +void QDltRegistration::setDefaultContext(const char *categoryName) +{ + Q_D(QDltRegistration); + d->setDefaultContext(d->context(categoryName)); +} + +void QDltRegistration::unregisterApplication() +{ + Q_D(QDltRegistration); + if (!d->m_dltAppID.isEmpty()) + DLT_UNREGISTER_APP(); +} + +void QDltRegistration::messageHandler(QtMsgType msgTypes, const QMessageLogContext & msgCtx, const QString & msg) +{ + DltContext* dltCtx = globalDltRegistration()->d_ptr->context(msgCtx.category); + if (!dltCtx) + { + return; + } + + DltLogLevelType logLevel = DLT_LOG_INFO; + + switch (msgTypes) { + case QtDebugMsg: logLevel = DLT_LOG_DEBUG; break; + case QtWarningMsg: logLevel = DLT_LOG_INFO; break; + case QtCriticalMsg: logLevel = DLT_LOG_ERROR; break; + case QtFatalMsg: logLevel = DLT_LOG_FATAL; break; + } + + DLT_LOG(*dltCtx, logLevel, DLT_STRING(qPrintable(qFormatLogMessage(msgTypes, msgCtx, msg)))); +} diff --git a/src/geniviextras/qdltregistration.h b/src/geniviextras/qdltregistration.h new file mode 100644 index 0000000..66ea6bd --- /dev/null +++ b/src/geniviextras/qdltregistration.h @@ -0,0 +1,40 @@ +/************************************************************************************************ + * Copyright (c) 2012-2015 Pelagicore AG. All rights reserved. + * + * This software, including documentation, is protected by copyright controlled by Pelagicore AG. + * All rights reserved. Copying, including reproducing, storing, adapting or translating, any or + * all of this material requires prior written consent of Pelagicore AG Corporation. This material + * also contains confidential information which may not be disclosed to others without the prior + * written consent of Pelagicore AG. + ************************************************************************************************/ + +#ifndef QDLTREGISTRATION_H +#define QDLTREGISTRATION_H + +#include <QString> +#include <QMap> +#include <qgeniviextrasglobal.h> + +class QDltRegistrationPrivate; + +class Q_GENIVIEXTRAS_EXPORT QDltRegistration +{ +public: + QDltRegistration(); + ~QDltRegistration(); + + void registerApplication(const char *dltAppID, const char *dltAppDescription); + void unregisterApplication(); + + void registerCategory(const char* categoryName, const char* dltCtxName, const char* dltCtxDescription); + void setDefaultContext(const char* categoryName); + + static void messageHandler(QtMsgType msgTypes, const QMessageLogContext &msgCtx, const QString &msg); +private: + QDltRegistrationPrivate* const d_ptr; + Q_DECLARE_PRIVATE(QDltRegistration) +}; + +Q_GENIVIEXTRAS_EXPORT extern QDltRegistration* globalDltRegistration(); + +#endif // QDLTREGISTRATION_H diff --git a/src/geniviextras/qdltregistration_p.h b/src/geniviextras/qdltregistration_p.h new file mode 100644 index 0000000..906a8be --- /dev/null +++ b/src/geniviextras/qdltregistration_p.h @@ -0,0 +1,28 @@ +/************************************************************************************************ + * Copyright (c) 2012-2015 Pelagicore AG. All rights reserved. + * + * This software, including documentation, is protected by copyright controlled by Pelagicore AG. + * All rights reserved. Copying, including reproducing, storing, adapting or translating, any or + * all of this material requires prior written consent of Pelagicore AG Corporation. This material + * also contains confidential information which may not be disclosed to others without the prior + * written consent of Pelagicore AG. + ************************************************************************************************/ + +#include <QString> +#include <QMap> + +#include <dlt.h> + +class QDltRegistrationPrivate { +public: + QDltRegistrationPrivate(); + + void registerCategory(const char* categoryName, DltContext* dltContext, const char* dltCtxName, const char* dltCtxDescription); + void setDefaultContext(DltContext* dltContext); + + DltContext* context(const char* categoryName); + + QString m_dltAppID; + DltContext* m_defaultContext; + QMap<QString, DltContext*> m_map; +}; diff --git a/src/geniviextras/qgeniviextrasglobal.h b/src/geniviextras/qgeniviextrasglobal.h new file mode 100644 index 0000000..81d7290 --- /dev/null +++ b/src/geniviextras/qgeniviextrasglobal.h @@ -0,0 +1,26 @@ +/************************************************************************************************ + * Copyright (c) 2012-2015 Pelagicore AG. All rights reserved. + * + * This software, including documentation, is protected by copyright controlled by Pelagicore AG. + * All rights reserved. Copying, including reproducing, storing, adapting or translating, any or + * all of this material requires prior written consent of Pelagicore AG Corporation. This material + * also contains confidential information which may not be disclosed to others without the prior + * written consent of Pelagicore AG. + ************************************************************************************************/ + +#ifndef QGENIVIEXTRASGLOBAL_H +#define QGENIVIEXTRASGLOBAL_H + +#include <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +#if defined(QT_BUILD_GENIVIEXTRAS_LIB) +# define Q_GENIVIEXTRAS_EXPORT Q_DECL_EXPORT +#else +# define Q_GENIVIEXTRAS_EXPORT Q_DECL_IMPORT +#endif + +QT_END_NAMESPACE + +#endif // QGENIVIEXTRASGLOBAL_H diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..58312e1 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +config_dlt { + SUBDIRS += geniviextras +} else { + warning("No dlt found, disabling building geniviextras") +} diff --git a/sync.profile b/sync.profile new file mode 100644 index 0000000..359adf3 --- /dev/null +++ b/sync.profile @@ -0,0 +1,9 @@ +%modules = ( + "QtGeniviExtras" => "$basedir/src/geniviextras", +); +%classnames = ( + "qdlt.h" => "QtDlt", +); +%dependencies = ( + "qtbase" => "refs/heads/stable", +); |