• 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_CLOUD_SYNC_SERVICE_DATA_HANDLER_H
17 #define OHOS_CLOUD_SYNC_SERVICE_DATA_HANDLER_H
18 
19 #include <mutex>
20 
21 #include "cloud_pref_impl.h"
22 #include "sdk_helper.h"
23 #include "values_bucket.h"
24 
25 namespace OHOS {
26 namespace FileManagement {
27 namespace CloudSync {
28 struct OnFetchParams {
29     int32_t totalPullCount{0};
30     std::vector<DriveKit::DKDownloadAsset> assetsToDownload{};
31     std::vector<NativeRdb::ValuesBucket> insertFiles{};
32     std::map<std::string, std::set<int>> recordAlbumMaps{};
33 };
34 const static std::string DOWNLOAD_THUMB_LIMIT = "download_thumb_limit";
35 const static std::string BATCH_NO = "batch_no";
36 const static std::string RECORD_SIZE = "record_size";
37 const static std::string CHECKING_FLAG = "checking_flag";
38 class DataHandler {
39 public:
40     DataHandler(int32_t userId, const std::string &bundleName, const std::string &table);
41     /* download */
42     virtual void GetFetchCondition(FetchCondition &cond) = 0;
43     virtual int32_t OnFetchRecords(std::shared_ptr<std::vector<DriveKit::DKRecord>> &records,
44                                    OnFetchParams &params) = 0;
45     virtual int32_t GetRetryRecords(std::vector<DriveKit::DKRecordId> &records) = 0;
46     virtual int32_t GetCheckRecords(std::vector<DriveKit::DKRecordId> &checkRecords,
47                                     const std::shared_ptr<std::vector<DriveKit::DKRecord>> &records);
48     virtual int32_t GetAssetsToDownload(std::vector<DriveKit::DKDownloadAsset> &outAssetsToDownload);
49 
50     virtual int32_t GetDownloadAsset(std::string cloudId,
51                                      std::vector<DriveKit::DKDownloadAsset> &outAssetsToDownload);
52     /* upload */
53     virtual int32_t GetCreatedRecords(std::vector<DriveKit::DKRecord> &records) = 0;
54     virtual int32_t GetDeletedRecords(std::vector<DriveKit::DKRecord> &records) = 0;
55     virtual int32_t GetMetaModifiedRecords(std::vector<DriveKit::DKRecord> &records) = 0;
56     virtual int32_t GetFileModifiedRecords(std::vector<DriveKit::DKRecord> &records);
57 
58     /* upload callback */
59     virtual int32_t OnCreateRecords(const std::map<DriveKit::DKRecordId,
60         DriveKit::DKRecordOperResult> &map) = 0;
61     virtual int32_t OnDeleteRecords(const std::map<DriveKit::DKRecordId,
62         DriveKit::DKRecordOperResult> &map) = 0;
63     virtual int32_t OnModifyMdirtyRecords(const std::map<DriveKit::DKRecordId,
64         DriveKit::DKRecordOperResult> &map) = 0;
65     virtual int32_t OnModifyFdirtyRecords(const std::map<DriveKit::DKRecordId,
66         DriveKit::DKRecordOperResult> &map);
67     virtual int32_t OnDownloadSuccess(const DriveKit::DKDownloadAsset &asset);
68     virtual int32_t OnDownloadThumb(const std::map<DriveKit::DKDownloadAsset, DriveKit::DKDownloadResult> &resultMap);
69     virtual int32_t OnDownloadThumb(const DriveKit::DKDownloadAsset &asset);
70 
71     /*clean*/
72     virtual int32_t Clean(const int action);
73 
74     /* cursor */
75     virtual void GetNextCursor(DriveKit::DKQueryCursor &cursor);
76     virtual void SetTempStartCursor(const DriveKit::DKQueryCursor &cursor);
77     virtual void GetTempStartCursor(DriveKit::DKQueryCursor &cursor);
78     virtual void SetTempNextCursor(const DriveKit::DKQueryCursor &cursor, bool isFinish);
79     virtual int32_t GetBatchNo();
80     virtual bool IsPullRecords();
81     virtual void ClearCursor();
82     virtual void FinishPull(const int32_t barchNo);
83     virtual void SetRecordSize(const int32_t recordSize);
84     virtual int32_t GetRecordSize();
85     virtual bool GetCheckFlag();
86     virtual void SetChecking();
87 
88 protected:
89     /* cursor */
90     DriveKit::DKQueryCursor startCursor_;
91     DriveKit::DKQueryCursor nextCursor_;
92     DriveKit::DKQueryCursor tempStartCursor_;
93     DriveKit::DKQueryCursor tempNextCursor_;
94     int32_t batchNo_{0};
95     int32_t recordSize_{0};
96     int32_t downloadThumbLimit_{0};
97     bool isFinish_{false};
98     std::map<int32_t, DriveKit::DKQueryCursor> cursorMap_;
99     std::map<int32_t, bool> cursorFinishMap_;
100     bool isChecking_{false};
101 
102     std::mutex mutex_;
103 
104     /* cloud preference impl */
105     CloudPrefImpl cloudPrefImpl_;
106 };
107 } // namespace CloudSync
108 } // namespace FileManagement
109 } // namespace OHOS
110 #endif // OHOS_CLOUD_SYNC_SERVICE_DATA_HANDLER_H
111