Index: denali.pro =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- denali.pro (.../denali.pro) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ denali.pro (.../denali.pro) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -68,6 +68,7 @@ sources/canbus/frameinterface.cpp \ sources/canbus/messagebuilder.cpp \ sources/canbus/messagedispatcher.cpp \ + sources/canbus/messageglobals.cpp \ sources/canbus/messageinterpreter.cpp \ sources/configuration/display.cpp \ sources/configuration/sound.cpp \ Index: main.cpp =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- main.cpp (.../main.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ main.cpp (.../main.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -99,34 +99,34 @@ //! - Initializing USB Watcher _USBWatcher.init(); - //! - Initializing Main Timer - _MainTimer->init(); - //! - Initializing CanBus Interface - _CanInterface->init(); - _CanInterface->enableConsoleOut(_consoleoutCanInterface); + if (_CanInterface.init()) { + _CanInterface.enableConsoleOut(_consoleoutCanInterface); + } //! - Initializing CanBus Message Handler - _FrameInterface->init(); + _FrameInterface.init(); //! - Initializing CanBus Message Dispatcher - _MessageDispatcher->init(); - _MessageDispatcher->enableConsoleOut(_consoleoutFrameInterface); + _MessageDispatcher.init(); + _MessageDispatcher.enableConsoleOut(_consoleoutFrameInterface); //! - Initializing Application Controller - _ApplicationController->init(); + _ApplicationController.init(); QObject::connect(&app, &QApplication::aboutToQuit, []() { - emit _ApplicationController->quit(); + emit _ApplicationController.quit(); }); - QObject::connect(_ApplicationController, &ApplicationController::quit, &app, [](int retcode) { - _CanInterface->quit(); + QObject::connect(&_ApplicationController, &ApplicationController::quit, &app, [](int retcode) { QCoreApplication::exit(retcode); qDebug() << QObject::tr("Application Terminated: %1").arg(retcode); }, Qt::QueuedConnection); ////! - Initializing GUI Controller - _GuiController->init(); + _GuiController.init(); + //! - Initializing Main Timer + _MainTimer.init(); + //! - Initialize the Qml Viewer and starts GUI startGui(); Index: sources/applicationcontroller.cpp =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -24,9 +24,6 @@ #include "usbwatcher.h" #include "filehandler.h" -// Singleton -SINGLETON_INIT(ApplicationController) - /*! * \brief ApplicationController Constructor * \param parent @@ -52,28 +49,26 @@ void ApplicationController::initConnections() { - connect(_MainTimer , SIGNAL( didTimeout()), - this , SLOT(onMainTimerTimeout())); + connect(&_MainTimer , SIGNAL( didTimeout()), + this , SLOT(onMainTimerTimeout())); // From GUI - connect(_GuiController , SIGNAL(didActionTransmit(GuiActionType, const QVariantList &)), - this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); + connect(&_GuiController , SIGNAL(didActionTransmit(GuiActionType, const QVariantList &)), + this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); // From HD/DG - connect(_MessageDispatcher, SIGNAL(didActionReceive(GuiActionType, const QVariantList &)), - this , SLOT( onActionReceive(GuiActionType, const QVariantList &))); + connect(&_MessageDispatcher, SIGNAL(didActionReceive(GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive(GuiActionType, const QVariantList &))); - connect(_GuiController , SIGNAL(didUSBDriveUmount()), - this , SLOT( onUSBDriveUmount())); + connect(&_GuiController , SIGNAL(didUSBDriveUmount()), + this , SLOT( onUSBDriveUmount())); connect(&_USBWatcher , SIGNAL(didUSBDriveMount ()), - this , SLOT( onUSBDriveMount ())); + this , SLOT( onUSBDriveMount ())); connect(&_USBWatcher , SIGNAL(didUSBDriveRemove()), - this , SLOT( onUSBDriveRemove())); + this , SLOT( onUSBDriveRemove())); - connect(_GuiController , SIGNAL(didExportLog()), - this , SLOT( onExportLog())); - - + connect(&_GuiController , SIGNAL(didExportLog()), + this , SLOT( onExportLog())); } /*! Index: sources/applicationcontroller.h =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/applicationcontroller.h (.../applicationcontroller.h) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/applicationcontroller.h (.../applicationcontroller.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -38,7 +38,7 @@ ApplicationPost *_applicationPost = nullptr; // Singleton -SINGLETON_DECL(ApplicationController) +SINGLETON(ApplicationController) public: bool init(); Index: sources/canbus/caninterface.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -15,17 +15,16 @@ // Qt #include +#include // Project #include "logger.h" #include "frameinterface.h" +#include "messageglobals.h" // namespace using namespace Can; -// Singleton -SINGLETON_INIT(CanInterface) - /*! * \brief Caninterface Constructor * \param parent object @@ -39,32 +38,47 @@ */ bool CanInterface::init() { - QString mError; - _canDevice = QCanBus::instance()->createDevice(_canType, _canInterface, &mError); - if (!_canDevice) { - status(tr("Device Creation"), mError); - LOG_ERROR(status()); - return false; - } - _numberFramesWritten = 0; + // This is required for Signal/Slots in threading. + qRegisterMetaType("QCanBusFrame"); + // runs in main thread + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , "_CanInterface::init", "The Class initialization must be done in Main Thread" ); + _CanFrame_Thread.setObjectName("CAN Frame Thread"); + connect(qApp, &QApplication::aboutToQuit, this, &CanInterface::quit); + _CanFrame_Thread.start(); + moveToThread(&_CanFrame_Thread); + + if ( ! createDevice() ) return false; + if ( ! checkDevice () ) return false; + + _numberFramesWritten = 0; initConnections(); - if (!_canDevice->connectDevice()) { - status(tr("Connection")); - LOG_ERROR(status()); - delete _canDevice; - _canDevice = nullptr; - return false; - } status(tr("Connected")); LOG_EVENT(QObject::tr("CanInterface Initialized")); LOG_EVENT(status()); return true; } /*! + * \brief CanInterface quit + * \details Quit the CANBUS Interface by disconnecting the bus and device. + */ +void CanInterface::quit() +{ + deleteDevice(); + + // runs in Logger thread + moveToThread(qApp->thread()); + + // runs in main thread + _CanFrame_Thread.quit(); + _CanFrame_Thread.wait(); + +} + +/*! * \brief CanInterface status * \details CanInterface status description * \return The current stores status @@ -92,11 +106,59 @@ this , SLOT (onFrameWrittern(qint64))); } - connect(_FrameInterface, SIGNAL(didFrameTransmit(QCanBusFrame)), - this , SLOT( onFrameTransmit(QCanBusFrame))); + connect(&_FrameInterface, SIGNAL(didFrameTransmit(QCanBusFrame)), + this , SLOT( onFrameTransmit(QCanBusFrame))); } /*! + * \brief CanInterface::createDevice + * \details Creates the CANBus device + * \return false if can't create the device + */ +bool CanInterface::createDevice() +{ + QString mError; + _canDevice = QCanBus::instance()->createDevice(_canType, _canInterface, &mError); + if (!_canDevice) { + status(tr("Device Creation"), mError); + LOG_ERROR(status()); + return false; + } + return true; +} + +/*! + * \brief CanInterface::checkDevice + * \details Checks if the device has been connected. + * \return + */ +bool CanInterface::checkDevice() +{ + if (!_canDevice->connectDevice()) { + status(tr("Connection")); + LOG_ERROR(status()); + delete _canDevice; + _canDevice = nullptr; + return false; + } + return true; +} + +/*! + * \brief CanInterface::deleteDevice + * \details Disconnect the CANBus device and deletes the pointer + */ +void CanInterface::deleteDevice() +{ + if (!_canDevice) + return; + _canDevice->disconnectDevice(); + delete _canDevice; + _canDevice = nullptr; + status(tr("Disconnected")); +} + +/*! * \brief CanInterface status * \details Sets the Can interface status description * \param vDescription - Description about the CANBUS Interface errors @@ -159,22 +221,6 @@ } /*! - * \brief CanInterface quit - * \details Quit the CANBUS Interface by disconnecting the bus and device. - */ -void CanInterface::quit() -{ - if (!_canDevice) - return; - - _canDevice->disconnectDevice(); - delete _canDevice; - _canDevice = nullptr; - - status(tr("Disconnected")); -} - -/*! * \brief frameFlags * \details CANBUS message frame type as flags * \param vFrame - CANBUS message frame @@ -237,10 +283,10 @@ { if (!_canDevice) return; - while (_canDevice->framesAvailable()) { - // qDebug() << "framesAvailable : " << _canDevice->framesAvailable(); + //int i = _canDevice->framesAvailable(); const QCanBusFrame frame = _canDevice->readFrame(); + //qDebug() << "frame: #" << i << frame.toString(); consoleOut(frame); emit didFrameReceive(frame); } Index: sources/canbus/caninterface.h =================================================================== diff -u -r561055268da68e24fe91a1148b76bf1785dae14d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/caninterface.h (.../caninterface.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d) +++ sources/canbus/caninterface.h (.../caninterface.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -57,7 +57,8 @@ bool _enableConsoleOut = false; // Singleton - SINGLETON_DECL(CanInterface) + SINGLETON(CanInterface) + public: bool init(); void quit(); @@ -67,6 +68,10 @@ private: void initConnections(); + bool createDevice(); + bool checkDevice (); + void deleteDevice(); + void status (const QString &vDescription, QString vError = ""); bool transmit (const QCanBusFrame &vFrame); void consoleOut (const QCanBusFrame &vFrame); Index: sources/canbus/frameinterface.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/frameinterface.cpp (.../frameinterface.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/canbus/frameinterface.cpp (.../frameinterface.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -16,6 +16,7 @@ // Qt #include #include +#include // Project #include "logger.h" @@ -27,9 +28,6 @@ // namespace using namespace Can; -// Singleton -SINGLETON_INIT(FrameInterface) - /*! * \brief FrameInterface Constructor * \param parent @@ -39,12 +37,36 @@ /*! * \brief Message Handler initializer */ -void FrameInterface::init() +bool FrameInterface::init() { + // This is required for Signal/Slots in threading. + qRegisterMetaType("Can_Id"); + + // runs in main thread + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , "_FrameInterface::init", "The Class initialization must be done in Main Thread" ); + _CanFrame_Thread.setObjectName("Can Frame Thread"); + connect(qApp, &QApplication::aboutToQuit, this, &FrameInterface::quit); + _CanFrame_Thread.start(); + moveToThread(&_CanFrame_Thread); + + // runs in USB Watcher thread initConnections(); + LOG_EVENT(QObject::tr("FrameInterface Initialized")); + + return true; } +void FrameInterface::quit() +{ + // runs in Logger thread + moveToThread(qApp->thread()); + + // runs in main thread + _CanFrame_Thread.quit(); + _CanFrame_Thread.wait(); +} + /*! * \brief FrameInterface connections definition * \details Initializes the required signal/slot connection between this class and other objects @@ -53,12 +75,12 @@ void FrameInterface::initConnections() { // From GUI - connect(_MessageDispatcher, SIGNAL(didFrameTransmit(Can_Id, const QByteArray &)), - this , SLOT( onFrameTransmit(Can_Id, const QByteArray &))); + connect(&_MessageDispatcher, SIGNAL(didFrameTransmit(Can_Id, const QByteArray &)), + this , SLOT( onFrameTransmit(Can_Id, const QByteArray &))); // From CAN - connect(_CanInterface , SIGNAL( didFrameReceive( const QCanBusFrame &)), - this , SLOT( onFrameReceive( const QCanBusFrame &))); + connect(&_CanInterface , SIGNAL( didFrameReceive( const QCanBusFrame &)), + this , SLOT( onFrameReceive( const QCanBusFrame &))); } /*! Index: sources/canbus/frameinterface.h =================================================================== diff -u -r561055268da68e24fe91a1148b76bf1785dae14d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/frameinterface.h (.../frameinterface.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d) +++ sources/canbus/frameinterface.h (.../frameinterface.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -60,9 +60,10 @@ }; // Singleton - SINGLETON_DECL(FrameInterface) + SINGLETON(FrameInterface) public: - void init(); + bool init(); + void quit(); private: void initConnections(); Index: sources/canbus/messagedispatcher.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -14,6 +14,7 @@ #include "messagedispatcher.h" // Qt +#include // Project #include "logger.h" @@ -22,9 +23,6 @@ using namespace Can; -// Singleton -SINGLETON_INIT(MessageDispatcher) - /*! * \brief MessageDispatcher Constructor * \param parent @@ -34,12 +32,37 @@ /*! * \brief Message Handler initializer */ -void MessageDispatcher::init() +bool MessageDispatcher::init() { + // This is required for Signal/Slots in threading. + qRegisterMetaType("Can_Id"); + + // runs in main thread + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , "_MessageDispatcher::init", "The Class initialization must be done in Main Thread" ); + _CanMessage_Thread.setObjectName("Can Message Thread"); + connect(qApp, &QApplication::aboutToQuit, this, &MessageDispatcher::quit); + _CanMessage_Thread.start(); + moveToThread(&_CanMessage_Thread); + + + // runs in USBWatcher thread initConnections(); + LOG_EVENT(QObject::tr("MessageDispatcher Initialized")); + + return true; } +void MessageDispatcher::quit() +{ + // runs in Logger thread + moveToThread(qApp->thread()); + + // runs in main thread + _CanMessage_Thread.quit(); + _CanMessage_Thread.wait(); +} + /*! * \brief Message Handler connections definition * \details Initializes the required signal/slot connection between this class and other objects @@ -48,12 +71,12 @@ void MessageDispatcher::initConnections() { // From GUI - connect(_ApplicationController, SIGNAL(didActionTransmit(GuiActionType, const QVariantList &)), - this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); + connect(&_ApplicationController, SIGNAL(didActionTransmit(GuiActionType, const QVariantList &)), + this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); // From HD - connect(_FrameInterface , SIGNAL(didFrameReceive ( Can_Id, const QByteArray &)), - this , SLOT( onFrameReceive ( Can_Id, const QByteArray &))); + connect(&_FrameInterface , SIGNAL(didFrameReceive ( Can_Id, const QByteArray &)), + this , SLOT( onFrameReceive ( Can_Id, const QByteArray &))); } /*! @@ -71,8 +94,13 @@ // Append a message to the list if (_messageList[vCanId].isEmpty() || _messageList[vCanId].last().isComplete()) { _messageList[vCanId].append(Message()); - } - + //qDebug() << tr("Created a message for channel %1#%2").arg(vCanId).arg(Format::toHexString(vPayload)); + } /*else { + qDebug() << tr("Data for message on channel %1#%2").arg(vCanId).arg(Format::toHexString(vPayload)); + }*/ + //for (int i = 0; i < _messageList[vCanId].count(); ++i) { + // qDebug() << _messageList[vCanId][i].data.toHex('.'); + //} // build the message if (! _builder.buildMessage(vPayload, _messageList[vCanId].last(), vCanId)) { _messageList[vCanId].removeLast(); Index: sources/canbus/messagedispatcher.h =================================================================== diff -u -r561055268da68e24fe91a1148b76bf1785dae14d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/messagedispatcher.h (.../messagedispatcher.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d) +++ sources/canbus/messagedispatcher.h (.../messagedispatcher.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -91,9 +91,10 @@ friend class ::tst_canbus; // Singleton - SINGLETON_DECL(MessageDispatcher) + SINGLETON(MessageDispatcher) public: - void init(); + bool init(); + void quit(); void enableConsoleOut(bool vEnable) { _builder.enableConsoleOut(vEnable); } private: Index: sources/canbus/messageglobals.cpp =================================================================== diff -u --- sources/canbus/messageglobals.cpp (revision 0) +++ sources/canbus/messageglobals.cpp (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -0,0 +1,20 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * file messageglobals.cpp + * date 1/4/2020 + * author Behrouz NematiPour + * + */ + +#include "messageglobals.h" + +namespace Can { + QThread _CanFrame_Thread; + QThread _CanMessage_Thread; +} Index: sources/canbus/messageglobals.h =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/canbus/messageglobals.h (.../messageglobals.h) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/canbus/messageglobals.h (.../messageglobals.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -15,13 +15,18 @@ // Qt #include +#include // Project #include "guiglobals.h" using namespace Gui; namespace Can { +extern QThread _CanFrame_Thread; +extern QThread _CanMessage_Thread; + + /*! * \brief Payload Length * \details List of each ActionID required data (in byte) length in the message. Index: sources/gui/guicontroller.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -23,9 +23,6 @@ // namespace using namespace Gui; -// Singleton -SINGLETON_INIT(GuiController) - /*! * \brief GuiController Constructor * \param parent @@ -38,14 +35,14 @@ void GuiController::initConnections() { // From HD/DG - connect(_ApplicationController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), - this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + connect(&_ApplicationController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); // From OS : USB Drive has been removed physically. - connect(_ApplicationController, SIGNAL(didUSBDriveMount ()), - this , SLOT( onUSBDriveMount ())); - connect(_ApplicationController, SIGNAL(didUSBDriveRemove()), - this , SLOT( onUSBDriveRemove())); + connect(&_ApplicationController, SIGNAL(didUSBDriveMount ()), + this , SLOT( onUSBDriveMount ())); + connect(&_ApplicationController, SIGNAL(didUSBDriveRemove()), + this , SLOT( onUSBDriveRemove())); } /*! @@ -55,7 +52,6 @@ { initConnections(); LOG_EVENT(QObject::tr("Gui Controller Initialized")); - } /*! Index: sources/gui/guicontroller.h =================================================================== diff -u -r5963f00ffd2c557d3ae06a5deea05032a3a3bd68 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/gui/guicontroller.h (.../guicontroller.h) (revision 5963f00ffd2c557d3ae06a5deea05032a3a3bd68) +++ sources/gui/guicontroller.h (.../guicontroller.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -30,7 +30,7 @@ { Q_OBJECT -SINGLETON_DECL(GuiController) +SINGLETON(GuiController) public: void init(); Index: sources/gui/guiview.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/gui/guiview.cpp (.../guiview.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/gui/guiview.cpp (.../guiview.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -32,27 +32,27 @@ void GuiView::initConnections() { - connect(_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), - this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); // since we don't have access to GuiView object because it is created in Qml. // Connection to the GuiController made here // It should be defined in the class which wants to connect to signal. - connect(this , SIGNAL(didActionTransmit(GuiActionType,const QVariantList &)), - _GuiController, SLOT( doActionTransmit(GuiActionType,const QVariantList &))); + connect(this , SIGNAL(didActionTransmit(GuiActionType,const QVariantList &)), + &_GuiController, SLOT( doActionTransmit(GuiActionType,const QVariantList &))); // From UI : USB drive umount - connect(this , SIGNAL(didUSBDriveUmount()), - _GuiController, SLOT( doUSBDriveUmount())); + connect(this , SIGNAL(didUSBDriveUmount()), + &_GuiController, SLOT( doUSBDriveUmount())); // From OS : USB drive removed - connect(_GuiController, SIGNAL(didUSBDriveMount ()), - this , SLOT( doUSBDriveMount ())); - connect(_GuiController, SIGNAL(didUSBDriveRemove()), - this , SLOT( doUSBDriveRemove())); + connect(&_GuiController, SIGNAL(didUSBDriveMount ()), + this , SLOT( doUSBDriveMount ())); + connect(&_GuiController, SIGNAL(didUSBDriveRemove()), + this , SLOT( doUSBDriveRemove())); // From UI : Export Log - connect(this , SIGNAL(didExportLog()), - _GuiController, SLOT( doExportLog())); + connect(this , SIGNAL(didExportLog()), + &_GuiController, SLOT( doExportLog())); } void GuiView::onActionReceive (GuiActionType vAction, const QVariantList &vData) Index: sources/main.h =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/main.h (.../main.h) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/main.h (.../main.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -23,26 +23,14 @@ // Project -#define SINGLETON_DECL(vCLASS) \ -private: \ - static vCLASS *_instance; \ - explicit vCLASS(QObject *parent = nullptr); \ - virtual ~vCLASS() { \ - delete _instance; \ - } \ - vCLASS(vCLASS const &) = delete; \ - vCLASS & operator = (vCLASS const &) = delete; \ -public: \ - static vCLASS *I() { \ - if (!_instance) \ - _instance = new vCLASS(); \ - return _instance; \ - } +// TODO : A singleton parent class needs to be created +// to taking care of the Threading, init, quit, and so -#define SINGLETON_INIT(vCLASS) \ - vCLASS *vCLASS::_instance = nullptr; - - +// TODO : +// - We still need to work on threading on other classes +// - We need to have a singleton parent class +// - Some code has been added to debug can interface (We still have swap frames) +// - Thread Objects need to be gathered all together in one place to be handled easily. #define SINGLETON(vCLASS) \ private: \ explicit vCLASS(QObject *parent = nullptr); \ Index: sources/maintimer.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/maintimer.cpp (.../maintimer.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/maintimer.cpp (.../maintimer.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -18,9 +18,6 @@ //Project #include "logger.h" -// Singleton -SINGLETON_INIT(MainTimer) - /*! * \brief MainTimer Constructor * \param parent Index: sources/maintimer.h =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/maintimer.h (.../maintimer.h) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/maintimer.h (.../maintimer.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -33,7 +33,7 @@ static const int _interval = 1000; //ms // Singleton -SINGLETON_DECL(MainTimer) +SINGLETON(MainTimer) public: bool init(); void quit(); Index: sources/storage/logger.h =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/storage/logger.h (.../logger.h) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/storage/logger.h (.../logger.h) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -72,7 +72,6 @@ const char *_timeSeparator = " , "; // Singleton -//SINGLETON_DECL(Logger) SINGLETON(Logger) public: Index: sources/storage/storageglobals.cpp =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/storage/storageglobals.cpp (.../storageglobals.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/storage/storageglobals.cpp (.../storageglobals.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -14,9 +14,8 @@ #include "storageglobals.h" -namespace Storage { - - //QThread _Logger_Thread; +namespace Storage +{ QThread _USBWatcher_Thread; // USB @@ -26,5 +25,5 @@ // Log const char *Log_Base_Path_Name = "/media/sd-card/"; const char *Log_Base_Path_Name_Location = "/media/sd-card/log/"; - const char *Log_File_Name = "denali.log"; + const char *Log_File_Name = "denali.log"; } Index: sources/storage/usbwatcher.cpp =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- sources/storage/usbwatcher.cpp (.../usbwatcher.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/storage/usbwatcher.cpp (.../usbwatcher.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -61,7 +61,8 @@ void USBWatcher::initConnections() { - connect(_ApplicationController, SIGNAL(didUSBDriveUmount()), this, SLOT(onUSBDriveUmount())); + connect(&_ApplicationController, SIGNAL(didUSBDriveUmount()), + this , SLOT( onUSBDriveUmount())); } bool USBWatcher::isMounted() const Index: unittests/tst_canbus.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -re1605219ac2baf49ef21d0889f845ac53d59c3c1 --- unittests/tst_canbus.cpp (.../tst_canbus.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ unittests/tst_canbus.cpp (.../tst_canbus.cpp) (revision e1605219ac2baf49ef21d0889f845ac53d59c3c1) @@ -42,28 +42,28 @@ void tst_canbus::tst_CanInterface_Connect_Error_Interface() { QString mTr = tr("Error: Connection"); - Can::_CanInterface->_canInterface = "can1"; - Can::_CanInterface ->init(); - Can::_CanInterface ->enableConsoleOut(false); - QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr); + Can::_CanInterface ._canInterface = "can1"; + Can::_CanInterface .init(); + Can::_CanInterface .enableConsoleOut(false); + QCOMPARE(Can::_CanInterface.status().left(mTr.length()), mTr); } void tst_canbus::tst_CanInterface_Connect_NoError() { - Can::_CanInterface->_canInterface = "can0"; - Can::_CanInterface ->init(); - Can::_CanInterface ->enableConsoleOut(true); + Can::_CanInterface._canInterface = "can0"; + Can::_CanInterface.init(); + Can::_CanInterface.enableConsoleOut(true); QString mTr = tr("Connected"); - QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr); + QCOMPARE(Can::_CanInterface.status().left(mTr.length()), mTr); - Can::_CanInterface->onFrameReceive (); + Can::_CanInterface.onFrameReceive (); } void tst_canbus::tst_FrameInterface_Init() { - Can::_FrameInterface->init(); - Can::_MessageDispatcher->init(); - Can::_MessageDispatcher->enableConsoleOut(true); + Can::_FrameInterface .init(); + Can::_MessageDispatcher .init(); + Can::_MessageDispatcher .enableConsoleOut(true); connect(Can::_MessageDispatcher, &Can::MessageDispatcher::didFrameTransmit, [=](Can_Id vCanId , const QByteArray &vPayload) { _emited = true; @@ -87,38 +87,38 @@ void tst_canbus::tst_FrameInterface_ActionTransmit_KeepAlive() { _expected = "A5.07.00.00.E3.00.00.00"; - _MessageDispatcher->onActionTransmit(Gui::GuiActionType::KeepAlive, {}); + _MessageDispatcher.onActionTransmit(Gui::GuiActionType::KeepAlive, {}); QVERIFY(_emited); } void tst_canbus::tst_FrameInterface_TransmitFrame_LongerData() { _expected = QByteArray("123456789"); - _FrameInterface->transmitFrame(Can_Id::eChlid_HD, _expected); + _FrameInterface.transmitFrame(Can_Id::eChlid_HD, _expected); QCOMPARE(_emited, false); //there is no signal call - Code Coverage only : Error : "Payload can't be larger than 8 bytes" } void tst_canbus::tst_FrameInterface_ActionTransmit_PowerOff_Accepted() { _expected = "A5.01.00.01.01.5E.00.00"; QVariantList mData {static_cast(Gui::GuiActionData::Accepted)}; - _MessageDispatcher->onActionTransmit(Gui::GuiActionType::PowerOff, mData); + _MessageDispatcher.onActionTransmit(Gui::GuiActionType::PowerOff, mData); QVERIFY(_emited); } void tst_canbus::tst_FrameInterface_ActionTransmit_PowerOff_Rejected() { _expected = "A5.01.00.01.02.0D.00.00"; QVariantList mData {static_cast(Gui::GuiActionData::Rejected)}; - _MessageDispatcher->onActionTransmit(Gui::GuiActionType::PowerOff, mData); + _MessageDispatcher.onActionTransmit(Gui::GuiActionType::PowerOff, mData); QVERIFY(_emited); } void tst_canbus::tst_FrameInterface_ActionTransmit_PowerOff() { _expected = "A5.01.00.01.00.6F.00.00"; QVariantList mData {static_cast(Gui::GuiActionData::NoData)}; - _MessageDispatcher->onActionTransmit(Gui::GuiActionType::PowerOff, mData); + _MessageDispatcher.onActionTransmit(Gui::GuiActionType::PowerOff, mData); QVERIFY(_emited); } @@ -128,14 +128,14 @@ // which can be as long as 255 byte. _expected = "A5.FF.FF.03.41.42.43.EF"; QVariantList mData {"ABC"}; - _MessageDispatcher->onActionTransmit(Gui::GuiActionType::String, mData); + _MessageDispatcher.onActionTransmit(Gui::GuiActionType::String, mData); QVERIFY(_emited); } void tst_canbus::tst_FrameInterface_ActionTransmit_Unknown() { _expected = ""; - _MessageDispatcher->onActionTransmit(Gui::GuiActionType::Unknown, {}); + _MessageDispatcher.onActionTransmit(Gui::GuiActionType::Unknown, {}); QCOMPARE(_emited, false); // should not emit the signal due to unknown action } @@ -148,7 +148,7 @@ mFrame.setFrameId(Can::Can_Id::eChlid_HD); mPayload = "A5.01.00.01.00.6F.00.00"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QVERIFY(_emited); } @@ -161,7 +161,7 @@ mFrame.setFrameId(Can::Can_Id::eChlid_HD); mPayload = "A5.01.00.01.01.5E.00.00"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QVERIFY(_emited); } @@ -174,7 +174,7 @@ mFrame.setFrameId(Can::Can_Id::eChlid_HD_DG); mPayload = "A5.01.00.01.01.5E.00.00"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QCOMPARE(_emited, false); // should not be emitted due to not listening channel } @@ -187,7 +187,7 @@ mFrame.setFrameId(0x999); mPayload = "A5.01.00.01.01.5E.00.00"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QCOMPARE(_emited, false); // should not be emitted due to not listening channel } @@ -200,7 +200,7 @@ mFrame.setFrameId(Can::Can_Id::eChlid_HD); mPayload = "A5.01.00.01.00.66.00.00"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QCOMPARE(_emited, false); // Should not emit due to crc error } @@ -213,7 +213,7 @@ mFrame.setFrameId(Can::Can_Id::eChlid_HD); mPayload = "A5.01.00.01.00.6F"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QVERIFY(_emited); // Should not emit due to crc error } @@ -226,7 +226,7 @@ mFrame.setFrameId(Can::Can_Id::eChlid_HD); mPayload = "A5.01.00.01.00.6F.FF.FF.FF"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); QVERIFY(_emited); // Should not emit due to crc error } @@ -245,7 +245,7 @@ }; for ( QString payload : mPayloadList ) { mFrame.setPayload(QByteArray::fromHex(payload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); } QVERIFY(_emited); // Should not emit due to crc error } @@ -264,7 +264,7 @@ }; for ( QString payload : mPayloadList ) { mFrame.setPayload(QByteArray::fromHex(payload.remove(QLatin1Char('.')).toLatin1())); - emit Can::_CanInterface->didFrameReceive(mFrame); + emit Can::_CanInterface.didFrameReceive(mFrame); } QCOMPARE(_emited, false); // Should not emit due to - ERROR : "Incorrect data for Message ID (HD) '0x0500'" } @@ -280,7 +280,7 @@ void tst_canbus::cleanupTestCase() { - Can::_CanInterface->quit(); + Can::_CanInterface.quit(); QString mTr = tr("Disconnected"); - QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr); + QCOMPARE(Can::_CanInterface.status().left(mTr.length()), mTr); }