/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_NETWORK_DOWNLOAD_MANAGER_H #define FOUNDATION_ACE_FRAMEWORKS_BASE_NETWORK_DOWNLOAD_MANAGER_H #include #include #include #include #include #include #include namespace OHOS::Ace { struct DownloadCallback { std::function successCallback; std::function failCallback; std::function cancelCallback; std::function onProgressCallback; }; struct DownloadCondition { std::condition_variable cv; std::string dataOut; std::mutex downloadMutex; std::string errorMsg; std::optional downloadSuccess; }; struct DownloadResult { std::string dataOut; std::string errorMsg; std::optional downloadSuccess; }; class DownloadManager { public: static DownloadManager* GetInstance(); virtual ~DownloadManager() = default; virtual bool Download(const std::string& url, std::vector& dataOut); virtual bool Download(const std::string& url, const std::shared_ptr& result); virtual bool DownloadAsync( DownloadCallback&& downloadCallback, const std::string& url, int32_t instanceId, int32_t nodeId); virtual bool DownloadSync( DownloadCallback&& downloadCallback, const std::string& url, int32_t instanceId, int32_t nodeId); virtual bool RemoveDownloadTask(const std::string& url, int32_t nodeId, bool isCancel = true); private: static std::unique_ptr instance_; static std::mutex mutex_; }; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_NETWORK_DOWNLOAD_MANAGER_H