• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     friend class UdmfCopyFile;
25     static UdmfAsyncClient API_EXPORT &GetInstance();
26     Status API_EXPORT StartAsyncDataRetrieval(const GetDataParams &params);
27     Status API_EXPORT Cancel(std::string businessUdKey);
28     Status CancelOnSingleTask();
29 private:
30     UdmfAsyncClient();
31     ~UdmfAsyncClient() = default;
32     UdmfAsyncClient(const UdmfAsyncClient &obj) = delete;
33     UdmfAsyncClient &operator = (const UdmfAsyncClient &obj) = delete;
34 
35     Status ProgressTask(const std::string &businessUdKey);
36     Status GetDataTask(const QueryOption &query);
37     Status InvokeHapTask(const std::string &businessUdKey);
38 
39     Status RegisterAsyncHelper(const GetDataParams &params);
40     Status CheckSync(std::unique_ptr<AsyncHelper> &asyncHelper, const QueryOption &query);
41     Status GetDataFromDB(std::unique_ptr<AsyncHelper> &asyncHelper, const QueryOption &query);
42     Status GetDataFromCache(std::unique_ptr<AsyncHelper> &asyncHelper, const QueryOption &query);
43     Status SetProgressData(const std::string &businessUdKey);
44     Status SetCancelData(const std::string &businessUdKey);
45     Status UpdateProgressData(const std::string &progressUdKey, const ProgressInfo &progressInfo);
46     Status CopyFile(std::unique_ptr<AsyncHelper> &asyncHelper);
47     void CallProgress(std::unique_ptr<AsyncHelper> &asyncHelper, ProgressInfo &progressInfo,
48         std::shared_ptr<UnifiedData> data);
49     Status Clear(const std::string &businessUdKey);
50     Status ProcessUnifiedData(std::unique_ptr<AsyncHelper> &asyncHelper);
51     bool IsParamValid(const GetDataParams &params);
52 
53 #ifndef IOS_PLATFORM
54     ExecutorPool executor_;
55 #endif
56     std::map<std::string, std::unique_ptr<AsyncHelper>> asyncHelperMap_;
57     std::mutex mutex_;
58 };
59 } // namespace
60 #endif // UDMF_ASYNC_CLIENT_H
61