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