1 /*
2  * Copyright (c) 2021-2022 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 BND_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_KVSTORE_DEATH_RECIPIENT_H
17 #define BND_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_KVSTORE_DEATH_RECIPIENT_H
18 
19 #include <functional>
20 
21 #include "kvstore_death_recipient.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 class DistributedKvStoreDeathRecipient : public DistributedKv::KvStoreDeathRecipient {
26 public:
27     /**
28      * @brief The constructor.
29      *
30      * @param callback Indicates the callback.
31      */
DistributedKvStoreDeathRecipient(const std::function<void ()> & callback)32     explicit DistributedKvStoreDeathRecipient(const std::function<void()> &callback)
33     {
34         callback_ = callback;
35     }
36 
37     /**
38      * @brief The deconstructor.
39      */
~DistributedKvStoreDeathRecipient()40     virtual ~DistributedKvStoreDeathRecipient()
41     {}
42 
43     /**
44      * @brief Obtains the death event. Inherited from DistributedKv::KvStoreDeathRecipient.
45      */
OnRemoteDied()46     void OnRemoteDied() override
47     {
48         if (callback_ != nullptr) {
49             callback_();
50         }
51     }
52 
53 private:
54     std::function<void()> callback_;
55 };
56 }  // namespace Notification
57 }  // namespace OHOS
58 #endif // BND_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_KVSTORE_DEATH_RECIPIENT_H