/*! * * 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 * date 1/17/2020 * author Behrouz NematiPour * */ #pragma once // Qt #include // Project #include "messageglobals.h" // Define #define _MessageAcknowModel Can::MessageAcknowModel::I() // namespace namespace Can { namespace Private { /*! * \brief The AcknowModel class * \details This is the private class of the MessageAcknowModel * 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 const int _interval = 1000; // in ms int _timerId = 0; quint8 _retry = 9; 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() { _timerId = startTimer(_interval); } protected: /*! * \brief MessageAcknowModel::timerEvent * \details This event handler has been overrode 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: void didFramesTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList); // Retry void didFailedTransmit( Sequence vSequence ); // Retry failed }; } class MessageAcknowModel : public QObject { Q_OBJECT 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: void didFramesTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList); // Retry 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 }; }