• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_MEDIASERVICE_DEATHRECIPIENT_H
18 #define ANDROID_MEDIASERVICE_DEATHRECIPIENT_H
19 
20 #include <binder/binder.h>
21 #include <hidl/HidlSupport.h>
22 
23 #include <variant>
24 
25 class DeathNotifier :
26         public IBinder::DeathRecipient,
27         public ::android::hardware::hidl_death_recipient {
28 public:
29     using Service = std::variant<
30             sp<IBinder> const&,
31             sp<android::hidl::base::V1_0::IBase> const&>;
32 
33     DeathNotifier(std::variant<sp<IBinder> const&,
34             const sp<IBinder>& service,
35             const sp<MediaPlayerBase>& listener,
36             int which,
37             const std::string& name);
38     DeathNotifier(
39             const sp<android::hidl::base::V1_0::IBase>& hService,
40             const sp<MediaPlayerBase>& listener,
41             int which,
42             const std::string& name);
43     virtual ~DeathNotifier() = default;
44     virtual void binderDied(const wp<IBinder>& who);
45     virtual void serviceDied(
46             uint64_t cookie,
47             const wp<::android::hidl::base::V1_0::IBase>& who);
48     void unlinkToDeath();
49 
50 private:
51     sp<IBinder> mService;
52     sp<android::hidl::base::V1_0::IBase> mHService; // HIDL service
53     wp<MediaPlayerBase> mListener;
54     int mWhich;
55     std::string mName;
56 };
57 
58 #endif // ANDROID_MEDIASERVICE_DEATHRECIPIENT_H
59 
60