Music Hub ..
A session-wide music playback service
 
Loading...
Searching...
No Matches
dbus_client_death_observer.cpp
Go to the documentation of this file.
1/*
2 * Copyright © 2021-2022 UBports Foundation.
3 *
4 * Contact: Alberto Mardegan <mardy@users.sourceforge.net>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
20
21#include "logging.h"
22
23#include <QDBusConnection>
24#include <QPair>
25#include <QPointer>
26
28
29media::DBusClientDeathObserver::DBusClientDeathObserver(ClientDeathObserver *q):
31{
32 QObject::connect(&m_watcher, &QDBusServiceWatcher::serviceUnregistered,
34 m_watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
35 m_watcher.setConnection(QDBusConnection::sessionBus());
36}
37
38media::DBusClientDeathObserver::~DBusClientDeathObserver()
39{
40}
41
42void media::DBusClientDeathObserver::onServiceDied(const QString &serviceName)
43{
44 MH_DEBUG() << "Client died:" << serviceName;
45 for (int i = 0; i < m_clients.count(); i++) {
46 const media::Player::Client &client = m_clients[i];
47 if (serviceName == client.name) {
48 notifyClientDeath(client);
49 m_clients.removeAt(i);
50 break;
51 }
52 }
53}
54
55void media::DBusClientDeathObserver::registerForDeathNotifications(
56 const media::Player::Client &client)
57{
58 MH_DEBUG() << "Watching for client name" << client.name;
59 for (const media::Player::Client &c: m_clients) {
60 if (client == c) return; // nothing to do
61 }
62 m_clients.append(client);
63
64 m_watcher.addWatchedService(client.name);
65}
#define MH_DEBUG(...)
Definition logging.h:38