1 /*
2 * Copyright (c) 2023 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 "adapter/preview/osal/task/task_runner_adapter_impl.h"
17
18 #include "adapter/preview/entrance/ace_preview_helper.h"
19
20 namespace OHOS::Ace {
PostTask(std::function<void ()> task,const std::string & caller,PriorityType priorityType)21 void TaskRunnerAdapterImpl::PostTask(std::function<void()> task, const std::string& caller, PriorityType priorityType)
22 {
23 auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
24 if (postTask) {
25 postTask(std::move(task), 0);
26 }
27 }
28
PostTaskForTime(std::function<void ()> task,uint32_t targetTime,const std::string & caller)29 void TaskRunnerAdapterImpl::PostTaskForTime(std::function<void()> task, uint32_t targetTime, const std::string& caller)
30 {
31 auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
32 if (postTask) {
33 postTask(std::move(task), targetTime);
34 }
35 }
36
PostDelayedTask(std::function<void ()> task,uint32_t delay,const std::string & caller,PriorityType priorityType)37 void TaskRunnerAdapterImpl::PostDelayedTask(
38 std::function<void()> task, uint32_t delay, const std::string& caller, PriorityType priorityType)
39 {
40 auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
41 if (postTask) {
42 postTask(std::move(task), delay);
43 }
44 }
45
RunsTasksOnCurrentThread()46 bool TaskRunnerAdapterImpl::RunsTasksOnCurrentThread()
47 {
48 auto isCurrentRunnerThread =
49 OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfIsCurrentRunnerThread();
50 return isCurrentRunnerThread && isCurrentRunnerThread();
51 }
52
Initialize(bool useCurrentEventRunner,const std::string & name)53 void TaskRunnerAdapterImpl::Initialize(bool useCurrentEventRunner, const std::string& name) {}
54 } // namespace OHOS::Ace
55