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_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_GENERATE_WORKER_MANAGER_H 17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_GENERATE_WORKER_MANAGER_H 18 19 #include <safe_map.h> 20 #include <shared_mutex> 21 22 #include "thumbnail_generate_worker.h" 23 24 namespace OHOS { 25 namespace Media { 26 #define EXPORT __attribute__ ((visibility ("default"))) 27 using ThumbnailWorkerPtr = std::shared_ptr<ThumbnailGenerateWorker>; 28 29 class ThumbnailGenerateWorkerManager { 30 public: GetInstance()31 EXPORT static ThumbnailGenerateWorkerManager &GetInstance() 32 { 33 static ThumbnailGenerateWorkerManager instance; 34 return instance; 35 } 36 37 EXPORT ThumbnailWorkerPtr GetThumbnailWorker(const ThumbnailTaskType &taskType); 38 39 EXPORT void ClearAllTask(); 40 41 EXPORT void TryCloseThumbnailWorkerTimer(); 42 43 private: 44 ThumbnailGenerateWorkerManager() = default; 45 ~ThumbnailGenerateWorkerManager(); 46 47 int32_t InitThumbnailWorker(const ThumbnailTaskType &taskType); 48 49 SafeMap<ThumbnailTaskType, ThumbnailWorkerPtr> thumbnailWorkerMap_; 50 51 std::mutex mutex_; 52 }; 53 } // namespace Media 54 } // namespace OHOS 55 56 #endif //FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_GENERATE_WORKER_MANAGER_H