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_DEATHNOTIFIER_H
18 #define ANDROID_MEDIASERVICE_DEATHNOTIFIER_H
19 
20 #include <android/binder_auto_utils.h>
21 #include <android/hidl/base/1.0/IBase.h>
22 #include <binder/Binder.h>
23 #include <hidl/HidlSupport.h>
24 
25 #include <variant>
26 
27 namespace android {
28 
29 class DeathNotifier {
30 public:
31     using HBase = hidl::base::V1_0::IBase;
32     using Notify = std::function<void()>;
33 
34     DeathNotifier(sp<IBinder> const& service, Notify const& notify);
35     DeathNotifier(sp<HBase> const& service, Notify const& notify);
36     DeathNotifier(::ndk::SpAIBinder const& service, Notify const& notify);
37     DeathNotifier(DeathNotifier&& other);
38     ~DeathNotifier();
39 
40     class DeathRecipient;
41 
42 private:
43     std::variant<std::monostate, sp<IBinder>, sp<HBase>, ::ndk::SpAIBinder> mService;
44 
45     sp<DeathRecipient> mDeathRecipient;
46 };
47 
48 } // namespace android
49 
50 #endif // ANDROID_MEDIASERVICE_DEATHNOTIFIER_H
51 
52