1 /*
2  * Copyright (c) 2022, 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 #pragma once
18 
19 #include <android/binder_auto_utils.h>
20 #include <utils/RefBase.h>
21 
22 namespace android {
23 namespace automotive {
24 namespace watchdog {
25 
26 class AIBinderDeathRegistrationWrapperInterface : public virtual android::RefBase {
27 public:
28     /**
29      * Links the recipient to the binder's death. The cookie is passed to the recipient in case
30      * the binder dies.
31      */
32     virtual ndk::ScopedAStatus linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
33                                            void* cookie) const = 0;
34     /**
35      * Unlinks the recipient from the binder's death. Pass the same cookie that was used to link to
36      * the binder's death.
37      */
38     virtual ndk::ScopedAStatus unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
39                                              void* cookie) const = 0;
40 };
41 
42 class AIBinderDeathRegistrationWrapper final : public AIBinderDeathRegistrationWrapperInterface {
43 public:
44     ndk::ScopedAStatus linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
45                                    void* cookie) const override;
46     ndk::ScopedAStatus unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
47                                      void* cookie) const override;
48 };
49 
50 }  // namespace watchdog
51 }  // namespace automotive
52 }  // namespace android
53