SGL
geventqueue.h
1 /*
2  * File: geventqueue.h
3  * -------------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2021/04/03
9  * - removed dependency on custom collections
10  * @version 2018/09/07
11  * - added doc comments for new documentation generation
12  * @version 2018/08/23
13  * - renamed to geventqueue.h
14  * @version 2018/07/03
15  * - initial version
16  */
17 
18 
19 #ifndef _geventqueue_h
20 #define _geventqueue_h
21 
22 #include <queue>
23 #include <string>
24 #include <QObject>
25 #include <QReadWriteLock>
26 
27 #include "gevent.h"
28 #include "gtypes.h"
29 
30 namespace sgl {
31 
32 class GObservable;
33 class GThread;
34 class QtGui;
35 
48 class GEventQueue : public QObject {
49  Q_OBJECT
50 
51 public:
57  static GEventQueue* instance();
58 
63  int getEventMask() const;
64 
69  GEvent getNextEvent(int mask = ANY_EVENT);
70 
75  bool isAcceptingEvent(const GEvent& event) const;
76  bool isAcceptingEvent(int type) const;
77 
83  void setEventMask(int mask);
84 
91  GEvent waitForEvent(int mask = ANY_EVENT);
92 
93 signals:
97  void eventReady();
98 
99 private:
100  Q_DISABLE_COPY(GEventQueue)
101 
102  /*
103  * Prevents construction. Use instance() instead.
104  */
105  GEventQueue();
106 
107  GThunk dequeue();
108  void enqueueEvent(const GEvent& event);
109  bool isEmpty() const;
110  GThunk peek();
111  void runOnQtGuiThreadAsync(GThunk thunk);
112  void runOnQtGuiThreadSync(GThunk thunk);
113 
114  static GEventQueue* _instance;
115  std::queue<GThunk> _functionQueue;
116  std::queue<GEvent> _eventQueue;
117  QReadWriteLock _eventQueueMutex;
118  QReadWriteLock _functionQueueMutex;
119  int _eventMask;
120 
121  friend class GObservable;
122  friend class GThread;
123  friend class QtGui;
124 };
125 
126 } // namespace sgl
127 
128 #endif // _geventqueue_h
Definition: console.h:45
GEvent waitForEvent(int mask=ANY_EVENT)
Dismisses the process until an event occurs whose type is covered by the event mask.
Definition: geventqueue.cpp:176
Definition: gevent.h:62
GEvent getNextEvent(int mask=ANY_EVENT)
Checks to see if there are any events of the desired type waiting on the event queue.
Definition: geventqueue.cpp:163
std::function< void()> GThunk
An alias for a function wrapper around a void function with no parameters and no return.
Definition: gtypes.h:30