11ebd3d54Sopenharmony_ci/* 21ebd3d54Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 31ebd3d54Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41ebd3d54Sopenharmony_ci * you may not use this file except in compliance with the License. 51ebd3d54Sopenharmony_ci * You may obtain a copy of the License at 61ebd3d54Sopenharmony_ci * 71ebd3d54Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81ebd3d54Sopenharmony_ci * 91ebd3d54Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101ebd3d54Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111ebd3d54Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121ebd3d54Sopenharmony_ci * See the License for the specific language governing permissions and 131ebd3d54Sopenharmony_ci * limitations under the License. 141ebd3d54Sopenharmony_ci */ 151ebd3d54Sopenharmony_ci 161ebd3d54Sopenharmony_ci#ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_EXPIRED_CALLBACK_H 171ebd3d54Sopenharmony_ci#define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_EXPIRED_CALLBACK_H 181ebd3d54Sopenharmony_ci 191ebd3d54Sopenharmony_ci#include <iremote_broker.h> 201ebd3d54Sopenharmony_ci 211ebd3d54Sopenharmony_ci#include "expired_callback_stub.h" 221ebd3d54Sopenharmony_ci#include "ibackground_task_mgr.h" 231ebd3d54Sopenharmony_ci 241ebd3d54Sopenharmony_cinamespace OHOS { 251ebd3d54Sopenharmony_cinamespace BackgroundTaskMgr { 261ebd3d54Sopenharmony_ciclass ExpiredCallback : public std::enable_shared_from_this<ExpiredCallback> { 271ebd3d54Sopenharmony_cipublic: 281ebd3d54Sopenharmony_ci /** 291ebd3d54Sopenharmony_ci * @brief Default constructor used to create a instance. 301ebd3d54Sopenharmony_ci */ 311ebd3d54Sopenharmony_ci ExpiredCallback(); 321ebd3d54Sopenharmony_ci 331ebd3d54Sopenharmony_ci /** 341ebd3d54Sopenharmony_ci * @brief Init something necessary. 351ebd3d54Sopenharmony_ci */ 361ebd3d54Sopenharmony_ci void Init(); 371ebd3d54Sopenharmony_ci 381ebd3d54Sopenharmony_ci /** 391ebd3d54Sopenharmony_ci * @brief Default destructor. 401ebd3d54Sopenharmony_ci */ 411ebd3d54Sopenharmony_ci virtual ~ExpiredCallback(); 421ebd3d54Sopenharmony_ci 431ebd3d54Sopenharmony_ci /** 441ebd3d54Sopenharmony_ci * @brief Callback when the transient task will be overtime. 451ebd3d54Sopenharmony_ci */ 461ebd3d54Sopenharmony_ci virtual void OnExpired() = 0; 471ebd3d54Sopenharmony_ci 481ebd3d54Sopenharmony_ciprivate: 491ebd3d54Sopenharmony_ci class ExpiredCallbackImpl final : public ExpiredCallbackStub { 501ebd3d54Sopenharmony_ci public: 511ebd3d54Sopenharmony_ci explicit ExpiredCallbackImpl(const std::shared_ptr<ExpiredCallback> &callback); 521ebd3d54Sopenharmony_ci ~ExpiredCallbackImpl() {} 531ebd3d54Sopenharmony_ci 541ebd3d54Sopenharmony_ci /** 551ebd3d54Sopenharmony_ci * @brief Notify the delayed transition to the suspended state times out. 561ebd3d54Sopenharmony_ci */ 571ebd3d54Sopenharmony_ci void OnExpired() override; 581ebd3d54Sopenharmony_ci 591ebd3d54Sopenharmony_ci public: 601ebd3d54Sopenharmony_ci std::weak_ptr<ExpiredCallback> callback_; 611ebd3d54Sopenharmony_ci }; 621ebd3d54Sopenharmony_ci 631ebd3d54Sopenharmony_ciprivate: 641ebd3d54Sopenharmony_ci const sptr<ExpiredCallbackImpl> GetImpl() const; 651ebd3d54Sopenharmony_ci 661ebd3d54Sopenharmony_ciprivate: 671ebd3d54Sopenharmony_ci sptr<ExpiredCallbackImpl> impl_ = nullptr; 681ebd3d54Sopenharmony_ci 691ebd3d54Sopenharmony_ci friend class BackgroundTaskManager; 701ebd3d54Sopenharmony_ci}; 711ebd3d54Sopenharmony_ci} // namespace BackgroundTaskMgr 721ebd3d54Sopenharmony_ci} // namespace OHOS 731ebd3d54Sopenharmony_ci#endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_EXPIRED_CALLBACK_H