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 #include "expired_callback.h" 17 #include "bgtaskmgr_inner_errors.h" 18 19 namespace OHOS { 20 namespace BackgroundTaskMgr { ExpiredCallback()21ExpiredCallback::ExpiredCallback() {} 22 ~ExpiredCallback()23ExpiredCallback::~ExpiredCallback() {} 24 Init()25__attribute__((no_sanitize("cfi"))) void ExpiredCallback::Init() 26 { 27 impl_ = new (std::nothrow) ExpiredCallbackImpl(shared_from_this()); 28 } 29 GetImpl() const30const sptr<ExpiredCallback::ExpiredCallbackImpl> ExpiredCallback::GetImpl() const 31 { 32 return impl_; 33 } 34 ExpiredCallbackImpl(const std::shared_ptr<ExpiredCallback> & callback)35ExpiredCallback::ExpiredCallbackImpl::ExpiredCallbackImpl(const std::shared_ptr<ExpiredCallback> &callback) 36 : callback_(callback) {} 37 OnExpired()38ErrCode ExpiredCallback::ExpiredCallbackImpl::OnExpired() 39 { 40 auto callback = callback_.lock(); 41 if (callback != nullptr) { 42 callback->OnExpired(); 43 return ERR_OK; 44 } 45 return ERR_BGTASK_CALLBACK_NOT_EXIST; 46 } 47 } // namespace BackgroundTaskMgr 48 } // namespace OHOS