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
ZMailbox.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2016 Bob Dinitto
4  *
5  * Filename: ZMailbox.cpp
6  * Created on: 1/2/2016
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 <QVariant>
26 #include <QtQml>
27 #include "ZMailbox.h"
28 #include "ZMailslot.h"
29 #include "ZblApp.h"
30 
31 namespace Zbl {
32 
33 ZMailbox::ZMailbox(QObject *parent) :
34  QObject(parent)
35 {
36 }
37 
39 {
40  qmlRegisterType<ZMailbox>("org.zuble.qml", 1, 0, "ZMailbox");
41 }
42 
43 
44 void ZMailbox::setOwnerName(const QString& name)
45 {
46  m_ownerName = name;
47 }
48 
49 const QString ZMailbox::getOwnerName()
50 {
51  return m_ownerName;
52 }
53 
54 QObject* ZMailbox::mailslot(const QString& slotName)
55 {
56  return m_slots.value(slotName, NULL);
57 }
58 
59 QObject* ZMailbox::createMailslot(const QString& mailslot)
60 {
61  ZMailslot* newMailslot = NULL;
62 
63  if(!m_slots.contains(mailslot))
64  {
65  newMailslot = new ZMailslot(this);
66 
67  m_slots.insert(mailslot, newMailslot);
68 
69  emit mailslotCreated(m_ownerName, mailslot);
70  }
71 
72  return newMailslot;
73 }
74 
75 void ZMailbox::removeMailslot(const QString& mailslot)
76 {
77  ZMailslot* slot = m_slots.value(mailslot, NULL);
78 
79  if(slot)
80  {
81  m_slots.remove(mailslot);
82 
83  emit mailslotRemoved(m_ownerName, mailslot);
84 
85  slot->deleteLater();
86  }
87 }
88 
89 bool ZMailbox::hasMailslot(const QString& mailslot)
90 {
91  return m_slots.contains(mailslot);
92 }
93 
95 {
96  return(m_slots.keys());
97 }
98 
99 
100 } // Zbl
Q_INVOKABLE QObject * createMailslot(const QString &mailslot)
creates and returns the ZMailslot object for the named mailslot.
Definition: ZMailbox.cpp:59
void mailslotCreated(const QString &owner, const QString &mailslot)
Sent when a mail slot has been created.
ZMailbox(QObject *parent=0)
Definition: ZMailbox.cpp:33
Q_INVOKABLE QStringList getSlotNames()
Returns an array containing the names of all mailslots in the mailbox.
Definition: ZMailbox.cpp:94
zMailslotMap m_slots
Mail slots mapped by name.
Definition: ZMailbox.h:135
Q_INVOKABLE const QString getOwnerName()
Get the name of the mailbox owner.
Definition: ZMailbox.cpp:49
Definition: ZAndGate.cpp:6
Q_INVOKABLE QObject * mailslot(const QString &slotName)
Returns the ZMailslot object for the named mailslot.
Definition: ZMailbox.cpp:54
Q_INVOKABLE void removeMailslot(const QString &mailslot)
removes the ZMailslot object for the named mailslot from the Mailbox.
Definition: ZMailbox.cpp:75
QString m_ownerName
Name of the mailbox owner.
Definition: ZMailbox.h:141
A two-way buffered message stream with attached user-defined data cache.
Definition: ZMailslot.h:50
Q_INVOKABLE bool hasMailslot(const QString &mailslot)
Checks to see if a mailslot exists.
Definition: ZMailbox.cpp:89
static void registerType()
Register ZMailbox as a QML type.
Definition: ZMailbox.cpp:38
void mailslotRemoved(const QString &owner, const QString &mailslot)
Sent when a mail slot has been removed.
Q_INVOKABLE void setOwnerName(const QString &name)
Set the name of the mailbox owner.
Definition: ZMailbox.cpp:44