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.h"
17
18 #include "constants.h"
19 #include "dh_utils_tool.h"
20
21 namespace OHOS {
22 namespace DistributedHardware {
Task(const std::string & networkId,const std::string & uuid,const std::string & udid,const std::string & dhId,const DHType dhType)23 Task::Task(const std::string &networkId, const std::string &uuid, const std::string &udid, const std::string &dhId,
24 const DHType dhType) : id_(DH_TASK_NAME_PREFIX + GetRandomID()), networkId_(networkId), uuid_(uuid), udid_(udid),
25 dhId_(dhId), dhType_(dhType)
26 {}
27
~Task()28 Task::~Task()
29 {
30 this->childrenTasks_.clear();
31 }
32
GetId()33 std::string Task::GetId()
34 {
35 return this->id_;
36 }
37
GetNetworkId()38 std::string Task::GetNetworkId()
39 {
40 return this->networkId_;
41 }
42
GetUUID()43 std::string Task::GetUUID()
44 {
45 return this->uuid_;
46 }
47
GetUDID()48 std::string Task::GetUDID()
49 {
50 return this->udid_;
51 }
52
GetDhId()53 std::string Task::GetDhId()
54 {
55 return this->dhId_;
56 }
57
GetDhType()58 DHType Task::GetDhType()
59 {
60 return this->dhType_;
61 }
62
GetTaskType()63 TaskType Task::GetTaskType()
64 {
65 return this->taskType_;
66 }
67
SetTaskType(TaskType taskType)68 void Task::SetTaskType(TaskType taskType)
69 {
70 this->taskType_ = taskType;
71 }
72
SetTaskSteps(std::vector<TaskStep> taskSteps)73 void Task::SetTaskSteps(std::vector<TaskStep> taskSteps)
74 {
75 this->taskSteps_.swap(taskSteps);
76 }
77
GetTaskSteps()78 const std::vector<TaskStep> Task::GetTaskSteps()
79 {
80 return this->taskSteps_;
81 }
82
GetTaskState()83 TaskState Task::GetTaskState()
84 {
85 return this->taskState_;
86 }
87
SetTaskState(TaskState taskState)88 void Task::SetTaskState(TaskState taskState)
89 {
90 this->taskState_ = taskState;
91 }
92
AddChildrenTask(std::shared_ptr<Task> childrenTask)93 void Task::AddChildrenTask(std::shared_ptr<Task> childrenTask)
94 {
95 std::lock_guard<std::mutex> lock(taskMtx_);
96 this->childrenTasks_.push_back(childrenTask);
97 }
98
GetChildrenTasks()99 const std::vector<std::shared_ptr<Task>> Task::GetChildrenTasks()
100 {
101 std::lock_guard<std::mutex> lock(taskMtx_);
102 return this->childrenTasks_;
103 }
104
GetFatherTask()105 const std::weak_ptr<Task> Task::GetFatherTask()
106 {
107 return this->fatherTask_;
108 }
109
SetFatherTask(std::shared_ptr<Task> fatherTask)110 void Task::SetFatherTask(std::shared_ptr<Task> fatherTask)
111 {
112 this->fatherTask_ = fatherTask;
113 }
114 } // namespace DistributedHardware
115 } // namespace OHOS
116