• 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 #ifndef OHOS_DISTRIBUTED_HARDWARE_TASK_H
17 #define OHOS_DISTRIBUTED_HARDWARE_TASK_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
25 #include "impl_utils.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 class Task : public std::enable_shared_from_this<Task> {
30 public:
31     Task() = delete;
32     Task(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType);
33     virtual ~Task();
34     virtual void DoTask() = 0;
35 
36     std::string GetId();
37     std::string GetNetworkId();
38     std::string GetUUID();
39     std::string GetDhId();
40     DHType GetDhType();
41     TaskType GetTaskType();
42     void SetTaskType(TaskType taskType);
43     void SetTaskSteps(std::vector<TaskStep> taskSteps);
44     const std::vector<TaskStep> GetTaskSteps();
45 
46     TaskState GetTaskState();
47     void SetTaskState(TaskState taskState);
48 
49     virtual void AddChildrenTask(std::shared_ptr<Task> childrenTask);
50     const std::vector<std::shared_ptr<Task>> GetChildrenTasks();
51 
52     const std::weak_ptr<Task> GetFatherTask();
53     void SetFatherTask(std::shared_ptr<Task> fatherTask);
54 
55 private:
56     std::string id_;
57     std::string networkId_;
58     std::string uuid_;
59     std::string dhId_;
60     DHType dhType_;
61     TaskType taskType_ { TaskType::UNKNOWN };
62     std::vector<TaskStep> taskSteps_;
63     std::weak_ptr<Task> fatherTask_;
64 
65     std::mutex taskMtx_;
66     std::vector<std::shared_ptr<Task>> childrenTasks_;
67 
68     TaskState taskState_ { TaskState::INIT };
69 };
70 } // namespace DistributedHardware
71 } // namespace OHOS
72 #endif
73