Unity 8
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 
27 class QDBusAbstractInterface;
28 class QDBusServiceWatcher;
29 
30 class Q_DECL_EXPORT AbstractDBusServiceMonitor : public QObject
31 {
32  Q_OBJECT
33  Q_ENUMS(Bus)
34  Q_PROPERTY(bool serviceAvailable READ serviceAvailable NOTIFY serviceAvailableChanged)
35 
36 public:
37  enum Bus {
38  SessionBus,
39  SystemBus,
40  };
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 
51 Q_SIGNALS:
52  void serviceAvailableChanged(bool available);
53 
54 private Q_SLOTS:
55  void onServiceRegistered(const QString &service);
56  void onServiceUnregistered(const QString &service);
57 
58 protected:
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