/*! * * 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 messageacknowmodel.h * \author (last) Behrouz NematiPour * \date (last) 07-May-2020 * \author (original) Behrouz NematiPour * \date (original) 17-Jan-2020 * */ #pragma once // Qt #include // Project #include "messageglobals.h" // Define #define _MessageAcknowModel Can::MessageAcknowModel::I() class tst_acknow; // namespace namespace Can { namespace Private { /*! * \brief The AcknowModel class * \details This is the private class of the MessageAcknowModel * which keeps list of the messages require Acknow. * but since Qt doesn't support nested meta objects, * it has been moved out with a meaningful namespace. */ class AcknowModel : public QObject { // Private Model Q_OBJECT friend class ::tst_acknow; const int _interval = 1000; // in ms int _timerId = 0; quint8 _retry = 5; Can_Id _can_Id = Can_Id::eChlid_NONE; Sequence _sequence = 0; FrameList _frameList ; explicit AcknowModel(QObject *parent = nullptr) : QObject (parent) { } public: AcknowModel(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList) : AcknowModel (nullptr) { _can_Id = vCan_Id ; _sequence = vSequence ; _frameList = vFrameList; } void start(); protected: /*! * \brief MessageAcknowModel::timerEvent * \details This event handler has been override in here * to receive timer events for the object * for the timer which has been set to _interval * emits the didFramesTransmit signal to retry transmitting the frames * emits the didFailedTransmit signal if exceeds retry limit. */ void timerEvent(QTimerEvent *) override { if ( _retry -- ) { emit didFramesTransmit(_can_Id, _sequence, _frameList); } else { killTimer(_timerId); emit didFailedTransmit(_sequence); } } signals: /*! * \brief didFramesTransmit * \details This signal is emitted when the requested Acknow has not been received during the _interval to retry to send message. * \param vCan_Id - Denali message Can channel * \param vSequence - Sequence number of the message which requires Acknow * \param vFrameList - List of the frames to be sent on retries. */ void didFramesTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList); // Retry /*! * \brief didFailedTransmit * \details This signal is emitted when the requested Acknow has not been received after all the _retry times of retries. * \param vSequence */ void didFailedTransmit( Sequence vSequence ); // Retry failed }; } /*! * \brief The MessageAcknowModel class * \details The wrapper class of the AcknowModel which does the thread handling. */ class MessageAcknowModel : public QObject { Q_OBJECT friend class ::tst_acknow; typedef QHash AcknowList; AcknowList _acknowList; QThread *_thread = nullptr; bool _init = false; // Singleton SINGLETON(MessageAcknowModel) public slots: bool init(); bool init(QThread &vThread); private slots: void quit(); private: void initConnections(); void initThread(QThread &vThread); void quitThread(); signals: /*! * \brief didFramesTransmit * \details This signal is the propagation signal to propagate the AcknowModel Message signal of the same name * when the requested Acknow has not been received during the _interval to retry to send message. * \param vCan_Id - Denali message Can channel * \param vSequence - Sequence number of the message which requires Acknow * \param vFrameList - List of the frames to be sent on retries. */ void didFramesTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList); // Retry /*! * \brief didFailedTransmit * \details This signal is the propagation signal to propagate the AcknowModel Message signal of the same name * when the requested Acknow has not been received after all the _retry times of retries. * \param vSequence */ void didFailedTransmit( Sequence vSequence ); // Retry failed private slots: void onFramesTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList); // Retry void onFailedTransmit( Sequence vSequence ); // Retry failed void onAcknowTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList); // Add void onAcknowReceive ( Sequence vSequence ); // Del }; }