blob: 0fd7c6522f93c5e04c5224a4a85e861a81bc6f0e [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
Devin Moore55128e72024-03-18 22:37:53 +000040 class DeathRecipient;
41
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070042private:
Wonsik Kime8e98152022-12-16 16:04:17 -080043 std::variant<std::monostate, sp<IBinder>, sp<HBase>, ::ndk::SpAIBinder> mService;
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070044
Pawin Vongmasa270dd6a2019-04-06 04:41:15 -070045 sp<DeathRecipient> mDeathRecipient;
46};
47
48} // namespace android
49
50#endif // ANDROID_MEDIASERVICE_DEATHNOTIFIER_H
51