SGL
geventqueue.h
1 /*
2  * File: geventqueue.h
3  * -------------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/03
7  * - removed dependency on custom collections
8  * @version 2018/09/07
9  * - added doc comments for new documentation generation
10  * @version 2018/08/23
11  * - renamed to geventqueue.h
12  * @version 2018/07/03
13  * - initial version
14  */
15 
16 
17 #ifndef _geventqueue_h
18 #define _geventqueue_h
19 
20 #include <queue>
21 #include <string>
22 #include <QObject>
23 #include <QReadWriteLock>
24 
25 #include "gevent.h"
26 #include "gtypes.h"
27 
28 class GObservable;
29 class GThread;
30 class QtGui;
31 
44 class GEventQueue : public QObject {
45  Q_OBJECT
46 
47 public:
53  static GEventQueue* instance();
54 
59  int getEventMask() const;
60 
65  GEvent getNextEvent(int mask = ANY_EVENT);
66 
71  bool isAcceptingEvent(const GEvent& event) const;
72  bool isAcceptingEvent(int type) const;
73 
79  void setEventMask(int mask);
80 
87  GEvent waitForEvent(int mask = ANY_EVENT);
88 
89 signals:
93  void eventReady();
94 
95 private:
96  Q_DISABLE_COPY(GEventQueue)
97 
98  /*
99  * Prevents construction. Use instance() instead.
100  */
101  GEventQueue();
102 
103  GThunk dequeue();
104  void enqueueEvent(const GEvent& event);
105  bool isEmpty() const;
106  GThunk peek();
107  void runOnQtGuiThreadAsync(GThunk thunk);
108  void runOnQtGuiThreadSync(GThunk thunk);
109 
110  static GEventQueue* _instance;
111  std::queue<GThunk> _functionQueue;
112  std::queue<GEvent> _eventQueue;
113  QReadWriteLock _eventQueueMutex;
114  QReadWriteLock _functionQueueMutex;
115  int _eventMask;
116 
117  friend class GObservable;
118  friend class GThread;
119  friend class QtGui;
120 };
121 
122 #endif // _geventqueue_h
A GEvent represents a user action that has occurred on a graphical interactor.
Definition: gevent.h:153
A GObservable object is one that is able to send out events.
Definition: gobservable.h:36
The GThread class is a utility class containing static methods that allow you to run code on various ...
Definition: gthread.h:111