1 /*
2  * Copyright (c) 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 FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_EXPIRED_CALLBACK_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_EXPIRED_CALLBACK_H
18 
19 #include <iremote_broker.h>
20 
21 #include "expired_callback_stub.h"
22 #include "ibackground_task_mgr.h"
23 
24 namespace OHOS {
25 namespace BackgroundTaskMgr {
26 class ExpiredCallback : public std::enable_shared_from_this<ExpiredCallback> {
27 public:
28     /**
29      * @brief Default constructor used to create a instance.
30      */
31     ExpiredCallback();
32 
33     /**
34      * @brief Init something necessary.
35      */
36     void Init();
37 
38     /**
39      * @brief Default destructor.
40      */
41     virtual ~ExpiredCallback();
42 
43     /**
44      * @brief Callback when the transient task will be overtime.
45      */
46     virtual void OnExpired() = 0;
47 
48 private:
49     class ExpiredCallbackImpl final : public ExpiredCallbackStub {
50     public:
51         explicit ExpiredCallbackImpl(const std::shared_ptr<ExpiredCallback> &callback);
~ExpiredCallbackImpl()52         ~ExpiredCallbackImpl() {}
53 
54         /**
55          * @brief Notify the delayed transition to the suspended state times out.
56          */
57         void OnExpired() override;
58 
59     public:
60         std::weak_ptr<ExpiredCallback> callback_;
61     };
62 
63 private:
64     const sptr<ExpiredCallbackImpl> GetImpl() const;
65 
66 private:
67     sptr<ExpiredCallbackImpl> impl_ = nullptr;
68 
69     friend class BackgroundTaskManager;
70 };
71 }  // namespace BackgroundTaskMgr
72 }  // namespace OHOS
73 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_EXPIRED_CALLBACK_H