Index: main.cpp =================================================================== diff -u -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 -rb9c5b0b3afc3b34d4980ecc4f023f498f80dafbc --- main.cpp (.../main.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) +++ main.cpp (.../main.cpp) (revision b9c5b0b3afc3b34d4980ecc4f023f498f80dafbc) @@ -1,6 +1,6 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. * \copyright \n * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n * IN PART OR IN WHOLE, \n @@ -25,18 +25,22 @@ #include #include #include +#include // Project #include "maintimer.h" #include "caninterface.h" -#include "messagehandler.h" +#include "frameinterface.h" +#include "messagedispatcher.h" #include "applicationcontroller.h" -#include "guiglobals.h" #include "guicontroller.h" +#include "logger.h" +#include "usbwatcher.h" +#include "threads.h" #ifdef UNIT_TEST - #include "unittests/unittests.h" - QTEST_MAIN(unittests) + #include TEST_CLASS_INCLUDE + QTEST_MAIN(TEST_CLASS_NAME) #else /*! \brief Application Initialization\n * Some part of the application need to be initialized out of any thread. @@ -48,11 +52,28 @@ //! - Qt Application initialization and parameters settings // Qt Core Application parameters settings + + QApplication::setApplicationName(QLatin1String("Denali")); + QApplication::setOrganizationName(QLatin1String("Diality Inc.")); + + //! - Check the required font(s) present and can be loaded + QApplication::setFont(QFont("Barlow")); + // Qt Core Application Initialization QApplication app(argc, argv); - QCoreApplication::setApplicationName(QLatin1String("Denali")); - QCoreApplication::setOrganizationName(QLatin1String("Diality Inc.")); + app.thread()->setObjectName("Main Thread"); + // Test code for debugging can messages + bool _consoleoutFrameInterface = false; + bool _consoleoutCanInterface = false; + QStringList args = app.arguments(); + if (args.length() >= 2) { + _consoleoutFrameInterface = args[1] == "1"; + } + if (args.length() >= 3) { + _consoleoutCanInterface = args[2] == "1"; + } + //! - Setting the application version regarding the Bamboo build number. QString ver_revis = QString("%1").arg(VER_REVIS); if (ver_revis.isEmpty()) { @@ -70,28 +91,51 @@ app.installTranslator(&translator); } - //! - Initializing Main Timer - _MainTimer->init(); + //! - Initializing required thread types + Threads::registerTypes(); + //! - Initializing Logger + _Logger.init(Threads::_Logger_Thread); + + LOG_EVENT(QObject::tr("Application Started")); + + //! - Initializing USB Watcher + _USBWatcher.init(Threads::_USBWatcher_Thread); + //! - Initializing CanBus Interface - _CanInterface->init(); + if (_CanInterface.init(Threads::_CanFrame_Thread)) { + _CanInterface.enableConsoleOut(_consoleoutCanInterface); + } //! - Initializing CanBus Message Handler - _MessageHandler->init(); + _FrameInterface.init(Threads::_CanFrame_Thread); + //! - Initializing CanBus Message Dispatcher + if (_MessageDispatcher.init(Threads::_CanMessage_Thread)) { + _MessageDispatcher.enableConsoleOut(_consoleoutFrameInterface); + } + //! - Initializing Application Controller - _ApplicationController->init(); - QObject::connect(_ApplicationController, &ApplicationController::quit, &app, [](int retcode) { - //qDebug() << "Application Terminated:" << retcode; - QCoreApplication::exit(retcode); - }, Qt::QueuedConnection); + _ApplicationController.init(Threads::_Application_Thread); ////! - Initializing GUI Controller - _GuiController->init(); + _GuiController.init(Threads::_Application_Thread); + //! - Initializing Main Timer + _MainTimer.init(); + //! - Initialize the Qml Viewer and starts GUI startGui(); - return app.exec(); + int app_exec = app.exec(); + + // Due to Qt Error the CAN Device cannot be disable/enable from withing another thread + // (other than main thread which is the owner of the CanDevice owner). + // So it needs to be done here in main thread. + _CanInterface.quitDevice(); + + Threads::quitThreads(); + + return app_exec; } #endif