/*! * * 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 * \author (last) Behrouz NematiPour * \date (last) 07-May-2020 * \author (original) Behrouz NematiPour * \date (original) 07-Jan-2020 * */ #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) { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. // runs in main thread vThread.quit(); // validated vThread.wait(); // validated } // coco end /*! * \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() { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. quitThread(_CanFrame_Thread ); // validated quitThread(_CanAcknow_Thread ); // validated quitThread(_CanMessage_Thread ); // validated quitThread(_USBWatcher_Thread ); // validated quitThread(_Logger_Thread ); // validated quitThread(_Application_Thread ); // validated } // coco end }