1 /* 2 * Copyright (C) 2024 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 FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_MANAGER_H 17 #define FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_MANAGER_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_map> 22 23 namespace OHOS { 24 namespace Media { 25 #define EXPORT __attribute__ ((visibility ("default"))) 26 27 struct EnhancementTaskInfo { 28 std::string taskId; 29 int32_t fileId; 30 int32_t requestCount; EnhancementTaskInfoEnhancementTaskInfo31 EnhancementTaskInfo() : taskId(""), fileId(0), requestCount(0) {} EnhancementTaskInfoEnhancementTaskInfo32 EnhancementTaskInfo(std::string taskId, int32_t fileId, int32_t count) 33 : taskId(taskId), fileId(fileId), requestCount(count) {} 34 }; 35 36 class EnhancementTaskManager { 37 public: 38 EXPORT static void AddEnhancementTask(int32_t fileId, const std::string &photoId); 39 EXPORT static void RemoveEnhancementTask(const std::string &photoId); 40 EXPORT static void RemoveAllEnhancementTask(std::vector<std::string> &taskIds); 41 EXPORT static bool InProcessingTask(const std::string &photoId); 42 EXPORT static std::string QueryPhotoIdByFileId(int32_t fileId); 43 EXPORT static void SetTaskRequestCount(const std::string &photoId, int32_t count); 44 EXPORT static int32_t GetTaskRequestCount(const std::string &photoId); 45 46 private: 47 // key: photo_id 48 EXPORT static std::unordered_map<std::string, std::shared_ptr<EnhancementTaskInfo>> taskInProcess_; 49 EXPORT static std::unordered_map<int32_t, std::string> fileId2PhotoId_; 50 51 static std::mutex mutex_; 52 }; 53 } // namespace Media 54 } // namespace OHOS 55 #endif // FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_TASK_MANAGER_H