Music Hub  ..
A session-wide music playback service
hybris_client_death_observer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 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: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
20 
21 #include <hybris/media/media_codec_layer.h>
22 
23 namespace media = core::ubuntu::media;
24 
25 
26 namespace
27 {
28 typedef std::pair<media::Player::PlayerKey, std::weak_ptr<media::HybrisClientDeathObserver>> Holder;
29 }
30 
32 {
33  auto holder = static_cast<Holder*>(context);
34 
35  if (not holder)
36  return;
37 
38  // We check if we are still alive or if we already got killed.
39  if (auto sp = holder->second.lock())
40  {
41  sp->client_with_key_died(holder->first);
42  }
43 
44  // And with that, we have reached end of life for our holder object.
45  delete holder;
46 }
47 
48 // Creates an instance of the HybrisClientDeathObserver or throws
49 // if the underlying platform does not support it.
51 {
53 }
54 
55 media::HybrisClientDeathObserver::HybrisClientDeathObserver()
56 {
57 }
58 
60 {
61 }
62 
64 {
65  decoding_service_set_client_death_cb(&media::HybrisClientDeathObserver::on_client_died_cb, key, new Holder{key, shared_from_this()});
66 }
67 
68 const core::Signal<media::Player::PlayerKey>& media::HybrisClientDeathObserver::on_client_with_key_died() const
69 {
70  return client_with_key_died;
71 }
std::shared_ptr< ClientDeathObserver > Ptr
void register_for_death_notifications_with_key(const Player::PlayerKey &) override
const core::Signal< Player::PlayerKey > & on_client_with_key_died() const override