1 /* 2 * Copyright (c) 2025-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_FILEMGMT_BACKUP_SCAN_FILE_SINGLETON_H 17 #define OHOS_FILEMGMT_BACKUP_SCAN_FILE_SINGLETON_H 18 19 #include <map> 20 #include <mutex> 21 #include <queue> 22 #include <string> 23 #include <sys/stat.h> 24 25 namespace OHOS::FileManagement::Backup { 26 class ScanFileSingleton { 27 public: 28 static ScanFileSingleton &GetInstance(); 29 30 void AddBigFile(const std::string& key, const struct stat& value); 31 32 void AddSmallFile(const std::string& key, size_t value); 33 34 std::map<std::string, struct stat> GetAllBigFiles(); 35 36 bool GetCompletedFlag(); 37 38 void SetCompletedFlag(bool value); 39 40 std::map<std::string, size_t> GetAllSmallFiles(); 41 42 void SetIncludeSize(uint32_t includeSize); 43 44 void SetExcludeSize(uint32_t excludeSize); 45 46 uint32_t GetIncludeSize(); 47 48 uint32_t GetExcludeSize(); 49 50 // 条件等待,等待文件被添加或者扫描完成 51 void WaitForFiles(); 52 private: 53 // 私有构造函数,防止外部实例化 ScanFileSingleton()54 ScanFileSingleton() {} 55 ~ScanFileSingleton(); 56 57 std::queue<std::pair<std::string, struct stat>> bigFileQueue_; 58 std::map<std::string, size_t> smallFiles_; 59 std::mutex mutexLock_; 60 std::condition_variable waitForFilesAddCv_; 61 bool isCalculateCompleted_ = false; 62 uint32_t includeSize_ = 0; 63 uint32_t excludeSize_ = 0; 64 }; 65 } // namespace OHOS::FileManagement::ScanFileSingleton 66 #endif // OHOS_FILEMGMT_BACKUP_SCAN_FILE_SINGLETON_H