1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef IAM_CONTEXT_DEAD_RECIPIENT_H
17 #define IAM_CONTEXT_DEAD_RECIPIENT_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "context_callback.h"
23 #include "nocopyable.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 class ContextDeathRecipientManager {
29     public:
30         ContextDeathRecipientManager() = default;
31         ~ContextDeathRecipientManager() = default;
32         void AddDeathRecipient(std::shared_ptr<ContextCallback> &callback, uint64_t contextId);
33         void RemoveDeathRecipient(std::shared_ptr<ContextCallback> &callback);
34     protected:
35         sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
36 };
37 
38 class ContextDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable {
39     public:
40         ContextDeathRecipient(uint64_t contextId);
41         ~ContextDeathRecipient() override = default;
42         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
43     protected:
44         uint64_t contextId_ = INVALID_CONTEXT_ID;
45 };
46 } // namespace UserAuth
47 } // namespace UserIam
48 } // namespace OHOS
49 #endif // IAM_CONTEXT_DEAD_RECIPIENT_H