180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#include "session_xcollie.h" 1780922886Sopenharmony_ci 1880922886Sopenharmony_ci#include "avsession_log.h" 1980922886Sopenharmony_ci 2080922886Sopenharmony_ci#ifdef HICOLLIE_ENABLE 2180922886Sopenharmony_ci#include "xcollie/xcollie.h" 2280922886Sopenharmony_ci#endif 2380922886Sopenharmony_ci 2480922886Sopenharmony_cinamespace OHOS::AVSession { 2580922886Sopenharmony_ciSessionXCollie::SessionXCollie(const std::string& tag, uint32_t timeoutSeconds, 2680922886Sopenharmony_ci std::function<void(void *)> func, void *arg, uint32_t flag) 2780922886Sopenharmony_ci{ 2880922886Sopenharmony_ci tag_ = tag; 2980922886Sopenharmony_ci#ifdef HICOLLIE_ENABLE 3080922886Sopenharmony_ci id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag_, timeoutSeconds, func, arg, flag); 3180922886Sopenharmony_ci#else 3280922886Sopenharmony_ci id_ = -1; 3380922886Sopenharmony_ci#endif 3480922886Sopenharmony_ci isCanceled_ = false; 3580922886Sopenharmony_ci SLOGD("start SessionXCollie, tag:%{public}s, timeout:%{public}u, flag:%{public}u, id:%{public}d", 3680922886Sopenharmony_ci tag_.c_str(), timeoutSeconds, flag, id_); 3780922886Sopenharmony_ci} 3880922886Sopenharmony_ci 3980922886Sopenharmony_ciSessionXCollie::~SessionXCollie() 4080922886Sopenharmony_ci{ 4180922886Sopenharmony_ci CancelSessionXCollie(); 4280922886Sopenharmony_ci} 4380922886Sopenharmony_ci 4480922886Sopenharmony_civoid SessionXCollie::CancelSessionXCollie() 4580922886Sopenharmony_ci{ 4680922886Sopenharmony_ci if (!isCanceled_) { 4780922886Sopenharmony_ci #ifdef HICOLLIE_ENABLE 4880922886Sopenharmony_ci HiviewDFX::XCollie::GetInstance().CancelTimer(id_); 4980922886Sopenharmony_ci #endif 5080922886Sopenharmony_ci isCanceled_ = true; 5180922886Sopenharmony_ci SLOGD("cancel SessionXCollie, tag:%{public}s,id:%{public}d", tag_.c_str(), id_); 5280922886Sopenharmony_ci } 5380922886Sopenharmony_ci} 5480922886Sopenharmony_ci} // namespace OHOS::AVSession