1 /* 2 * Copyright (c) 2025 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_MEDIALIBRARY_MULTI_THREAD_ASSET_CHANGE_INFO_MGR_H 17 #define OHOS_MEDIALIBRARY_MULTI_THREAD_ASSET_CHANGE_INFO_MGR_H 18 19 #include <mutex> 20 #include <unordered_map> 21 22 #include "photo_asset_change_info.h" 23 24 namespace OHOS { 25 namespace Media::AccurateRefresh { 26 27 struct MultiThreadAssetChangeData { 28 int32_t count_ = 0; 29 bool isMultiOperation_ = false; 30 PhotoAssetChangeInfo infoBefore_; 31 PhotoAssetChangeInfo infoAfter_; 32 }; 33 34 class MultiThreadAssetChangeInfoMgr { 35 public: GetInstance()36 static MultiThreadAssetChangeInfoMgr& GetInstance() 37 { 38 static MultiThreadAssetChangeInfoMgr instance; 39 return instance; 40 } 41 42 // 插入修改前数据,多次插入返回true 43 bool CheckInsertBeforeInfo(PhotoAssetChangeInfo& info); 44 45 // 插入修改后数据,多次插入返回true 46 bool CheckInsertAfterInfo(PhotoAssetChangeInfo& info, bool isAdd = false); 47 48 std::pair<PhotoAssetChangeInfo, PhotoAssetChangeInfo> GetAssetChangeData(int32_t fileId); 49 50 // 相册计算时获取fileId对应的数据,同时执行update信息before = after 51 std::pair<PhotoAssetChangeInfo, PhotoAssetChangeInfo> GetAndUpdateAssetChangeData(int32_t fileId); 52 53 void ClearMultiThreadChangeData(int32_t fileId); 54 55 private: MultiThreadAssetChangeInfoMgr()56 MultiThreadAssetChangeInfoMgr() {} ~MultiThreadAssetChangeInfoMgr()57 ~MultiThreadAssetChangeInfoMgr() {} 58 MultiThreadAssetChangeInfoMgr(const MultiThreadAssetChangeInfoMgr&) = delete; 59 MultiThreadAssetChangeInfoMgr& operator=(const MultiThreadAssetChangeInfoMgr&) = delete; 60 61 private: 62 static std::mutex changeDataMutex_; 63 std::unordered_map<int32_t, MultiThreadAssetChangeData> assetChangeDataMap_; 64 }; 65 66 } // namespace Media::AccurateRefresh 67 } // namespace OHOS 68 69 #endif