• 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 "task_factory.h"
17 
18 #include "anonymous_string.h"
19 #include "disable_task.h"
20 #include "distributed_hardware_log.h"
21 #include "enable_task.h"
22 #include "offline_task.h"
23 #include "online_task.h"
24 #include "task_board.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 #undef DH_LOG_TAG
29 #define DH_LOG_TAG "TaskFactory"
30 
31 IMPLEMENT_SINGLE_INSTANCE(TaskFactory);
CreateTask(TaskType taskType,const std::string & networkId,const std::string & uuid,const std::string & dhId,std::shared_ptr<Task> fatherTask)32 std::shared_ptr<Task> TaskFactory::CreateTask(TaskType taskType, const std::string &networkId, const std::string &uuid,
33     const std::string &dhId, std::shared_ptr<Task> fatherTask)
34 {
35     DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s", static_cast<int32_t>(taskType),
36         GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), dhId.c_str());
37     std::shared_ptr<Task> task = nullptr;
38     switch (taskType) {
39         case TaskType::ENABLE: {
40             task = std::make_shared<EnableTask>(networkId, uuid, dhId);
41             break;
42         }
43         case TaskType::DISABLE: {
44             task = std::make_shared<DisableTask>(networkId, uuid, dhId);
45             break;
46         }
47         case TaskType::ON_LINE: {
48             task = std::make_shared<OnLineTask>(networkId, uuid, dhId);
49             break;
50         }
51         case TaskType::OFF_LINE: {
52             task = std::make_shared<OffLineTask>(networkId, uuid, dhId);
53             break;
54         }
55         default: {
56             DHLOGE("CreateTask type invalid, type: %d", taskType);
57             return nullptr;
58         }
59     }
60 
61     if (fatherTask != nullptr) {
62         task->SetFatherTask(fatherTask);
63         fatherTask->AddChildrenTask(task);
64     }
65     TaskBoard::GetInstance().AddTask(task);
66 
67     return task;
68 }
69 }
70 }