1 /*
2 * Copyright (c) 2022 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 #ifndef DISTRIBUTED_DATA_TASK_MANAGER_H
16 #define DISTRIBUTED_DATA_TASK_MANAGER_H
17 #include "ithread_pool.h"
18 #include "executor_pool.h"
19 #include "visibility.h"
20 namespace OHOS::DistributedData {
21 class TaskManager : public DistributedDB::IThreadPool {
22 public:
23     using TaskId = uint64_t;
24     using Task = std::function<void()>;
25     using Duration = std::chrono::steady_clock::duration;
26     TaskManager() = default;
27     explicit TaskManager(std::shared_ptr<ExecutorPool> executors);
28     ~TaskManager() override;
29     TaskId Execute(const Task &task) override;
30     TaskId Execute(const Task &task, Duration delay) override;
31     TaskId Schedule(const Task &task, Duration interval) override;
32     TaskId Schedule(const Task &task, Duration delay, Duration interval) override;
33     TaskId Schedule(const Task &task, Duration delay, Duration interval, uint64_t times) override;
34     bool Remove(const TaskId &taskId, bool wait) override;
35     TaskId Reset(const TaskId &taskId, Duration interval) override;
36 
37 private:
38     std::shared_ptr<ExecutorPool> executors_ = nullptr;
39 };
40 } // namespace OHOS::DistributedData
41 #endif // DISTRIBUTED_DATA_TASK_MANAGER_H
42