• 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 OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H
17 #define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H
18 
19 #include "cloud/asset_loader.h"
20 #include "cloud/cloud_store_types.h"
21 #include "cloud/iAssetLoader.h"
22 #include "error/general_error.h"
23 #include "snapshot/snapshot.h"
24 
25 namespace OHOS::DistributedRdb {
26 using Snapshot = DistributedData::Snapshot;
27 using BindAssets = std::shared_ptr<std::map<std::string, std::shared_ptr<Snapshot>>>;
28 class RdbAssetLoader : public DistributedDB::IAssetLoader {
29 public:
30     using Type = DistributedDB::Type;
31     using Asset = DistributedDB::Asset;
32     using DBStatus = DistributedDB::DBStatus;
33     using AssetsRecord = DistributedData::AssetRecord;
34     using AssetStatus = DistributedData::Asset::Status;
35     using GeneralError = DistributedData::GeneralError;
36     using VBucket = DistributedData::VBucket;
37 
38     explicit RdbAssetLoader(std::shared_ptr<DistributedData::AssetLoader> cloudAssetLoader, BindAssets bindAssets);
39 
40     ~RdbAssetLoader() = default;
41 
42     DBStatus Download(const std::string &tableName, const std::string &gid, const Type &prefix,
43         std::map<std::string, std::vector<Asset>> &assets) override;
44 
45     void BatchDownload(const std::string &tableName, std::vector<AssetRecord> &downloadAssets) override;
46 
47     DBStatus RemoveLocalAssets(const std::vector<Asset> &assets) override;
48 
49     DBStatus CancelDownload() override;
50 
51 private:
52     static std::vector<AssetRecord> Convert(std::vector<AssetsRecord> &&assetsRecords);
53     static std::vector<AssetsRecord> Convert(std::vector<AssetRecord> &&assetRecords);
54     static DBStatus ConvertStatus(AssetStatus error);
55     static void UpdateStatus(AssetRecord &assetRecord, const VBucket &assets);
56 
57     void PostEvent(std::set<std::string> &skipAssets, std::map<std::string, DistributedData::Value> &assets,
58         DistributedData::AssetEvent eventId, std::set<std::string> &deleteAssets);
59     void PostEvent(std::set<std::string> &skipAssets, std::vector<AssetsRecord> &assetsRecords,
60         DistributedData::AssetEvent eventId, std::set<std::string> &deleteAssets);
61     void PostEvent(DistributedData::AssetEvent eventId, DistributedData::Assets &assets,
62         std::set<std::string> &skipAssets, std::set<std::string> &deleteAssets);
63 
64     std::shared_ptr<DistributedData::AssetLoader> assetLoader_;
65     const BindAssets snapshots_;
66 };
67 } // namespace OHOS::DistributedRdb
68 #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H