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 enum FieldKey { 28 FIELDKEY_CONTENT = 1 << 0, 29 FIELDKEY_THUMB = 1 << 1, 30 FIELDKEY_LCD = 1 << 2, 31 }; 32 33 struct DownloadProgressObj : public Parcelable { 34 enum Status : int32_t { 35 RUNNING = 0, 36 COMPLETED = 1, 37 FAILED = 2, 38 STOPPED = 3, 39 }; 40 enum DownloadErrorType : int32_t { 41 NO_ERROR = 0, 42 UNKNOWN_ERROR = 1, 43 NETWORK_UNAVAILABLE = 2, 44 LOCAL_STORAGE_FULL = 3, 45 CONTENT_NOT_FOUND = 4, 46 FREQUENT_USER_REQUESTS = 5, 47 }; 48 uint32_t refCount; 49 std::string path; 50 int64_t downloadId; 51 Status state; 52 int32_t downloadErrorType; 53 int64_t downloadedSize; 54 int64_t totalSize; 55 56 // member for batch download(same downloadId) 57 int64_t batchDownloadSize; 58 int64_t batchTotalSize; 59 int64_t batchSuccNum; 60 int64_t batchFailNum; 61 int64_t batchTotalNum; 62 Status batchState; 63 64 bool ReadBatchFromParcel(Parcel &parcel); 65 bool ReadFromParcel(Parcel &parcel); 66 bool MarshallingBatch(Parcel &parcel) const; 67 bool Marshalling(Parcel &parcel) const override; 68 static DownloadProgressObj *Unmarshalling(Parcel &parcel); 69 std::string to_string(); 70 }; 71 72 struct SwitchDataObj : public Parcelable { 73 std::map<std::string, bool> switchData; 74 bool ReadFromParcel(Parcel &parcel); 75 bool Marshalling(Parcel &parcel) const override; 76 static SwitchDataObj *Unmarshalling(Parcel &parcel); 77 }; 78 79 struct CleanOptions : public Parcelable { 80 std::map<std::string, int32_t> appActionsData; 81 bool ReadFromParcel(Parcel &parcel); 82 bool Marshalling(Parcel &parcel) const override; 83 static CleanOptions *Unmarshalling(Parcel &parcel); 84 }; 85 86 struct DentryFileInfo { 87 std::string cloudId; 88 int64_t size; 89 int64_t modifiedTime; 90 std::string path; 91 std::string fileName; 92 std::string fileType; 93 }; 94 95 struct DentryFileInfoObj : public Parcelable { 96 std::string cloudId; 97 int64_t size; 98 int64_t modifiedTime; 99 std::string path; 100 std::string fileName; 101 std::string fileType; 102 bool ReadFromParcel(Parcel &parcel); 103 bool Marshalling(Parcel &parcel) const override; 104 static DentryFileInfoObj *Unmarshalling(Parcel &parcel); 105 106 DentryFileInfoObj() = default; DentryFileInfoObjDentryFileInfoObj107 DentryFileInfoObj(const DentryFileInfo &FileInfo) 108 : cloudId(FileInfo.cloudId), 109 size(FileInfo.size), 110 modifiedTime(FileInfo.modifiedTime), 111 path(FileInfo.path), 112 fileName(FileInfo.fileName), 113 fileType(FileInfo.fileType) 114 { 115 } 116 }; 117 118 struct AssetInfoObj : public Parcelable { 119 std::string uri; 120 std::string recordType; 121 std::string recordId; 122 std::string fieldKey; 123 std::string assetName; 124 bool ReadFromParcel(Parcel &parcel); 125 bool Marshalling(Parcel &parcel) const override; 126 static AssetInfoObj *Unmarshalling(Parcel &parcel); 127 128 AssetInfoObj() = default; AssetInfoObjAssetInfoObj129 AssetInfoObj(const AssetInfo &assetInfo) 130 : uri(assetInfo.uri), 131 recordType(assetInfo.recordType), 132 recordId(assetInfo.recordId), 133 fieldKey(assetInfo.fieldKey), 134 assetName(assetInfo.assetName) 135 { 136 } 137 }; 138 } // namespace OHOS::FileManagement::CloudSync 139 #endif 140