Music Hub  ..
A session-wide music playback service
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 
27 namespace media = lomiri::MediaHubService;
28 
31 {
32  QObject::connect(&m_watcher, &QDBusServiceWatcher::serviceUnregistered,
34  m_watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
35  m_watcher.setConnection(QDBusConnection::sessionBus());
36 }
37 
39 {
40 }
41 
42 void 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 
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 }
lomiri::MediaHubService::DBusClientDeathObserver::registerForDeathNotifications
void registerForDeathNotifications(const Player::Client &) override
Definition: dbus_client_death_observer.cpp:55
lomiri::MediaHubService::ClientDeathObserver
Definition: client_death_observer.h:39
dbus_client_death_observer.h
lomiri::MediaHubService::DBusClientDeathObserver::~DBusClientDeathObserver
~DBusClientDeathObserver()
Definition: dbus_client_death_observer.cpp:38
lomiri::MediaHubService::ClientDeathObserverPrivate
Definition: client_death_observer_p.h:27
lomiri::MediaHubService
Definition: context.h:28
lomiri::MediaHubService::DBusClientDeathObserver::onServiceDied
void onServiceDied(const QString &serviceName)
Definition: dbus_client_death_observer.cpp:42
lomiri::MediaHubService::DBusClientDeathObserver::DBusClientDeathObserver
DBusClientDeathObserver(ClientDeathObserver *q)
Definition: dbus_client_death_observer.cpp:29
MH_DEBUG
#define MH_DEBUG(...)
Definition: logging.h:38
logging.h