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 AssetInfoObj : public Parcelable { 87 std::string uri; 88 std::string recordType; 89 std::string recordId; 90 std::string fieldKey; 91 std::string assetName; 92 bool ReadFromParcel(Parcel &parcel); 93 bool Marshalling(Parcel &parcel) const override; 94 static AssetInfoObj *Unmarshalling(Parcel &parcel); 95 96 AssetInfoObj() = default; AssetInfoObjAssetInfoObj97 AssetInfoObj(const AssetInfo &assetInfo) 98 : uri(assetInfo.uri), 99 recordType(assetInfo.recordType), 100 recordId(assetInfo.recordId), 101 fieldKey(assetInfo.fieldKey), 102 assetName(assetInfo.assetName) 103 { 104 } 105 }; 106 } // namespace OHOS::FileManagement::CloudSync 107 #endif 108