summaryrefslogtreecommitdiffstats
path: root/qt/qdbusstandardinterfaces.h
blob: af2c8dde3548f19e091ba416f445f49aa2aa2f6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* -*- C++ -*-
 *
 * Copyright (C) 2005 Thiago Macieira <thiago@kde.org>
 * Copyright (C) 2006 Trolltech AS. All rights reserved.
 *    Author: Thiago Macieira <thiago.macieira@trolltech.com>
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef QDBUS_STANDARD_INTERFACES_H
#define QDBUS_STANDARD_INTERFACES_H

#include "qdbusinterface.h"
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
#include <dbus/dbus.h>

class QDBusConnection;

class QDBUS_EXPORT QDBusPeerInterface: public QDBusInterface
{
public:
    static inline const char* staticInterfaceName()
    { return DBUS_INTERFACE_PEER; }

    static inline const char* staticIntrospectionData()
    {
        return
            "<interface name=\"org.freedesktop.DBus.Peer\">"
            "<method name=\"Ping\" />"
            "</interface>";
    }

public:
    explicit QDBusPeerInterface(const QDBusObject& obj)
        : QDBusInterface(obj, staticInterfaceName())
    { }

    QDBusPeerInterface(QDBusConnection& conn, const QString& service, const QString& path)
        : QDBusInterface(conn, service, path, staticInterfaceName())
    { }

    ~QDBusPeerInterface();

    inline virtual QString introspectionData() const
    { return staticIntrospectionData(); }

    inline void ping()
    { call(QLatin1String("Ping")); }
};

class QDBUS_EXPORT QDBusIntrospectableInterface: public QDBusInterface
{
public:
    static inline const char* staticInterfaceName()
    { return DBUS_INTERFACE_INTROSPECTABLE; }

    static inline const char* staticIntrospectionData()
    {
        return
            "<interface name=\"org.freedesktop.DBus.Introspectable\">"
            "<method name=\"Introspect\">"
            "<arg name=\"xml_data\" type=\"s\" direction=\"out\" />"
            "</method>"
            "</interface>";
    }
public:
    explicit QDBusIntrospectableInterface(const QDBusObject& obj)
        : QDBusInterface(obj, staticInterfaceName())
    { }

    QDBusIntrospectableInterface(QDBusConnection& conn, const QString& service, const QString& path)
        : QDBusInterface(conn, service, path, staticInterfaceName())
    { }

    ~QDBusIntrospectableInterface();

    inline virtual QString introspectionData() const
    { return staticIntrospectionData(); }
    
    inline QString introspect()
    { return call(QLatin1String("Introspect")).at(0).toString(); }
};

class QDBUS_EXPORT QDBusPropertiesInterface: public QDBusInterface
{
public:
    static inline const char* staticInterfaceName()
    { return DBUS_INTERFACE_PROPERTIES; }

    static inline const char* staticIntrospectionData()
    {
        return
            "<interface name=\"org.freedesktop.DBus.Properties\">"
            "<method name=\"Get\">"
            "<arg name=\"interface_name\" type=\"s\" direction=\"in\"/>"
            "<arg name=\"property_name\" type=\"s\" direction=\"in\"/>"
            "<arg name=\"value\" type=\"v\" direction=\"out\"/>"
            "</method>"
            "<method name=\"Set\">"
            "<arg name=\"interface_name\" type=\"s\" direction=\"in\"/>"
            "<arg name=\"property_name\" type=\"s\" direction=\"in\"/>"
            "<arg name=\"value\" type=\"v\" direction=\"in\"/>"
            "</method>";
            }
public:
    explicit QDBusPropertiesInterface(const QDBusObject& obj)
        : QDBusInterface(obj, staticInterfaceName())
    { }

    QDBusPropertiesInterface(QDBusConnection& conn, const QString& service, const QString& path)
        : QDBusInterface(conn, service, path, staticInterfaceName())
    { }

    ~QDBusPropertiesInterface();
    
    inline virtual QString introspectionData() const
    { return staticIntrospectionData(); }

    inline void set(const QString& interfaceName, const QString& propertyName, QVariant value)
    { call(QLatin1String("Set.ssv"), interfaceName, propertyName, value); }

    inline QVariant get(const QString& interfaceName, const QString& propertyName)
    { return call(QLatin1String("Get.ss"), interfaceName, propertyName).at(0); }
};

class QDBUS_EXPORT QDBusBusInterface: public QDBusInterface
{
public:
    static inline const char* staticInterfaceName()
    { return DBUS_INTERFACE_DBUS; }

    static const char* staticIntrospectionData();

public:
    explicit QDBusBusInterface(const QDBusObject& obj)
        : QDBusInterface(obj, staticInterfaceName())
    { }

    QDBusBusInterface(QDBusConnection& conn, const QString& service, const QString& path)
        : QDBusInterface(conn, service, path, staticInterfaceName())
    { }

    ~QDBusBusInterface();

    inline virtual QString introspectionData() const
    { return staticIntrospectionData(); }

    inline unsigned requestName(const QString& name, unsigned flags)
    { return call(QLatin1String("RequestName.su"), name, flags).at(0).toUInt(); }

    inline unsigned releaseName(const QString& name)
    { return call(QLatin1String("ReleaseName.s"), name).at(0).toUInt(); }

    inline unsigned startServiceByName(const QString& name, unsigned flags)
    { return call(QLatin1String("StartServiceByName.su"), name, flags).at(0).toUInt(); }

    inline QString Hello()
    { return call(QLatin1String("Hello")).at(0).toString(); }

    inline bool nameHasOwner(const QString& name)
    { return call(QLatin1String("NameHasOwner.s"), name).at(0).toBool(); }

    inline QStringList listNames()
    { return call(QLatin1String("ListNames")).at(0).toStringList(); }

    inline void addMatch(const QString& rule)
    { call(QLatin1String("AddMatch"), rule); }

    inline void removeMatch(const QString& rule)
    { call(QLatin1String("RemoveMatch"), rule); }

    inline QString getNameOwner(const QString& name)
    { return call(QLatin1String("GetNameOwner.s"), name).at(0).toString(); }

    inline QStringList listQueuedOwners(const QString& name)
    { return call(QLatin1String("ListQueuedOwners.s"), name).at(0).toStringList(); }

    inline quint32 getConnectionUnixUser(const QString& connectionName)
    { return call(QLatin1String("GetConnectionUnixUser.s"), connectionName).at(0).toUInt(); }

    inline quint32 getConnectionUnixProcessID(const QString& connectionName)
    { return call(QLatin1String("GetConnectionUnixProcessID.s"), connectionName).at(0).toUInt(); }

    inline QByteArray getConnectionSELinuxSecurityContext(const QString& connectionName)
    { return call(QLatin1String("GetConnectionSELinuxSecurityContext.s"), connectionName).at(0).toByteArray(); }

    inline void reloadConfig()
    { call(QLatin1String("ReloadConfig")); }
};
    

namespace org {
    namespace freedesktop {
        namespace DBus {
            typedef ::QDBusPeerInterface Peer;
            typedef ::QDBusIntrospectableInterface Introspectable;
            typedef ::QDBusPropertiesInterface Properties;
        }
    }
}

#endif