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 MYOBJECT_H
30#define MYOBJECT_H
31
32#include <QtCore/QObject>
33#include <QtDBus/QtDBus>
34
35
36class MyObject: public QObject, protected QDBusContext
37{
38 Q_OBJECT
39 Q_CLASSINFO("D-Bus Interface", "org.qtproject.QtDBus.MyObject")
40 Q_CLASSINFO("D-Bus Introspection", ""
41" <interface name=\"org.qtproject.QtDBus.MyObject\" >\n"
42" <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n"
43" <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n"
44" <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"QList&lt;int&gt;\"/>\n"
45" </property>\n"
46" <signal name=\"somethingHappened\" >\n"
47" <arg direction=\"out\" type=\"s\" />\n"
48" </signal>\n"
49" <method name=\"ping\" >\n"
50" <arg direction=\"in\" type=\"v\" name=\"ping\" />\n"
51" <arg direction=\"out\" type=\"v\" name=\"ping\" />\n"
52" </method>\n"
53" <method name=\"ping_invokable\" >\n"
54" <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n"
55" <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n"
56" </method>\n"
57" <method name=\"ping\" >\n"
58" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n"
59" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n"
60" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
61" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n"
62" </method>\n"
63" <method name=\"ping_invokable\" >\n"
64" <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n"
65" <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n"
66" <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n"
67" <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n"
68" </method>\n"
69" <method name=\"ping\" >\n"
70" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n"
71" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n"
72" <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
73" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
74" </method>\n"
75" <method name=\"ping_invokable\" >\n"
76" <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n"
77" <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n"
78" <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
79" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
80" </method>\n"
81" </interface>\n"
82 "")
83 Q_PROPERTY(int prop1 READ prop1 WRITE setProp1)
84 Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp)
85
86public:
87 static int callCount;
88 static QVariantList callArgs;
89 MyObject()
90 {
91 QObject *subObject = new QObject(this);
92 subObject->setObjectName("subObject");
93 }
94
95 int m_prop1;
96 int prop1() const
97 {
98 ++callCount;
99 return m_prop1;
100 }
101 void setProp1(int value)
102 {
103 ++callCount;
104 m_prop1 = value;
105 }
106
107 QList<int> m_complexProp;
108 QList<int> complexProp() const
109 {
110 ++callCount;
111 return m_complexProp;
112 }
113 void setComplexProp(const QList<int> &value)
114 {
115 ++callCount;
116 m_complexProp = value;
117 }
118
119 Q_INVOKABLE void ping_invokable(QDBusMessage msg)
120 {
121 Q_ASSERT(QDBusContext::calledFromDBus());
122 ++callCount;
123 callArgs = msg.arguments();
124
125 msg.setDelayedReply(true);
126 if (!QDBusContext::connection().send(message: msg.createReply(arguments: callArgs)))
127 exit(status: 1);
128 }
129
130public slots:
131
132 void ping(QDBusMessage msg)
133 {
134 Q_ASSERT(QDBusContext::calledFromDBus());
135 ++callCount;
136 callArgs = msg.arguments();
137
138 msg.setDelayedReply(true);
139 if (!QDBusContext::connection().send(message: msg.createReply(arguments: callArgs)))
140 exit(status: 1);
141 }
142};
143
144#endif // INTERFACE_H
145

source code of qtbase/tests/auto/dbus/qdbusinterface/myobject.h