• 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_FILEMGMT_CLOUD_SYNC_COMMON_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_COMMON_H
18 
19 #include <bitset>
20 #include <map>
21 
22 #include "parcel.h"
23 #include "cloud_sync_asset_manager.h"
24 
25 namespace OHOS::FileManagement::CloudSync {
26 #define FIELD_KEY_MAX_SIZE 4
27 constexpr int32_t CLEAN_FILE_MAX_SIZE = 200;
28 enum FieldKey : int32_t {
29     FIELDKEY_CONTENT = 0,
30     FIELDKEY_THUMB,
31     FIELDKEY_LCD,
32 };
33 
34 struct DownloadProgressObj : public Parcelable {
35     enum Status : int32_t {
36         RUNNING = 0,
37         COMPLETED = 1,
38         FAILED = 2,
39         STOPPED = 3,
40     };
41     enum DownloadErrorType : int32_t {
42         NO_ERROR = 0,
43         UNKNOWN_ERROR = 1,
44         NETWORK_UNAVAILABLE = 2,
45         LOCAL_STORAGE_FULL = 3,
46         CONTENT_NOT_FOUND = 4,
47         FREQUENT_USER_REQUESTS = 5,
48     };
49     uint32_t refCount;
50     std::string path;
51     int64_t downloadId;
52     Status state;
53     int32_t downloadErrorType;
54     int64_t downloadedSize;
55     int64_t totalSize;
56 
57     // member for batch download(same downloadId)
58     int64_t batchDownloadSize;
59     int64_t batchTotalSize;
60     int64_t batchSuccNum;
61     int64_t batchFailNum;
62     int64_t batchTotalNum;
63     Status batchState;
64 
65     bool ReadBatchFromParcel(Parcel &parcel);
66     bool ReadFromParcel(Parcel &parcel);
67     bool MarshallingBatch(Parcel &parcel) const;
68     bool Marshalling(Parcel &parcel) const override;
69     static DownloadProgressObj *Unmarshalling(Parcel &parcel);
70     std::string to_string();
71 };
72 
73 struct DowngradeProgress : public Parcelable {
74     enum State : int32_t {
75         RUNNING = 0,
76         COMPLETED,
77         STOPPED,
78     };
79     enum StopReason : int32_t {
80         NO_STOP = 0,
81         NETWORK_UNAVAILABLE,
82         LOCAL_STORAGE_FULL,
83         TEMPERATURE_LIMIT,
84         USER_STOPPED,
85         APP_UNLOAD,
86         OTHER_REASON
87     };
88     State state;
89     StopReason stopReason;
90     int64_t downloadedSize;
91     int64_t totalSize;
92     int32_t successfulCount;
93     int32_t failedCount;
94     int32_t totalCount;
95 
96     bool ReadFromParcel(Parcel &parcel);
97     bool Marshalling(Parcel &parcel) const override;
98     static DowngradeProgress *Unmarshalling(Parcel &parcel);
99     std::string to_string() const;
100 };
101 
102 struct SwitchDataObj : public Parcelable {
103     std::map<std::string, bool> switchData;
104     bool ReadFromParcel(Parcel &parcel);
105     bool Marshalling(Parcel &parcel) const override;
106     static SwitchDataObj *Unmarshalling(Parcel &parcel);
107 };
108 
109 struct CleanOptions : public Parcelable {
110     std::map<std::string, int32_t> appActionsData;
111     bool ReadFromParcel(Parcel &parcel);
112     bool Marshalling(Parcel &parcel) const override;
113     static CleanOptions *Unmarshalling(Parcel &parcel);
114 };
115 
116 struct OptimizeSpaceOptions : public Parcelable {
117     int64_t totalSize;
118     int32_t agingDays;
119     bool ReadFromParcel(Parcel &parcel);
120     bool Marshalling(Parcel &parcel) const override;
121     static OptimizeSpaceOptions *Unmarshalling(Parcel &parcel);
122 };
123 
124 
125 struct DentryFileInfo {
126     std::string cloudId;
127     int64_t size;
128     int64_t modifiedTime;
129     std::string path;
130     std::string fileName;
131     std::string fileType;
132 };
133 
134 struct  DentryFileInfoObj : public Parcelable {
135     std::string cloudId;
136     int64_t size;
137     int64_t modifiedTime;
138     std::string path;
139     std::string fileName;
140     std::string fileType;
141     bool ReadFromParcel(Parcel &parcel);
142     bool Marshalling(Parcel &parcel) const override;
143     static DentryFileInfoObj *Unmarshalling(Parcel &parcel);
144 
145     DentryFileInfoObj() = default;
DentryFileInfoObjDentryFileInfoObj146     DentryFileInfoObj(const DentryFileInfo &FileInfo)
147         : cloudId(FileInfo.cloudId),
148           size(FileInfo.size),
149           modifiedTime(FileInfo.modifiedTime),
150           path(FileInfo.path),
151           fileName(FileInfo.fileName),
152           fileType(FileInfo.fileType)
153     {
154     }
155 };
156 
157 struct AssetInfoObj : public Parcelable {
158     std::string uri;
159     std::string recordType;
160     std::string recordId;
161     std::string fieldKey;
162     std::string assetName;
163     bool ReadFromParcel(Parcel &parcel);
164     bool Marshalling(Parcel &parcel) const override;
165     static AssetInfoObj *Unmarshalling(Parcel &parcel);
166 
167     AssetInfoObj() = default;
AssetInfoObjAssetInfoObj168     AssetInfoObj(const AssetInfo &assetInfo)
169         : uri(assetInfo.uri),
170           recordType(assetInfo.recordType),
171           recordId(assetInfo.recordId),
172           fieldKey(assetInfo.fieldKey),
173           assetName(assetInfo.assetName)
174     {
175     }
176 };
177 
178 struct CleanFileInfo {
179     std::string cloudId;
180     int64_t size;
181     int64_t modifiedTime;
182     std::string path;
183     std::string fileName;
184     std::vector<std::string> attachment;
185 };
186 
187 struct  CleanFileInfoObj : public Parcelable {
188     std::string cloudId;
189     int64_t size;
190     int64_t modifiedTime;
191     std::string path;
192     std::string fileName;
193     std::vector<std::string> attachment;
194     bool ReadFromParcel(Parcel &parcel);
195     bool Marshalling(Parcel &parcel) const override;
196     static CleanFileInfoObj *Unmarshalling(Parcel &parcel);
197 
198     CleanFileInfoObj() = default;
CleanFileInfoObjCleanFileInfoObj199     CleanFileInfoObj(const CleanFileInfo &FileInfo)
200         : cloudId(FileInfo.cloudId),
201           size(FileInfo.size),
202           modifiedTime(FileInfo.modifiedTime),
203           path(FileInfo.path),
204           fileName(FileInfo.fileName),
205           attachment(FileInfo.attachment)
206     {
207     }
208 };
209 
210 struct HistoryVersion : public Parcelable {
211     int64_t editedTime{0};
212     uint64_t fileSize{0};
213     uint64_t versionId{0};
214     std::string originalFileName;
215     std::string sha256;
216     bool resolved{false};
217 
218     bool ReadFromParcel(Parcel &parcel);
219     bool Marshalling(Parcel &parcel) const override;
220     static HistoryVersion *Unmarshalling(Parcel &parcel);
221 };
222 
223 /*
224  * 降级下载:待下载信息
225  */
226 struct CloudFileInfo : public Parcelable {
227     int32_t cloudfileCount{0};
228     int64_t cloudFileTotalSize{0};
229     int32_t localFileCount{0};
230     int64_t localFileTotalSize{0};
231     int32_t bothFileCount{0};
232     int64_t bothFileTotalSize{0};
233 
234     bool ReadFromParcel(Parcel &parcel);
235     bool Marshalling(Parcel &parcel) const override;
236     static CloudFileInfo *Unmarshalling(Parcel &parcel);
237 };
238 } // namespace OHOS::FileManagement::CloudSync
239 #endif // OHOS_FILEMGMT_CLOUD_SYNC_COMMON_H
240