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
27namespace OHOS {
28namespace DistributedHardware {
29class Task : public std::enable_shared_from_this<Task> {
30public:
31    Task() = delete;
32    Task(const std::string &networkId, const std::string &uuid, const std::string &udid, const std::string &dhId,
33        const DHType dhType);
34    virtual ~Task();
35    virtual void DoTask() = 0;
36
37    std::string GetId();
38    std::string GetNetworkId();
39    std::string GetUUID();
40    std::string GetUDID();
41    std::string GetDhId();
42    DHType GetDhType();
43    TaskType GetTaskType();
44    void SetTaskType(TaskType taskType);
45    void SetTaskSteps(std::vector<TaskStep> taskSteps);
46    const std::vector<TaskStep> GetTaskSteps();
47
48    TaskState GetTaskState();
49    void SetTaskState(TaskState taskState);
50
51    virtual void AddChildrenTask(std::shared_ptr<Task> childrenTask);
52    const std::vector<std::shared_ptr<Task>> GetChildrenTasks();
53
54    const std::weak_ptr<Task> GetFatherTask();
55    void SetFatherTask(std::shared_ptr<Task> fatherTask);
56
57private:
58    std::string id_;
59    // the remote device networkid
60    std::string networkId_;
61    // the remote device uuid
62    std::string uuid_;
63    // the remote device udid
64    std::string udid_;
65    // the remote device dhid
66    std::string dhId_;
67    // the remote device dh type
68    DHType dhType_;
69    TaskType taskType_ { TaskType::UNKNOWN };
70    std::vector<TaskStep> taskSteps_;
71    std::weak_ptr<Task> fatherTask_;
72
73    std::mutex taskMtx_;
74    std::vector<std::shared_ptr<Task>> childrenTasks_;
75
76    TaskState taskState_ { TaskState::INIT };
77};
78} // namespace DistributedHardware
79} // namespace OHOS
80#endif
81