Blame view

src/ormtransqueue.h 1.97 KB
5251bf3a   Steven de Ridder   Initial commit. d...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  #ifndef OSDEV_CAELUS_ORMTRANSQUEUE_H
  #define OSDEV_CAELUS_ORMTRANSQUEUE_H
  
  // Qt
  #include <QObject>
  #include <QTimer>
  #include <QMutex>
  #include <QMutexLocker>
  #include <QQueue>
  
  // Local
  #include "ormreldata.h"
  
  namespace osdev  {
  namespace caelus {
  
  class OrmTransQueue : public QObject
  {
      Q_OBJECT
  
  public:
      explicit OrmTransQueue( QObject *_parent = 0 );
  
      // Copy constructors.
  
      // Deleted copy- and move constructors
      OrmTransQueue( const OrmTransQueue& ) = delete;
      OrmTransQueue( const OrmTransQueue&& ) = delete;
      OrmTransQueue& operator=( const OrmTransQueue& ) = delete;
      OrmTransQueue& operator=( const OrmTransQueue&& ) = delete;
  
      // Timer control.
      /*!
       * \brief setTimeOut
       * \param msec
       */
      void    setTimeOut(int mseconds = 1 );
  
      // Queue control
      /*!
       * \brief   Inserts a ORMReldata objectpointer into the queue.
       * \param   pData - the (valid) pointer of the ORMRelData structure we want to queue for later processing
       * \return  True if transaction was saved to the queue successfully, false if not.
       */
      bool setTransaction( ORMRelData *pData );
  
      bool processing() const;
  
      void startProcessing( bool force = false );
  
      void stopProcessing( bool force = false );
  
      /*!
       * \brief   Returns the number of transactions stored in the queue.
       * \return  The number of transactions, or 0 if empty.
       */
      int  transactions_count() { return m_ormQueue.size(); }
  
  signals:
      void signalProcessData( ORMRelData *pData );
  
  private:
      QTimer              *m_pQueueTimer; ///< Timer controlling the processing of the queue.
      QMutex              *m_pQueueMutex; ///< Mutex to prevent race conditions.
      QQueue<ORMRelData*>  m_ormQueue;    ///< The actual FIFO taking a ORMRelData pointer as input.
  
  private slots:
      /*!
       * \brief slotProcessQueue
       */
      void slotProcessQueue();
  
  
  };
  
  }   /* End namespace caelus */
  }   /* End namespace osdev  */
  
  #endif  /* OSDEV_CAELUS_ORMTRANSQUEUE_H */