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 UDMF_ASYNC_CLIENT_H 17 #define UDMF_ASYNC_CLIENT_H 18 19 #include "async_task_params.h" 20 21 namespace OHOS::UDMF { 22 class UdmfAsyncClient { 23 public: 24 using UdmfTask = std::function<void()>; 25 friend class UdmfCopyFile; 26 static UdmfAsyncClient API_EXPORT &GetInstance(); 27 Status API_EXPORT StartAsyncDataRetrieval(const GetDataParams ¶ms); 28 Status API_EXPORT Cancel(std::string businessUdKey); 29 Status CancelOnSingleTask(); 30 void PushTaskToExecutor(UdmfTask task); 31 private: 32 UdmfAsyncClient(); 33 ~UdmfAsyncClient() = default; 34 UdmfAsyncClient(const UdmfAsyncClient &obj) = delete; 35 UdmfAsyncClient &operator = (const UdmfAsyncClient &obj) = delete; 36 37 Status ProgressTask(const std::string &businessUdKey); 38 Status GetDataTask(const QueryOption &query); 39 Status InvokeHapTask(const std::string &businessUdKey); 40 41 Status RegisterAsyncHelper(const GetDataParams ¶ms); 42 Status CheckSync(std::unique_ptr<AsyncHelper> &asyncHelper, const QueryOption &query); 43 Status GetDataFromDB(std::unique_ptr<AsyncHelper> &asyncHelper, const QueryOption &query); 44 Status GetDataFromCache(std::unique_ptr<AsyncHelper> &asyncHelper, const QueryOption &query); 45 Status SetProgressData(const std::string &businessUdKey); 46 Status SetCancelData(const std::string &businessUdKey); 47 Status UpdateProgressData(const std::string &progressUdKey, const ProgressInfo &progressInfo); 48 Status CopyFile(std::unique_ptr<AsyncHelper> &asyncHelper); 49 void CallProgress(std::unique_ptr<AsyncHelper> &asyncHelper, ProgressInfo &progressInfo, 50 std::shared_ptr<UnifiedData> data); 51 Status Clear(const std::string &businessUdKey); 52 Status ProcessUnifiedData(std::unique_ptr<AsyncHelper> &asyncHelper); 53 bool IsParamValid(const GetDataParams ¶ms); 54 uint64_t GetCurrentTimeMillis(); 55 56 std::map<std::string, std::unique_ptr<AsyncHelper>> asyncHelperMap_ {}; 57 std::mutex mutex_; 58 }; 59 } // namespace 60 #endif // UDMF_ASYNC_CLIENT_H 61