Music Hub  ..
A session-wide music playback service
stub_client_death_observer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
17  */
18 
20 
21 namespace media = core::ubuntu::media;
22 
23 namespace
24 {
25 typedef std::pair<media::Player::PlayerKey, std::weak_ptr<media::StubClientDeathObserver>> Holder;
26 }
27 
29 {
30  auto holder = static_cast<Holder*>(context);
31 
32  if (not holder)
33  return;
34 
35  // We check if we are still alive or if we already got killed.
36  if (auto sp = holder->second.lock())
37  {
38  sp->client_with_key_died(holder->first);
39  }
40 
41  // And with that, we have reached end of life for our holder object.
42  delete holder;
43 }
44 
45 // Creates an instance of the StubClientDeathObserver.
47 {
49 }
50 
51 media::StubClientDeathObserver::StubClientDeathObserver()
52 {
53 }
54 
56 {
57 }
58 
60 {
61 }
62 
63 const core::Signal<media::Player::PlayerKey>& media::StubClientDeathObserver::on_client_with_key_died() const
64 {
65  return client_with_key_died;
66 }
std::shared_ptr< ClientDeathObserver > Ptr
const core::Signal< Player::PlayerKey > & on_client_with_key_died() const override
void register_for_death_notifications_with_key(const Player::PlayerKey &) override