1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 //
41 //  W A R N I N G
42 //  -------------
43 //
44 // This file is not part of the public API.  This header file may
45 // change from version to version without notice, or even be
46 // removed.
47 //
48 // We mean it.
49 //
50 //
51 
52 #ifndef QDBUSABSTRACTADAPTOR_P_H
53 #define QDBUSABSTRACTADAPTOR_P_H
54 
55 #include <QtDBus/private/qtdbusglobal_p.h>
56 #include <qdbusabstractadaptor.h>
57 
58 #include <QtCore/qobject.h>
59 #include <QtCore/qmap.h>
60 #include <QtCore/qreadwritelock.h>
61 #include <QtCore/qvariant.h>
62 #include <QtCore/qvector.h>
63 #include "private/qobject_p.h"
64 
65 #define QCLASSINFO_DBUS_INTERFACE       "D-Bus Interface"
66 #define QCLASSINFO_DBUS_INTROSPECTION   "D-Bus Introspection"
67 
68 #ifndef QT_NO_DBUS
69 
70 #ifdef interface
71 #  undef interface
72 #endif
73 
74 QT_BEGIN_NAMESPACE
75 
76 class QDBusAbstractAdaptor;
77 class QDBusAdaptorConnector;
78 class QDBusAdaptorManager;
79 class QDBusConnectionPrivate;
80 
81 class QDBusAbstractAdaptorPrivate: public QObjectPrivate
82 {
Q_DECLARE_PUBLIC(QDBusAbstractAdaptor)83     Q_DECLARE_PUBLIC(QDBusAbstractAdaptor)
84 public:
85     QDBusAbstractAdaptorPrivate() : autoRelaySignals(false) {}
86     QString xml;
87     bool autoRelaySignals;
88 
89     static QString retrieveIntrospectionXml(QDBusAbstractAdaptor *adaptor);
90     static void saveIntrospectionXml(QDBusAbstractAdaptor *adaptor, const QString &xml);
91 };
92 
93 class QDBusAdaptorConnector: public QObject
94 {
95     Q_OBJECT_FAKE
96 
97 public: // typedefs
98     struct AdaptorData
99     {
100         const char *interface;
101         QDBusAbstractAdaptor *adaptor;
102 
103         inline bool operator<(const AdaptorData &other) const
104         { return QByteArray(interface) < other.interface; }
105         inline bool operator<(const QString &other) const
106         { return QLatin1String(interface) < other; }
107         inline bool operator<(const QByteArray &other) const
108         { return interface < other; }
109     };
110     typedef QVector<AdaptorData> AdaptorMap;
111 
112 public: // methods
113     explicit QDBusAdaptorConnector(QObject *parent);
114     ~QDBusAdaptorConnector();
115 
116     void addAdaptor(QDBusAbstractAdaptor *adaptor);
117     void connectAllSignals(QObject *object);
118     void disconnectAllSignals(QObject *object);
119     void relay(QObject *sender, int id, void **);
120 
121 //public slots:
122     void relaySlot(void **);
123     void polish();
124 
125 protected:
126 //signals:
127     void relaySignal(QObject *obj, const QMetaObject *metaObject, int sid, const QVariantList &args);
128 
129 public: // member variables
130     AdaptorMap adaptors;
131     bool waitingForPolish : 1;
132 
133 private:
134     static int relaySlotMethodIndex();
135 };
136 Q_DECLARE_TYPEINFO(QDBusAdaptorConnector::AdaptorData, Q_PRIMITIVE_TYPE);
137 
138 extern QDBusAdaptorConnector *qDBusFindAdaptorConnector(QObject *object);
139 extern QDBusAdaptorConnector *qDBusCreateAdaptorConnector(QObject *object);
140 
141 QT_END_NAMESPACE
142 
143 #endif // QT_NO_DBUS
144 #endif // QDBUSABSTRACTADAPTOR_P_H
145