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.cpp
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.cpp
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 #include "ZMessageQueue.h"
26 #include <QtQml>
27 
28 namespace Zbl
29 {
30 
31 ZMessageQueue::ZMessageQueue(QObject *parent) :
32  QObject(parent)
33 {
34 }
35 
37 {
38  //ZBL_REGISTER_LOGGED_OBJECT
39 
40  qmlRegisterType<ZMessageQueue>("org.zuble.qml", 1, 0, "ZMessageQueue");
41 }
42 
43 void ZMessageQueue::sendMessage(QVariant message)
44 {
45  m_q.enqueue(message);
46 
48 }
49 
50 
51 void ZMessageQueue::queueMessage(QVariant message)
52 {
53  m_q.enqueue(message);
54 
55  QMetaObject::invokeMethod(this, "sendAvailableSignal",
56  Qt::QueuedConnection);
57 }
58 
60 {
61  if(m_q.count() > 0)
62  return m_q.dequeue();
63  else
64  return QVariant();
65 }
66 
68 {
69  if(m_q.count() > 0)
70  return m_q.head();
71  else
72  return QVariant();
73 }
74 
76 {
77  emit messageAvailable();
78 }
79 
81 {
82  return m_q.count();
83 }
84 
86 {
87  return m_q.count() == 0;
88 }
89 
90 
91 } // Zbl
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.
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()
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.