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