From 5803544f6c337e460e3ac99a2a49cd9f0e48cb85 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Sun, 10 Jul 2016 20:04:40 +0900 Subject: [PATCH] ui: clean-up logging for Qt5 UI Change-Id: I98436a9f75c8c639ea05289641df09f4383d7e2d Signed-off-by: SeokYeon Hwang --- tizen/src/ui/qt5_supplement.cpp | 254 ++++++++++++++++++++-------------------- tizen/src/util/new_debug_ch.h | 2 +- 2 files changed, 130 insertions(+), 126 deletions(-) diff --git a/tizen/src/ui/qt5_supplement.cpp b/tizen/src/ui/qt5_supplement.cpp index 4df02d7..639b9da 100644 --- a/tizen/src/ui/qt5_supplement.cpp +++ b/tizen/src/ui/qt5_supplement.cpp @@ -39,6 +39,10 @@ #include "resource/ui_strings.h" #include "displaybase.h" +#include "util/new_debug_ch.h" +// XXX: all modules in ui/* are controlled by channel name "qt5_ui" +DECLARE_DEBUG_CHANNEL(qt5_ui); + extern "C" { #include "emul_state.h" #include "emulator_options.h" @@ -48,10 +52,6 @@ bool is_display_off(void); } //using namespace std; -void qMessageOutput(QtMsgType, const QMessageLogContext &, const QString &); -void loadMainFormFromXML(QString, UiInformation *); -void loadConFormFromXML(QFile *, UiInformation *); - bool qt5IsOnscreen; QApplication *qt5App = NULL; @@ -95,6 +95,127 @@ bool EventFilter::nativeEventFilter(const QByteArray &eventType, void *message, } #endif +static void loadMainFormFromXML(QString xmlPath, UiInformation *uiInfo/* out */) +{ + QFile file(xmlPath); + + if (file.exists() == false || + file.open(QIODevice::ReadOnly | QIODevice::Text) == false) { + qFatal("Failed to load the emulator skin. %s%s", MSG_CHECK_PATH, + qPrintable(xmlPath)); + return; + } + + qDebug("main form is loaded from %s", qPrintable(file.fileName())); + + /* read xml */ + QXmlStreamReader xml(&file); + + /* parse xml */ + QFileInfo fileInfo(xmlPath); + XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo); + QString version = parser.parseEmulatorUI(xml); + qDebug() << "* main layout version:" << version; + + const bool hasError = xml.hasError(); + xml.clear(); + file.close(); + + if (hasError == true) { + qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH, + qPrintable(xmlPath)); + return; + } +} + +static void loadConFormFromXML(QFile *file, UiInformation *uiInfo/* out */) +{ + if (file->exists() == false || + file->open(QIODevice::ReadOnly | QIODevice::Text) == false) { + qWarning() << "Failed to load the controller skin:" << + file->fileName(); + return; + } + + qDebug("controller form is loaded from %s", qPrintable(file->fileName())); + + /* read xml */ + QXmlStreamReader xml(file); + + /* parse xml */ + QFileInfo fileInfo(*file); + XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo); + QString version = parser.parseControllerUI(xml); + qDebug() << "* con layout version:" << version; + + const bool hasError = xml.hasError(); + xml.clear(); + file->close(); + + if (hasError == true) { + qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH, + qPrintable(fileInfo.absoluteFilePath())); + return; + } +} + +static void qMessageOutput(QtMsgType type, const QMessageLogContext &context, + const QString &msg) +{ + char typeChar = '\0'; + + switch (type) { + case QtDebugMsg: + if (!IS_TRACE_ON) { + // if TRACE if off, we have nothing to do. + return; + } + typeChar = 'T'; + break; + case QtInfoMsg: + typeChar = 'I'; + break; + case QtWarningMsg: + typeChar = 'W'; + break; + case QtCriticalMsg: + case QtFatalMsg: + typeChar = 'S'; + default: + qFatal("invalid message type"); + break; + } + + QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss.zzz"); + QString path = QFileInfo(context.file).completeBaseName(); + path.truncate(10); + + // XXX: it is hard to use DEBUGCH for c++ modules, so we are printing + // logs now. + QTextStream out(stdout); + out.setFieldAlignment(QTextStream::AlignRight); + out << qSetFieldWidth(12) << timestamp; + out << qSetFieldWidth(1) << "|"; + out << qSetFieldWidth(5) << qemu_get_thread_id(); + out << qSetFieldWidth(1) << "|"; + out << qSetFieldWidth(1) << typeChar; + out << qSetFieldWidth(1) << "|"; + out << qSetFieldWidth(10) << path; + out << qSetFieldWidth(1) << "|"; + out << qSetFieldWidth(4) << context.line; + out << qSetFieldWidth(1) << "|"; + out << qSetFieldWidth(0) << msg; + out << qSetFieldWidth(0) << endl; + + if (type == QtCriticalMsg || type == QtFatalMsg) { + QMessageBox::critical(0, EMULATOR_TITLE, + QString(MSG_INTERNAL_ERR) + msg + + MSG_EMULATOR_EXIT); + + abort(); + } +} + const char *qt5_get_version(void) { return qVersion(); @@ -104,10 +225,10 @@ static void qt5_gui_init(void) { QCoreApplication::setApplicationName(EMULATOR_TITLE); - qDebug() << "* Qt version (compile time):" << QT_VERSION_STR; - qDebug() << "* Qt version (runtime):" << qVersion(); - qDebug() << "* working path:" << QDir::currentPath(); - qDebug() << "* binary path:" << QCoreApplication::applicationDirPath(); + qInfo() << "* Qt version (compile time):" << QT_VERSION_STR; + qInfo() << "* Qt version (runtime):" << qVersion(); + qInfo() << "* working path:" << QDir::currentPath(); + qInfo() << "* binary path:" << QCoreApplication::applicationDirPath(); uiInfo = new UiInformation(); @@ -428,120 +549,3 @@ void qt5_process_captured(bool captured, void *pixels, int width, int height) mainwindow->processCaptured(captured, pixels, width, height); } } - -void qMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) -{ - QByteArray localMsg = msg.toLocal8Bit(); - QByteArray dateMsg = QDateTime::currentDateTime().toString("hh:mm:ss.zzz").toLocal8Bit(); - - QString path = context.file; - QByteArray fname = NULL; - int posFname = path.lastIndexOf('/') + 1; - int posDot = path.lastIndexOf('.'); - - if (( posFname != 0 ) && ( posDot != -1)) { - int fnameLen = path.length() - posFname; - path = path.right(fnameLen); - fnameLen = posDot - posFname; - path.truncate(fnameLen); - } - fname = path.toLocal8Bit(); - - switch (type) { - case QtDebugMsg: - fprintf(stdout, "%s|%5d|I|%10.10s|%4u|%s\n", dateMsg.constData(), - qemu_get_thread_id(), fname.trimmed().constData(), context.line, - localMsg.trimmed().constData()); - break; - case QtWarningMsg: - fprintf(stdout, "%s|%5d|W|%10.10s|%4u|%s\n", dateMsg.constData(), - qemu_get_thread_id(), fname.trimmed().constData(), context.line, - localMsg.trimmed().constData()); - break; - case QtCriticalMsg: - fprintf(stderr, "%s|%5d|S|%10.10s|%4u|%s\n", dateMsg.constData(), - qemu_get_thread_id(), fname.trimmed().constData(), context.line, - localMsg.trimmed().constData()); - break; - case QtFatalMsg: - fprintf(stderr, "%s|%5d|S|%10.10s|%4u|%s\n", dateMsg.constData(), - qemu_get_thread_id(), fname.trimmed().constData(), context.line, - localMsg.trimmed().constData()); - { - QString err; - QMessageBox::critical(0, EMULATOR_TITLE, - QString(MSG_INTERNAL_ERR) + - err.sprintf("%s", (localMsg.trimmed()).constData()) + - MSG_EMULATOR_EXIT); - } - - abort(); - default: - qFatal("invalid message type"); - break; - } -} - -void loadMainFormFromXML(QString xmlPath, UiInformation *uiInfo/* out */) -{ - QFile file(xmlPath); - - if (file.exists() == false || - file.open(QIODevice::ReadOnly | QIODevice::Text) == false) { - qFatal("Failed to load the emulator skin. %s%s", MSG_CHECK_PATH, - qPrintable(xmlPath)); - return; - } - - qDebug("main form is loaded from %s", qPrintable(file.fileName())); - - /* read xml */ - QXmlStreamReader xml(&file); - - /* parse xml */ - QFileInfo fileInfo(xmlPath); - XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo); - QString version = parser.parseEmulatorUI(xml); - qDebug() << "* main layout version:" << version; - - const bool hasError = xml.hasError(); - xml.clear(); - file.close(); - - if (hasError == true) { - qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH, - qPrintable(xmlPath)); - return; - } -} - -void loadConFormFromXML(QFile *file, UiInformation *uiInfo/* out */) -{ - if (file->exists() == false || - file->open(QIODevice::ReadOnly | QIODevice::Text) == false) { - qWarning() << "Failed to load the controller skin:" << - file->fileName(); - return; - } - - qDebug("controller form is loaded from %s", qPrintable(file->fileName())); - - /* read xml */ - QXmlStreamReader xml(file); - - /* parse xml */ - QFileInfo fileInfo(*file); - XmlLayoutParser parser(fileInfo.absolutePath(), uiInfo); - QString version = parser.parseControllerUI(xml); - qDebug() << "* con layout version:" << version; - - const bool hasError = xml.hasError(); - xml.clear(); - file->close(); - - if (hasError == true) { - qFatal("%s %s%s", MSG_INVALID_XML_FORMAT, MSG_CHECK_PATH, - qPrintable(fileInfo.absoluteFilePath())); - return; - } -} diff --git a/tizen/src/util/new_debug_ch.h b/tizen/src/util/new_debug_ch.h index b34f8ee..0e2c870 100644 --- a/tizen/src/util/new_debug_ch.h +++ b/tizen/src/util/new_debug_ch.h @@ -139,7 +139,7 @@ extern int dbg_log(enum _debug_class cls, struct _debug_channel *ch, #define IS_TRACE_ON __IS_DEBUG_ON(_TRACE,&_dbch_) #define DECLARE_DEBUG_CHANNEL(ch) \ - static struct _debug_channel _dbch_ = { ~0, #ch }; + static struct _debug_channel _dbch_ = { (unsigned char)~0, #ch }; #ifdef __cplusplus } -- 2.7.4