WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZMessageQueue.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2015 Bob Dinitto
4  *
5  * Filename: ZMessageQueue.h
6  * Created on: 12/29/2015
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef ZMESSAGEQUEUE_H
26 #define ZMESSAGEQUEUE_H
27 
28 #include <QObject>
29 #include <QQueue>
30 #include <QVariant>
31 //#include <QVariantMap>
32 
33 namespace Zbl
34 {
35 
54 class ZMessageQueue : public QObject
55 {
56  Q_OBJECT
57 public:
58  explicit ZMessageQueue(QObject *parent = 0);
59 
60  typedef QQueue<QVariant> zMsgQueue;
61 
65  static void registerType();
66 
71  Q_PROPERTY(int count READ getCount)
72 
73  int getCount();
74 
80  Q_INVOKABLE bool isEmpty();
81 
82 
83 signals:
84 
90  void messageAvailable();
91 
92 public slots:
93 
99  void sendMessage(QVariant message);
100 
107  void queueMessage(QVariant message);
108 
115  QVariant dequeueMessage();
116 
124  QVariant peekMessage();
125 
126 protected:
127 
128  Q_INVOKABLE void sendAvailableSignal();
129 
134  zMsgQueue m_q;
135 
136 };
137 
138 } // Zbl
139 
140 #endif // ZMESSAGEQUEUE_H
void messageAvailable()
Sent when a message has been placed into the message queue.
void queueMessage(QVariant message)
Enqueues message immediately, then queues a defered messageAvailable signal to be sent later...
QVariant dequeueMessage()
Removes next message from message queue and returns it.
A message queue that decouples sending and processing of messages.
Definition: ZMessageQueue.h:54
Definition: ZAndGate.cpp:6
Q_INVOKABLE bool isEmpty()
Returns true if message queue is empty, false if one or more messages are in the queue.
Q_INVOKABLE void sendAvailableSignal()
int count
Returns the number of messages in the queue.
Definition: ZMessageQueue.h:71
void sendMessage(QVariant message)
Enqueues message and then sends messageAvailable signal immediately.
ZMessageQueue(QObject *parent=0)
zMsgQueue m_q
The message queue.
static void registerType()
Registers ZMessageQueue as a QML type.
QVariant peekMessage()
Returns the next message from message queue without removing it from the queue.
QQueue< QVariant > zMsgQueue
Definition: ZMessageQueue.h:60