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 { 29 FIELDKEY_CONTENT = 1 << 0, 30 FIELDKEY_THUMB = 1 << 1, 31 FIELDKEY_LCD = 1 << 2, 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 SwitchDataObj : public Parcelable { 74 std::map<std::string, bool> switchData; 75 bool ReadFromParcel(Parcel &parcel); 76 bool Marshalling(Parcel &parcel) const override; 77 static SwitchDataObj *Unmarshalling(Parcel &parcel); 78 }; 79 80 struct CleanOptions : public Parcelable { 81 std::map<std::string, int32_t> appActionsData; 82 bool ReadFromParcel(Parcel &parcel); 83 bool Marshalling(Parcel &parcel) const override; 84 static CleanOptions *Unmarshalling(Parcel &parcel); 85 }; 86 87 struct OptimizeSpaceOptions : public Parcelable { 88 int64_t totalSize; 89 int32_t agingDays; 90 bool ReadFromParcel(Parcel &parcel); 91 bool Marshalling(Parcel &parcel) const override; 92 static OptimizeSpaceOptions *Unmarshalling(Parcel &parcel); 93 }; 94 95 96 struct DentryFileInfo { 97 std::string cloudId; 98 int64_t size; 99 int64_t modifiedTime; 100 std::string path; 101 std::string fileName; 102 std::string fileType; 103 }; 104 105 struct DentryFileInfoObj : public Parcelable { 106 std::string cloudId; 107 int64_t size; 108 int64_t modifiedTime; 109 std::string path; 110 std::string fileName; 111 std::string fileType; 112 bool ReadFromParcel(Parcel &parcel); 113 bool Marshalling(Parcel &parcel) const override; 114 static DentryFileInfoObj *Unmarshalling(Parcel &parcel); 115 116 DentryFileInfoObj() = default; DentryFileInfoObjDentryFileInfoObj117 DentryFileInfoObj(const DentryFileInfo &FileInfo) 118 : cloudId(FileInfo.cloudId), 119 size(FileInfo.size), 120 modifiedTime(FileInfo.modifiedTime), 121 path(FileInfo.path), 122 fileName(FileInfo.fileName), 123 fileType(FileInfo.fileType) 124 { 125 } 126 }; 127 128 struct AssetInfoObj : public Parcelable { 129 std::string uri; 130 std::string recordType; 131 std::string recordId; 132 std::string fieldKey; 133 std::string assetName; 134 bool ReadFromParcel(Parcel &parcel); 135 bool Marshalling(Parcel &parcel) const override; 136 static AssetInfoObj *Unmarshalling(Parcel &parcel); 137 138 AssetInfoObj() = default; AssetInfoObjAssetInfoObj139 AssetInfoObj(const AssetInfo &assetInfo) 140 : uri(assetInfo.uri), 141 recordType(assetInfo.recordType), 142 recordId(assetInfo.recordId), 143 fieldKey(assetInfo.fieldKey), 144 assetName(assetInfo.assetName) 145 { 146 } 147 }; 148 149 struct CleanFileInfo { 150 std::string cloudId; 151 int64_t size; 152 int64_t modifiedTime; 153 std::string path; 154 std::string fileName; 155 std::vector<std::string> attachment; 156 }; 157 158 struct CleanFileInfoObj : public Parcelable { 159 std::string cloudId; 160 int64_t size; 161 int64_t modifiedTime; 162 std::string path; 163 std::string fileName; 164 std::vector<std::string> attachment; 165 bool ReadFromParcel(Parcel &parcel); 166 bool Marshalling(Parcel &parcel) const override; 167 static CleanFileInfoObj *Unmarshalling(Parcel &parcel); 168 169 CleanFileInfoObj() = default; CleanFileInfoObjCleanFileInfoObj170 CleanFileInfoObj(const CleanFileInfo &FileInfo) 171 : cloudId(FileInfo.cloudId), 172 size(FileInfo.size), 173 modifiedTime(FileInfo.modifiedTime), 174 path(FileInfo.path), 175 fileName(FileInfo.fileName), 176 attachment(FileInfo.attachment) 177 { 178 } 179 }; 180 181 } // namespace OHOS::FileManagement::CloudSync 182 #endif 183