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