1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDBUSSERVICEWATCHER_H
5#define QDBUSSERVICEWATCHER_H
6
7#include <QtCore/QObject>
8#include <QtCore/qcontainerfwd.h> // Q(String)List
9#include <QtDBus/qtdbusglobal.h>
10
11#if !defined(QT_NO_DBUS) && !defined(QT_NO_QOBJECT)
12
13QT_BEGIN_NAMESPACE
14
15class QString;
16template<typename T>
17class QBindable;
18
19class QDBusConnection;
20
21class QDBusServiceWatcherPrivate;
22class Q_DBUS_EXPORT QDBusServiceWatcher: public QObject
23{
24 Q_OBJECT
25 Q_PROPERTY(QStringList watchedServices READ watchedServices WRITE setWatchedServices
26 BINDABLE bindableWatchedServices)
27 Q_PROPERTY(WatchMode watchMode READ watchMode WRITE setWatchMode BINDABLE bindableWatchMode)
28public:
29 enum WatchModeFlag {
30 WatchForRegistration = 0x01,
31 WatchForUnregistration = 0x02,
32 WatchForOwnerChange = 0x03
33 };
34 Q_DECLARE_FLAGS(WatchMode, WatchModeFlag)
35 Q_FLAG(WatchMode)
36
37 explicit QDBusServiceWatcher(QObject *parent = nullptr);
38 QDBusServiceWatcher(const QString &service, const QDBusConnection &connection,
39 WatchMode watchMode = WatchForOwnerChange, QObject *parent = nullptr);
40 ~QDBusServiceWatcher();
41
42 QStringList watchedServices() const;
43 void setWatchedServices(const QStringList &services);
44 void addWatchedService(const QString &newService);
45 bool removeWatchedService(const QString &service);
46 QBindable<QStringList> bindableWatchedServices();
47
48 WatchMode watchMode() const;
49 void setWatchMode(WatchMode mode);
50 QBindable<WatchMode> bindableWatchMode();
51
52 QDBusConnection connection() const;
53 void setConnection(const QDBusConnection &connection);
54
55Q_SIGNALS:
56 void serviceRegistered(const QString &service);
57 void serviceUnregistered(const QString &service);
58 void serviceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner);
59
60private:
61 Q_PRIVATE_SLOT(d_func(), void _q_serviceOwnerChanged(QString,QString,QString))
62 Q_DISABLE_COPY(QDBusServiceWatcher)
63 Q_DECLARE_PRIVATE(QDBusServiceWatcher)
64};
65
66Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusServiceWatcher::WatchMode)
67
68QT_END_NAMESPACE
69
70#endif // QT_NO_DBUS || QT_NO_QOBJECT
71#endif // QDBUSSERVICEWATCHER_H
72

source code of qtbase/src/dbus/qdbusservicewatcher.h