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 test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef INTERFACE_H |
30 | #define INTERFACE_H |
31 | |
32 | #include <QtCore/QObject> |
33 | #include <QtCore/QHash> |
34 | #include <QtDBus/QDBusArgument> |
35 | |
36 | struct RegisteredType |
37 | { |
38 | inline RegisteredType(const QString &str = QString()) : s(str) {} |
39 | inline bool operator==(const RegisteredType &other) const { return s == other.s; } |
40 | QString s; |
41 | }; |
42 | Q_DECLARE_METATYPE(RegisteredType) |
43 | |
44 | inline QDBusArgument &operator<<(QDBusArgument &s, const RegisteredType &data) |
45 | { |
46 | s.beginStructure(); |
47 | s << data.s; |
48 | s.endStructure(); |
49 | return s; |
50 | } |
51 | |
52 | inline const QDBusArgument &operator>>(const QDBusArgument &s, RegisteredType &data) |
53 | { |
54 | s.beginStructure(); |
55 | s >> data.s; |
56 | s.endStructure(); |
57 | return s; |
58 | } |
59 | |
60 | struct UnregisteredType |
61 | { |
62 | QString s; |
63 | }; |
64 | Q_DECLARE_METATYPE(UnregisteredType) |
65 | |
66 | class Interface: public QObject |
67 | { |
68 | Q_OBJECT |
69 | Q_CLASSINFO("D-Bus Interface", "org.qtproject.QtDBus.Pinger") |
70 | Q_PROPERTY(QString stringProp READ stringProp WRITE setStringProp SCRIPTABLE true) |
71 | Q_PROPERTY(QDBusVariant variantProp READ variantProp WRITE setVariantProp SCRIPTABLE true) |
72 | Q_PROPERTY(RegisteredType complexProp READ complexProp WRITE setComplexProp SCRIPTABLE true) |
73 | |
74 | friend class tst_QDBusAbstractInterface; |
75 | friend class PingerServer; |
76 | QString m_stringProp; |
77 | QDBusVariant m_variantProp; |
78 | RegisteredType m_complexProp; |
79 | |
80 | public: |
81 | Interface(); |
82 | |
83 | QString stringProp() const { return m_stringProp; } |
84 | void setStringProp(const QString &s) { m_stringProp = s; } |
85 | QDBusVariant variantProp() const { return m_variantProp; } |
86 | void setVariantProp(const QDBusVariant &v) { m_variantProp = v; } |
87 | RegisteredType complexProp() const { return m_complexProp; } |
88 | void setComplexProp(const RegisteredType &r) { m_complexProp = r; } |
89 | |
90 | public slots: |
91 | Q_SCRIPTABLE void voidMethod() {} |
92 | Q_SCRIPTABLE int sleepMethod(int); |
93 | Q_SCRIPTABLE QString stringMethod() { return "Hello, world"; } |
94 | Q_SCRIPTABLE RegisteredType complexMethod(const QVariantHash &vars) { return RegisteredType(vars.value(akey: "arg1").toString()); } |
95 | Q_SCRIPTABLE QString multiOutMethod(int &value) { value = 42; return "Hello, world"; } |
96 | |
97 | signals: |
98 | Q_SCRIPTABLE void voidSignal(); |
99 | Q_SCRIPTABLE void stringSignal(const QString &); |
100 | Q_SCRIPTABLE void complexSignal(RegisteredType); |
101 | }; |
102 | |
103 | #endif // INTERFACE_H |
104 |