1794c9f46Sopenharmony_ci/* 2794c9f46Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3794c9f46Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4794c9f46Sopenharmony_ci * you may not use this file except in compliance with the License. 5794c9f46Sopenharmony_ci * You may obtain a copy of the License at 6794c9f46Sopenharmony_ci * 7794c9f46Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8794c9f46Sopenharmony_ci * 9794c9f46Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10794c9f46Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11794c9f46Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12794c9f46Sopenharmony_ci * See the License for the specific language governing permissions and 13794c9f46Sopenharmony_ci * limitations under the License. 14794c9f46Sopenharmony_ci */ 15794c9f46Sopenharmony_ci 16794c9f46Sopenharmony_ci#ifndef OHOS_DISTRIBUTED_HARDWARE_TASK_H 17794c9f46Sopenharmony_ci#define OHOS_DISTRIBUTED_HARDWARE_TASK_H 18794c9f46Sopenharmony_ci 19794c9f46Sopenharmony_ci#include <memory> 20794c9f46Sopenharmony_ci#include <mutex> 21794c9f46Sopenharmony_ci#include <set> 22794c9f46Sopenharmony_ci#include <string> 23794c9f46Sopenharmony_ci#include <vector> 24794c9f46Sopenharmony_ci 25794c9f46Sopenharmony_ci#include "impl_utils.h" 26794c9f46Sopenharmony_ci 27794c9f46Sopenharmony_cinamespace OHOS { 28794c9f46Sopenharmony_cinamespace DistributedHardware { 29794c9f46Sopenharmony_ciclass Task : public std::enable_shared_from_this<Task> { 30794c9f46Sopenharmony_cipublic: 31794c9f46Sopenharmony_ci Task() = delete; 32794c9f46Sopenharmony_ci Task(const std::string &networkId, const std::string &uuid, const std::string &udid, const std::string &dhId, 33794c9f46Sopenharmony_ci const DHType dhType); 34794c9f46Sopenharmony_ci virtual ~Task(); 35794c9f46Sopenharmony_ci virtual void DoTask() = 0; 36794c9f46Sopenharmony_ci 37794c9f46Sopenharmony_ci std::string GetId(); 38794c9f46Sopenharmony_ci std::string GetNetworkId(); 39794c9f46Sopenharmony_ci std::string GetUUID(); 40794c9f46Sopenharmony_ci std::string GetUDID(); 41794c9f46Sopenharmony_ci std::string GetDhId(); 42794c9f46Sopenharmony_ci DHType GetDhType(); 43794c9f46Sopenharmony_ci TaskType GetTaskType(); 44794c9f46Sopenharmony_ci void SetTaskType(TaskType taskType); 45794c9f46Sopenharmony_ci void SetTaskSteps(std::vector<TaskStep> taskSteps); 46794c9f46Sopenharmony_ci const std::vector<TaskStep> GetTaskSteps(); 47794c9f46Sopenharmony_ci 48794c9f46Sopenharmony_ci TaskState GetTaskState(); 49794c9f46Sopenharmony_ci void SetTaskState(TaskState taskState); 50794c9f46Sopenharmony_ci 51794c9f46Sopenharmony_ci virtual void AddChildrenTask(std::shared_ptr<Task> childrenTask); 52794c9f46Sopenharmony_ci const std::vector<std::shared_ptr<Task>> GetChildrenTasks(); 53794c9f46Sopenharmony_ci 54794c9f46Sopenharmony_ci const std::weak_ptr<Task> GetFatherTask(); 55794c9f46Sopenharmony_ci void SetFatherTask(std::shared_ptr<Task> fatherTask); 56794c9f46Sopenharmony_ci 57794c9f46Sopenharmony_ciprivate: 58794c9f46Sopenharmony_ci std::string id_; 59794c9f46Sopenharmony_ci // the remote device networkid 60794c9f46Sopenharmony_ci std::string networkId_; 61794c9f46Sopenharmony_ci // the remote device uuid 62794c9f46Sopenharmony_ci std::string uuid_; 63794c9f46Sopenharmony_ci // the remote device udid 64794c9f46Sopenharmony_ci std::string udid_; 65794c9f46Sopenharmony_ci // the remote device dhid 66794c9f46Sopenharmony_ci std::string dhId_; 67794c9f46Sopenharmony_ci // the remote device dh type 68794c9f46Sopenharmony_ci DHType dhType_; 69794c9f46Sopenharmony_ci TaskType taskType_ { TaskType::UNKNOWN }; 70794c9f46Sopenharmony_ci std::vector<TaskStep> taskSteps_; 71794c9f46Sopenharmony_ci std::weak_ptr<Task> fatherTask_; 72794c9f46Sopenharmony_ci 73794c9f46Sopenharmony_ci std::mutex taskMtx_; 74794c9f46Sopenharmony_ci std::vector<std::shared_ptr<Task>> childrenTasks_; 75794c9f46Sopenharmony_ci 76794c9f46Sopenharmony_ci TaskState taskState_ { TaskState::INIT }; 77794c9f46Sopenharmony_ci}; 78794c9f46Sopenharmony_ci} // namespace DistributedHardware 79794c9f46Sopenharmony_ci} // namespace OHOS 80794c9f46Sopenharmony_ci#endif 81