2 * Copyright (C) 2011-2014 Canonical, Ltd.
5 * Ugo Riboni <ugo.riboni@canonical.com>
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.
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.
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/>.
20#include "abstractdbusservicemonitor.h"
22#include <QDBusInterface>
23#include <QDBusServiceWatcher>
24#include <QDBusConnection>
25#include <QDBusConnectionInterface>
28AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(const QString &service, const QString &path,
29 const QString &interface, const Bus bus,
34 , m_interface(interface)
36 , m_watcher(new QDBusServiceWatcher(service,
37 (bus == SystemBus) ? QDBusConnection::systemBus()
38 : QDBusConnection::sessionBus()))
39 , m_dbusInterface(nullptr)
41 connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &AbstractDBusServiceMonitor::onServiceRegistered);
42 connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &AbstractDBusServiceMonitor::onServiceUnregistered);
44 // Connect to the service if it's up already
45 QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
46 QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
47 if (reply.isValid() && reply.value()) {
48 onServiceRegistered(m_service);
52AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()
55 delete m_dbusInterface;
58void AbstractDBusServiceMonitor::onServiceRegistered(const QString &)
60 if (m_dbusInterface != nullptr) {
61 delete m_dbusInterface;
62 m_dbusInterface = nullptr;
65 m_dbusInterface = createInterface(m_service, m_path, m_interface,
66 (m_bus == SystemBus) ? QDBusConnection::systemBus()
67 : QDBusConnection::sessionBus());
68 Q_EMIT serviceAvailableChanged(true);
72 * Default implementation creates a QDBusInterface. This performs blocking introspection of the
73 * service at initialization, which may be undesirable if the service is slow/blocked.
75QDBusAbstractInterface*
76AbstractDBusServiceMonitor::createInterface(const QString &service, const QString &path,
77 const QString &interface, const QDBusConnection &connection)
79 return new QDBusInterface(service, path, interface, connection);
82void AbstractDBusServiceMonitor::onServiceUnregistered(const QString &)
84 if (m_dbusInterface != nullptr) {
85 delete m_dbusInterface;
86 m_dbusInterface = nullptr;
89 Q_EMIT serviceAvailableChanged(false);
92QDBusAbstractInterface* AbstractDBusServiceMonitor::dbusInterface() const
94 return m_dbusInterface;
97bool AbstractDBusServiceMonitor::serviceAvailable() const
99 return m_dbusInterface != nullptr;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list