/*! * * 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 threads.cpp * date 1/6/2020 * author Behrouz NematiPour * */ #include "threads.h" // Qt #include #include // Application #include "messageglobals.h" #include "logger.h" /*! * \details All the Thread has been and shall be defined in here * And will be assigned to a required class from main thread. * \note quitThreads() needs to be called when the application execution event loop is done * this has currently been done in main.cpp in main() after the qpp.exe() is done. */ namespace Threads { QThread _CanFrame_Thread ; QThread _CanAcknow_Thread ; QThread _CanMessage_Thread ; QThread _USBWatcher_Thread ; QThread _Logger_Thread ; QThread _Application_Thread ; /*! * \brief registerTypes * \details this method has to be called before any class which uses these types * and also is handled by threads * It seems qt is using the meta objects for threading signal/slots * and it requires any type which has been used in this context to be registered. */ void registerTypes() { // Logger : This is required for Signal/Slots in threading. qRegisterMetaType("LogType"); // CanInterface : This is required for Signal/Slots in threading. qRegisterMetaType("QCanBusFrame"); // FrameInterface : This is required for Signal/Slots in threading. qRegisterMetaType("Can_Id"); // MessageAcknowModel : This is required for Signal/Slots in threading. qRegisterMetaType("Sequence"); // MessageAcknowModel : This is required for Signal/Slots in threading. qRegisterMetaType("FrameList"); } /*! * \brief quitThread * \details quits the thread vThread and wait for it to be destroyed. * \param vThread - the thread */ void quitThread(QThread &vThread) { // runs in main thread vThread.quit(); vThread.wait(); } /*! * \brief quitThreads * \details quits the list of the threads which has been defined * int the Threads namespace * \note It requires to be updated by developer if any more thread has been added */ void quitThreads() { quitThread(_CanFrame_Thread ); quitThread(_CanAcknow_Thread ); quitThread(_CanMessage_Thread ); quitThread(_USBWatcher_Thread ); quitThread(_Logger_Thread ); quitThread(_Application_Thread ); } }