1 /* 2 * Copyright (C) 2022 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_MEDIALIBRARY_COMMAND_PARSE_H 17 #define OHOS_MEDIALIBRARY_COMMAND_PARSE_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <vector> 22 23 #include "abs_rdb_predicates.h" 24 #include "datashare_predicates.h" 25 #include "dir_asset.h" 26 #include "medialibrary_db_const.h" 27 #include "uri.h" 28 #include "values_bucket.h" 29 30 namespace OHOS { 31 namespace Media { 32 enum class OperationObject : uint32_t { 33 UNKNOWN_OBJECT = 0, 34 FILESYSTEM_ASSET, 35 FILESYSTEM_PHOTO, 36 FILESYSTEM_AUDIO, 37 FILESYSTEM_DIR, 38 FILESYSTEM_ALBUM, 39 SMART_ALBUM, 40 SMART_ALBUM_MAP, 41 THUMBNAIL, 42 SMART_ALBUM_ASSETS, 43 ASSETMAP, 44 ALL_DEVICE, 45 ACTIVE_DEVICE, 46 MEDIA_VOLUME, 47 BUNDLE_PERMISSION, 48 PHOTO_ALBUM, 49 PHOTO_MAP, 50 UFM_PHOTO, 51 UFM_AUDIO, 52 UFM_ALBUM, 53 UFM_MAP, 54 PAH_PHOTO, 55 PAH_ALBUM, 56 PAH_MAP, 57 }; 58 59 enum class OperationType : uint32_t { 60 UNKNOWN_TYPE = 0, 61 OPEN, 62 CLOSE, 63 CREATE, 64 DELETE, 65 DELETE_TOOL, 66 UPDATE, 67 QUERY, 68 GETCAPACITY, 69 SCAN, 70 TRASH, 71 GENERATE, 72 AGING, 73 DISTRIBUTE_AGING, 74 COPY, 75 INSERT_PERMISSION, 76 ALBUM_ADD_PHOTOS, 77 ALBUM_REMOVE_PHOTOS, 78 ALBUM_RECOVER_ASSETS, 79 ALBUM_DELETE_ASSETS, // Delete assets permanently from system 80 TRASH_PHOTO, 81 UPDATE_PENDING, 82 SET_USER_COMMENT, 83 INDEX, 84 }; 85 86 class MediaLibraryCommand { 87 public: 88 explicit MediaLibraryCommand(const Uri &uri); 89 MediaLibraryCommand(const Uri &uri, const NativeRdb::ValuesBucket &value); 90 MediaLibraryCommand(const Uri &uri, const OperationType &oprnType); 91 MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 92 MediaLibraryApi api = MediaLibraryApi::API_OLD); 93 MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 94 const NativeRdb::ValuesBucket &value, MediaLibraryApi api = MediaLibraryApi::API_OLD); 95 MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 96 const std::string &networkId, MediaLibraryApi api = MediaLibraryApi::API_OLD); 97 MediaLibraryCommand() = delete; 98 ~MediaLibraryCommand(); 99 MediaLibraryCommand(const MediaLibraryCommand &) = delete; 100 MediaLibraryCommand &operator=(const MediaLibraryCommand &) = delete; 101 MediaLibraryCommand(MediaLibraryCommand &&) = delete; 102 MediaLibraryCommand &operator=(MediaLibraryCommand &&) = delete; 103 104 OperationObject GetOprnObject() const; 105 OperationType GetOprnType() const; 106 const std::string &GetTableName(); 107 NativeRdb::ValuesBucket &GetValueBucket(); 108 NativeRdb::AbsRdbPredicates *GetAbsRdbPredicates(); 109 const std::string &GetOprnFileId(); 110 const std::string &GetOprnDevice(); 111 const Uri &GetUri() const; 112 const std::string &GetBundleName(); 113 const std::string &GetDeviceName(); 114 std::string GetUriStringWithoutSegment() const; 115 MediaLibraryApi GetApi(); 116 std::string GetQuerySetParam(const std::string &key); 117 void SetDataSharePred(const DataShare::DataSharePredicates &pred); 118 const DataShare::DataSharePredicates &GetDataSharePred() const; 119 const std::string &GetResult(); 120 121 void SetOprnObject(OperationObject object); 122 void SetOprnAssetId(const std::string &oprnId); 123 void SetValueBucket(const NativeRdb::ValuesBucket &value); 124 void SetTableName(const std::string &tableName); 125 void SetBundleName(const std::string &bundleName); 126 void SetDeviceName(const std::string &deviceName); 127 void SetResult(const std::string &result); 128 129 private: 130 void SetOprnDevice(const std::string &networkId); 131 void ParseOprnObjectFromUri(); 132 void ParseOprnTypeFromUri(); 133 void ParseTableName(); 134 void InitAbsRdbPredicates(); 135 void ParseFileId(); 136 void ParseQuerySetMapFromUri(); 137 void SetApiFromQuerySetMap(); 138 void ParseOprnObjectFromFileUri(); 139 140 Uri uri_{""}; 141 NativeRdb::ValuesBucket insertValue_; 142 std::unique_ptr<NativeRdb::AbsRdbPredicates> absRdbPredicates_; 143 std::unique_ptr<const DataShare::DataSharePredicates> datasharePred_; 144 OperationObject oprnObject_{OperationObject::UNKNOWN_OBJECT}; 145 OperationType oprnType_{OperationType::UNKNOWN_TYPE}; 146 std::string oprnFileId_; 147 std::string oprnDevice_; 148 std::string tableName_; 149 std::string bundleName_; 150 std::string deviceName_; 151 std::unordered_map<std::string, std::string> querySetMap_; 152 std::string result_; 153 MediaLibraryApi api_; 154 }; 155 } // namespace Media 156 } // namespace OHOS 157 158 #endif // OHOS_MEDIALIBRARY_COMMAND_PARSE_H 159