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