• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,const std::string & networkId,const std::string & uuid,const std::string & dhId,std::shared_ptr<Task> fatherTask)28 std::shared_ptr<Task> MockTaskFactory::CreateTask(TaskType taskType, const std::string &networkId,
29     const std::string &uuid, const std::string &dhId, 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>(networkId, uuid, dhId);
35             break;
36         }
37         case TaskType::DISABLE: {
38             task = std::make_shared<MockDisableTask>(networkId, uuid, dhId);
39             break;
40         }
41         case TaskType::ON_LINE: {
42             task = std::make_shared<MockOnLineTask>(networkId, uuid, dhId);
43             break;
44         }
45         case TaskType::OFF_LINE: {
46             task = std::make_shared<MockOffLineTask>(networkId, uuid, dhId);
47             break;
48         }
49         default: {
50             DHLOGE("CreateTask type invalid, type: %d", taskType);
51             return nullptr;
52         }
53     }
54 
55     if (fatherTask != nullptr) {
56         task->SetFatherTask(fatherTask);
57         fatherTask->AddChildrenTask(task);
58     }
59     TaskBoard::GetInstance().AddTask(task);
60 
61     return task;
62 }
63 }
64 }