1 /*
2  * Copyright (c) 2023-2023 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_DEFERRED_PROCESSING_SERVICE_TASK_REGISTRY_H
17 #define OHOS_DEFERRED_PROCESSING_SERVICE_TASK_REGISTRY_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <functional>
22 #include <map>
23 #include <mutex>
24 #include <string>
25 
26 #include "thread_pool.h"
27 #include "itask_group.h"
28 
29 namespace OHOS {
30 namespace CameraStandard {
31 namespace DeferredProcessing {
32 class TaskRegistry final {
33 public:
34     TaskRegistry(const std::string& name, const ThreadPool* threadPool);
35     ~TaskRegistry();
36     bool RegisterTaskGroup(const std::string& name, TaskFunc func, bool serial, bool delayTask,
37         TaskGroupHandle& handle);
38     bool DeregisterTaskGroup(const std::string& name, TaskGroupHandle& handle);
39     bool SubmitTask(TaskGroupHandle handle, std::any param);
40     void CancelAllTasks(TaskGroupHandle handle);
41     size_t GetTaskCount(TaskGroupHandle handle);
42 private:
43 
44     bool IsTaskGroupAlreadyRegistered(const std::string& name);
45 
46     const std::string name_;
47     const ThreadPool* threadPool_;
48     std::mutex mutex_;
49     std::map<TaskGroupHandle, std::shared_ptr<ITaskGroup>> registry_;
50 };
51 } //namespace DeferredProcessing
52 } // namespace CameraStandard
53 } // namespace OHOS
54 #endif // OHOS_DEFERRED_PROCESSING_SERVICE_TASK_REGISTRY_H
55