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 "task_manager_test.h"
17
18 #include "intell_voice_log.h"
19
20 #define LOG_TAG "TaskManagerTest"
21
22 using namespace std;
23 using namespace OHOS::IntellVoiceUtils;
24
25 namespace OHOS {
26 namespace IntellVoiceEngine {
27 static constexpr uint32_t MAX_TASK_NUM = 5;
28 static const std::string TASK_THREAD_NAME = "TaskThreadTest";
29
TaskManagerTest()30 TaskManagerTest::TaskManagerTest() : TaskExecutor(TASK_THREAD_NAME, MAX_TASK_NUM)
31 {
32 TaskExecutor::StartThread();
33 }
34
~TaskManagerTest()35 TaskManagerTest::~TaskManagerTest()
36 {
37 TaskExecutor::StopThread();
38 }
39
AddAsyncTask(int32_t value)40 void TaskManagerTest::AddAsyncTask(int32_t value)
41 {
42 TaskExecutor::AddAsyncTask(
43 [this, value]() {
44 sleep(1);
45 threadId_ = value;
46 INTELL_VOICE_LOG_INFO("AddAsyncTask threadId_: %{public}d", threadId_);
47 },
48 std::to_string(value), false);
49 }
50
AddSyncTask(int32_t value)51 void TaskManagerTest::AddSyncTask(int32_t value)
52 {
53 TaskExecutor::AddSyncTask([this, value]() {
54 sleep(1);
55 threadId_ = value;
56 INTELL_VOICE_LOG_INFO("AddSyncTask threadId_: %{public}d", threadId_);
57 });
58 }
59 } // namespace IntellVoiceEngine
60 } // namespace OHOS
61