File indexing completed on 2025-01-05 04:55:03
0001 /* 0002 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 This library is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to the 0016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA. 0018 */ 0019 #pragma once 0020 0021 #include "kube_export.h" 0022 #include <QObject> 0023 #include <QVariant> 0024 #include <QVector> 0025 0026 namespace Kube { 0027 /** 0028 * The Fabric is a publish/subscribe message bus to interconnect components in kube. 0029 * 0030 * It provides a background mesh ("the fabric"), that interconnects various parts of kube. 0031 * This is useful as it allows us to decouple functionality from the UI components, and keeps us from writing unnecessary API 0032 * for visual components to pass through all necessary information for interaction. 0033 */ 0034 namespace Fabric { 0035 0036 class KUBE_EXPORT Fabric : public QObject { 0037 Q_OBJECT 0038 public: 0039 Q_INVOKABLE void postMessage(const QString &id, const QVariantMap &); 0040 }; 0041 0042 /** 0043 * A message handler. 0044 * 0045 * Can beinstantiated from QML like so: 0046 * Listener { 0047 * function onMessageReceived(msg) { 0048 * ...do something 0049 * } 0050 * } 0051 */ 0052 class KUBE_EXPORT Listener : public QObject 0053 { 0054 Q_OBJECT 0055 Q_PROPERTY(QString filter MEMBER mFilter) 0056 0057 public: 0058 Listener(QObject *parent = 0); 0059 virtual ~Listener(); 0060 0061 virtual void notify(const QString &id, const QVariantMap ¬ification); 0062 0063 signals: 0064 void messageReceived(const QVariantMap &message); 0065 0066 private: 0067 QString mFilter; 0068 }; 0069 0070 } 0071 }