• 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)23 Task::Task(const std::string &networkId, const std::string &uuid, const std::string &dhId)
24     : id_(DH_TASK_NAME_PREFIX + GetRandomID()), networkId_(networkId), uuid_(uuid), dhId_(dhId)
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 
GetTaskType()52 TaskType Task::GetTaskType()
53 {
54     return this->taskType_;
55 }
56 
SetTaskType(TaskType taskType)57 void Task::SetTaskType(TaskType taskType)
58 {
59     this->taskType_ = taskType;
60 }
61 
SetTaskSteps(std::vector<TaskStep> taskSteps)62 void Task::SetTaskSteps(std::vector<TaskStep> taskSteps)
63 {
64     this->taskSteps_.swap(taskSteps);
65 }
66 
GetTaskSteps()67 const std::vector<TaskStep> Task::GetTaskSteps()
68 {
69     return this->taskSteps_;
70 }
71 
GetTaskState()72 TaskState Task::GetTaskState()
73 {
74     return this->taskState_;
75 }
76 
SetTaskState(TaskState taskState)77 void Task::SetTaskState(TaskState taskState)
78 {
79     this->taskState_ = taskState;
80 }
81 
AddChildrenTask(std::shared_ptr<Task> childrenTask)82 void Task::AddChildrenTask(std::shared_ptr<Task> childrenTask)
83 {
84     std::lock_guard<std::mutex> lock(taskMtx_);
85     this->childrenTasks_.push_back(childrenTask);
86 }
87 
GetChildrenTasks()88 const std::vector<std::shared_ptr<Task>> Task::GetChildrenTasks()
89 {
90     std::lock_guard<std::mutex> lock(taskMtx_);
91     return this->childrenTasks_;
92 }
93 
GetFatherTask()94 const std::weak_ptr<Task> Task::GetFatherTask()
95 {
96     return this->fatherTask_;
97 }
98 
SetFatherTask(std::shared_ptr<Task> fatherTask)99 void Task::SetFatherTask(std::shared_ptr<Task> fatherTask)
100 {
101     this->fatherTask_ = fatherTask;
102 }
103 }
104 }