1 /*
2 * Copyright (c) 2021-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 #define HST_LOG_TAG "Task"
16 #include "osal/task/task.h"
17 #include "osal/task/taskInner.h"
18
19 namespace OHOS {
20 namespace Media {
21
SleepInTask(unsigned ms)22 void Task::SleepInTask(unsigned ms)
23 {
24 TaskInner::SleepInTask(ms);
25 }
26
SetEnableStateChangeLog(bool enable)27 void Task::SetEnableStateChangeLog(bool enable)
28 {
29 if (taskInner_ != nullptr) {
30 taskInner_->SetEnableStateChangeLog(enable);
31 }
32 }
33
Task(const std::string & name,const std::string & groupId,TaskType type,TaskPriority priority,bool singleLoop)34 Task::Task(const std::string& name, const std::string& groupId, TaskType type, TaskPriority priority, bool singleLoop)
35 : taskInner_(std::make_shared<TaskInner>(name, groupId, type, priority, singleLoop))
36 {
37 taskInner_->Init();
38 }
39
~Task()40 Task::~Task()
41 {
42 taskInner_->DeInit();
43 }
44
Start()45 void Task::Start()
46 {
47 taskInner_->Start();
48 }
49
Stop()50 void Task::Stop()
51 {
52 taskInner_->Stop();
53 }
54
StopAsync()55 void Task::StopAsync()
56 {
57 taskInner_->StopAsync();
58 }
59
Pause()60 void Task::Pause()
61 {
62 taskInner_->Pause();
63 }
64
PauseAsync()65 void Task::PauseAsync()
66 {
67 taskInner_->PauseAsync();
68 }
69
RegisterJob(const std::function<int64_t ()> & job)70 void Task::RegisterJob(const std::function<int64_t()>& job)
71 {
72 taskInner_->RegisterJob(job);
73 }
74
SubmitJobOnce(const std::function<void ()> & job,int64_t delayUs,bool wait)75 void Task::SubmitJobOnce(const std::function<void()>& job, int64_t delayUs, bool wait)
76 {
77 taskInner_->SubmitJobOnce(job, delayUs, wait);
78 }
79
SubmitJob(const std::function<void ()> & job,int64_t delayUs,bool wait)80 void Task::SubmitJob(const std::function<void()>& job, int64_t delayUs, bool wait)
81 {
82 taskInner_->SubmitJob(job, delayUs, wait);
83 }
84
IsTaskRunning()85 bool Task::IsTaskRunning()
86 {
87 return taskInner_->IsTaskRunning();
88 }
89
UpdateDelayTime(int64_t delayUs)90 void Task::UpdateDelayTime(int64_t delayUs)
91 {
92 taskInner_->UpdateDelayTime(delayUs);
93 }
94 } // namespace Media
95 } // namespace OHOS