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_FILEMGMT_CLOUD_FILE_CACHE_CORE_H 17 #define OHOS_FILEMGMT_CLOUD_FILE_CACHE_CORE_H 18 19 #include <mutex> 20 #include <optional> 21 #include <unordered_set> 22 23 #include "download_callback_impl_ani.h" 24 #include "filemgmt_libfs.h" 25 26 namespace OHOS::FileManagement::CloudSync { 27 const std::string PROGRESS = "progress"; 28 const std::string MULTI_PROGRESS = "batchDownload"; 29 class CloudFileCacheCore { 30 public: 31 CloudFileCacheCore() = default; 32 ~CloudFileCacheCore() = default; 33 34 static ModuleFileIO::FsResult<CloudFileCacheCore *> Constructor(); 35 ModuleFileIO::FsResult<void> DoOn(const std::string &event, 36 const std::shared_ptr<CloudFileCacheCallbackImplAni> callback); 37 ModuleFileIO::FsResult<void> DoOff(const std::string &event, 38 const std::optional<std::shared_ptr<CloudFileCacheCallbackImplAni>> &callback = std::nullopt); 39 ModuleFileIO::FsResult<void> DoStart(const std::string &uri); 40 ModuleFileIO::FsResult<int64_t> DoStart(const std::vector<std::string> &uriList, int32_t fieldKey); 41 ModuleFileIO::FsResult<void> DoStop(const std::string &uri, bool needClean = false); 42 ModuleFileIO::FsResult<void> DoStop(int64_t downloadId, bool needClean = false); 43 ModuleFileIO::FsResult<void> CleanCache(const std::string &uri); 44 std::shared_ptr<CloudFileCacheCallbackImplAni> GetCallbackImpl(const std::string &eventType, bool isInit); 45 46 private: 47 std::mutex registerMutex_; 48 std::unordered_map<std::string, std::shared_ptr<CloudFileCacheCallbackImplAni>> registerMap_; 49 }; 50 51 } // namespace OHOS::FileManagement::CloudSync 52 #endif // OHOS_FILEMGMT_CLOUD_FILE_CACHE_CORE_H