1 /*
2 * Copyright (c) 2021 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 "mock_task_factory.h"
17
18 #include "distributed_hardware_log.h"
19 #include "mock_disable_task.h"
20 #include "mock_enable_task.h"
21 #include "mock_offline_task.h"
22 #include "mock_online_task.h"
23 #include "task_board.h"
24
25 namespace OHOS {
26 namespace DistributedHardware {
27 IMPLEMENT_SINGLE_INSTANCE(MockTaskFactory);
CreateTask(TaskType taskType,TaskParam taskParam,std::shared_ptr<Task> fatherTask)28 std::shared_ptr<Task> MockTaskFactory::CreateTask(TaskType taskType, TaskParam taskParam,
29 std::shared_ptr<Task> fatherTask)
30 {
31 std::shared_ptr<Task> task = nullptr;
32 switch (taskType) {
33 case TaskType::ENABLE: {
34 task = std::make_shared<MockEnableTask>(taskParam.networkId, taskParam.uuid, taskParam.dhId,
35 taskParam.dhType);
36 break;
37 }
38 case TaskType::DISABLE: {
39 task = std::make_shared<MockDisableTask>(taskParam.networkId, taskParam.uuid, taskParam.dhId,
40 taskParam.dhType);
41 break;
42 }
43 case TaskType::ON_LINE: {
44 task = std::make_shared<MockOnLineTask>(taskParam.networkId, taskParam.uuid, taskParam.dhId,
45 taskParam.dhType);
46 break;
47 }
48 case TaskType::OFF_LINE: {
49 task = std::make_shared<MockOffLineTask>(taskParam.networkId, taskParam.uuid, taskParam.dhId,
50 taskParam.dhType);
51 break;
52 }
53 default: {
54 DHLOGE("CreateTask type invalid, type: %d", taskType);
55 return nullptr;
56 }
57 }
58
59 if (fatherTask != nullptr) {
60 task->SetFatherTask(fatherTask);
61 fatherTask->AddChildrenTask(task);
62 }
63 TaskBoard::GetInstance().AddTask(task);
64
65 return task;
66 }
67 } // namespace DistributedHardware
68 } // namespace OHOS
69