• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 DRIVE_KIT_ASSETS_DOWNLOADER_H
17 #define DRIVE_KIT_ASSETS_DOWNLOADER_H
18 
19 #include <functional>
20 #include <map>
21 
22 #include "dk_context.h"
23 #include "dk_error.h"
24 #include "dk_record.h"
25 #include "dk_result.h"
26 
27 namespace DriveKit {
28 using DKDownloadId = int64_t;
29 using DKAssetPath = std::string;
30 using TotalSize = int64_t;
31 using DownloadSize = int64_t;
32 class DKDatabase;
33 class DKDownloadResult : public DKResult {
34 public:
GetAsset()35     DKAsset GetAsset()
36     {
37         return asset_;
38     }
SetAsset(DKAsset asset)39     void SetAsset(DKAsset asset)
40     {
41         asset_ = asset;
42     }
43 
44 private:
45     DKAsset asset_;
46 };
47 struct DKDownloadAsset {
48     DKRecordType recordType;
49     DKRecordId recordId;
50     DKFieldKey fieldKey;
51     DKAsset asset;
52     DKAssetPath downLoadPath;
53 };
54 
55 class DKAssetsDownloader {
56 public:
57     DKLocalErrorCode DownLoadAssets(
58         std::shared_ptr<DKContext> contex,
59         std::vector<DKDownloadAsset> &assetsToDownload,
60         DKAssetPath downLoadPath,
61         DKDownloadId &id,
62         std::function<void(std::shared_ptr<DKContext>,
63                            std::shared_ptr<const DKDatabase>,
64                            const std::map<DKDownloadAsset, DKDownloadResult> &,
65                            const DKError &)> resultCallback,
66         std::function<void(std::shared_ptr<DKContext>, DKDownloadAsset, TotalSize, DownloadSize)> progressCallback);
67     DKLocalErrorCode DownLoadAssets(DKDownloadAsset &assetsToDownload);
68 
69     DKLocalErrorCode CancelDownloadAssets(DKDownloadId id);
DKAssetsDownloader(std::shared_ptr<DKDatabase> database)70     DKAssetsDownloader(std::shared_ptr<DKDatabase> database)
71     {
72         database_ = database;
73     };
~DKAssetsDownloader()74     virtual ~DKAssetsDownloader(){};
75 
76 private:
77     std::shared_ptr<DKDatabase> database_;
78 };
79 } // namespace DriveKit
80 #endif
81