blob: 24e45a36b9cfef56de4eee7a6773450e70b9d98c [file] [log] [blame]
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -07001/*
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
Wonsik Kime8e98152022-12-16 16:04:17 -080020#include <android/binder_auto_utils.h>
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070021#include <android/hidl/base/1.0/IBase.h>
22#include <binder/Binder.h>
23#include <hidl/HidlSupport.h>
24
25#include <variant>
26
27namespace android {
28
29class DeathNotifier {
30public:
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);
Wonsik Kime8e98152022-12-16 16:04:17 -080036 DeathNotifier(::ndk::SpAIBinder const& service, Notify const& notify);
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070037 DeathNotifier(DeathNotifier&& other);
38 ~DeathNotifier();
39
40private:
Wonsik Kime8e98152022-12-16 16:04:17 -080041 std::variant<std::monostate, sp<IBinder>, sp<HBase>, ::ndk::SpAIBinder> mService;
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070042
43 class DeathRecipient;
44 sp<DeathRecipient> mDeathRecipient;
45};
46
47} // namespace android
48
49#endif // ANDROID_MEDIASERVICE_DEATHNOTIFIER_H
50