Lomiri
Loading...
Searching...
No Matches
abstractdbusservicemonitor.h
1/*
2 * Copyright (C) 2011-2014 Canonical Ltd.
3 *
4 * Authors:
5 * Ugo Riboni <ugo.riboni@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef ABSTRACTDBUSSERVICEMONITOR_H
21#define ABSTRACTDBUSSERVICEMONITOR_H
22
23#include <QObject>
24#include <QString>
25#include <QDBusConnection>
26
27class QDBusAbstractInterface;
28class QDBusServiceWatcher;
29
30class Q_DECL_EXPORT AbstractDBusServiceMonitor : public QObject
31{
32 Q_OBJECT
33 Q_PROPERTY(bool serviceAvailable READ serviceAvailable NOTIFY serviceAvailableChanged)
34
35public:
36 enum Bus {
37 SessionBus,
38 SystemBus,
39 };
40 Q_ENUM(Bus)
41
42 explicit AbstractDBusServiceMonitor(const QString &service, const QString &path, const QString &interface,
43 const Bus bus = SessionBus,
44 QObject *parent = 0);
45 ~AbstractDBusServiceMonitor();
46
47 QDBusAbstractInterface* dbusInterface() const;
48
49 bool serviceAvailable() const;
50
51Q_SIGNALS:
52 void serviceAvailableChanged(bool available);
53
54private Q_SLOTS:
55 void onServiceRegistered(const QString &service);
56 void onServiceUnregistered(const QString &service);
57
58protected:
59 virtual QDBusAbstractInterface* createInterface(const QString &service, const QString &path,
60 const QString &interface, const QDBusConnection &connection);
61
62 const QString m_service;
63 const QString m_path;
64 const QString m_interface;
65 const Bus m_bus;
66 QDBusServiceWatcher* m_watcher;
67 QDBusAbstractInterface* m_dbusInterface;
68};
69
70#endif // ABSTRACTDBUSSERVICEMONITOR_H