1 /*
2 * Copyright (c) 2024 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 "common/rs_xcollie.h"
17 #include "platform/common/rs_log.h"
18 #ifdef ROSEN_OHOS
19 #include "xcollie/xcollie.h"
20 #endif
21 namespace OHOS {
22 namespace Rosen {
RSXCollie(const std::string & tag,uint32_t timeoutSeconds,std::function<void (void *)> func,void * arg,uint32_t flag)23 RSXCollie::RSXCollie(const std::string& tag, uint32_t timeoutSeconds,
24 std::function<void(void*)> func, void* arg, uint32_t flag)
25 {
26 tag_ = "render_service:" + tag;
27 #ifdef ROSEN_OHOS
28 id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag_, timeoutSeconds, func, arg, flag);
29 #else
30 id_ = -1;
31 #endif
32 RS_LOGD("start RSXCollie, tag: %{public}s, timeout: %{public}u, flag: %{public}u, id: %{public}d",
33 tag.c_str(), timeoutSeconds, flag, id_);
34 }
35
CancelRSXCollie()36 void RSXCollie::CancelRSXCollie()
37 {
38 if (!isCanceled_) {
39 isCanceled_ = true;
40 #ifdef ROSEN_OHOS
41 HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
42 #endif
43 RS_LOGD("cancel RSXCollie, tag: %{public}s, id: %{public}d", tag_.c_str(), id_);
44 }
45 }
46
~RSXCollie()47 RSXCollie::~RSXCollie()
48 {
49 CancelRSXCollie();
50 }
51 } // namespace Rosen
52 } // namespace OHOS