From d80f4167528e141a17a5f474d995ea1780525023 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 17 Dec 2014 18:35:09 +0100 Subject: [PATCH] refs #350 Changed log severity and log category in core as discussed --- src/swiftcore/main.cpp | 28 ++++++++++++++++------------ src/swiftcore/tool.cpp | 21 +++++---------------- src/swiftcore/tool.h | 3 --- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/swiftcore/main.cpp b/src/swiftcore/main.cpp index 7730d50df..5c5af95f9 100644 --- a/src/swiftcore/main.cpp +++ b/src/swiftcore/main.cpp @@ -33,16 +33,19 @@ using namespace BlackCore; */ int main(int argc, char *argv[]) { - // metadata are registered in runtime - QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412 - CLogHandler::instance()->install(); - CLogHandler::instance()->enableConsoleOutput(false); // default disable - QIcon icon(BlackMisc::CIcons::swiftNova24()); - QApplication::setWindowIcon(icon); + CRuntime::registerMetadata(); // register metadata + QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412 QTextStream cin(stdin); QTextStream cout(stdout); - cout << BlackMisc::CProject::version() << " " << BlackMisc::CProject::compiledInfo() << endl; + QIcon icon(BlackMisc::CIcons::swiftNova24()); + QApplication::setWindowIcon(icon); + + CLogHandler::instance()->install(); + CLogHandler::instance()->enableConsoleOutput(false); // default disable + CLogHandler::instance()->handlerForPattern( + CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo) + )->enableConsoleOutput(true); // enable for info cout << "1 + la/ra .. session DBus server (default)" << endl; cout << "2 + la/ra .. system DBus server" << endl; @@ -50,7 +53,6 @@ int main(int argc, char *argv[]) cout << "la .. local audio, audio runs in this core here (default)" << endl; cout << "ra .. remote audio, audio runs in the GUI or elsewhere" << endl; cout << "x .. exit" << endl; - QString input = cin.readLine().toLower().trimmed(); // configure DBus server @@ -73,12 +75,14 @@ int main(int argc, char *argv[]) // with remote audio bool remoteAudio = input.contains("ra"); - CRuntime *core = remoteAudio ? - new CRuntime(CRuntimeConfig::forCoreAllLocalInDBusNoAudio(dBusAddress), &a) : - new CRuntime(CRuntimeConfig::forCoreAllLocalInDBus(dBusAddress), &a); + CRuntime *coreRuntime = remoteAudio ? + new CRuntime(CRuntimeConfig::forCoreAllLocalInDBusNoAudio(dBusAddress), &a) : + new CRuntime(CRuntimeConfig::forCoreAllLocalInDBus(dBusAddress), &a); // tool to allow input indepent from event loop - QtConcurrent::run(BlackMiscTest::Tool::serverLoop, core); // QFuture future + cout << "Will start server loop ... " << endl; + QFuture future = QtConcurrent::run(BlackMiscTest::Tool::serverLoop, coreRuntime); + Q_UNUSED(future); cout << "Server event loop, pid: " << BlackMiscTest::Tool::getPid() << " Thread id: " << QThread::currentThreadId() << endl; // end diff --git a/src/swiftcore/tool.cpp b/src/swiftcore/tool.cpp index 7c1ee2600..7989bbfa5 100644 --- a/src/swiftcore/tool.cpp +++ b/src/swiftcore/tool.cpp @@ -24,27 +24,18 @@ using namespace BlackMisc::Audio; namespace BlackMiscTest { - /* - * Start a new process - */ - QProcess *Tool::startNewProcess(const QString &executable, const QStringList &arguments, QObject *parent) - { - QProcess *process = new QProcess(parent); - process->startDetached(executable, arguments); - return process; - } - /* * Send data to testservice, this sends data to the slots on the server */ void Tool::serverLoop(CRuntime *runtime) { - QMetaObject::invokeMethod(CLogHandler::instance(), "enableConsoleOutput", Q_ARG(bool, false)); + QTextStream qtout(stdout); + qtout << "Running on server here " << Tool::getPid() << " thread: " << QThread::currentThreadId() << endl; Q_ASSERT(runtime); - QThread::sleep(3); // let the DBus server startup + QThread::sleep(3); // time in secs, let the DBus server startup - // log + // log initial severity CLogSubscriber applicationMessageSubscriber, audioMessageSubscriber, networkMessageSubscriber, ownAircraftMessageSubscriber, settingsMessageSubscriber, simulatorMessageSubscriber; CStatusMessage::StatusSeverity messageSeverity = CStatusMessage::SeverityInfo; auto refreshSubscriptionSeverities = [ & ]() @@ -56,10 +47,8 @@ namespace BlackMiscTest settingsMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextSettings()).withSeverityAtOrAbove(messageSeverity)); simulatorMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextSimulator()).withSeverityAtOrAbove(messageSeverity)); }; - refreshSubscriptionSeverities(); - QTextStream qtout(stdout); - qtout << "Running on server here " << Tool::getPid() << " thread: " << QThread::currentThreadId() << endl; + refreshSubscriptionSeverities(); // // Server loop diff --git a/src/swiftcore/tool.h b/src/swiftcore/tool.h index d70c95a25..46bef774b 100644 --- a/src/swiftcore/tool.h +++ b/src/swiftcore/tool.h @@ -25,9 +25,6 @@ namespace BlackMiscTest return QCoreApplication::applicationPid(); } - //! Start a new process - static QProcess *startNewProcess(const QString &executable, const QStringList &arguments = QStringList(), QObject *parent = 0); - //! Server loop static void serverLoop(BlackCore::CRuntime *runtime);