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 <vector> 21 22 #include "abs_rdb_predicates.h" 23 #include "medialibrary_db_const.h" 24 #include "uri.h" 25 #include "values_bucket.h" 26 27 namespace OHOS { 28 namespace Media { 29 enum class OperationObject : uint32_t { 30 UNKNOWN_OBJECT = 0, 31 FILESYSTEM_ASSET, 32 FILESYSTEM_DIR, 33 FILESYSTEM_ALBUM, 34 SMART_ALBUM, 35 SMART_ALBUM_MAP, 36 THUMBNAIL, 37 SMART_ABLUM_ASSETS, 38 ASSETMAP, 39 ALL_DEVICE, 40 ACTIVE_DEVICE, 41 MEDIA_VOLUME, 42 BUNDLE_PERMISSION, 43 }; 44 45 enum class OperationType : uint32_t { 46 UNKNOWN_TYPE = 0, 47 OPEN, 48 CLOSE, 49 CREATE, 50 DELETE, 51 UPDATE, 52 QUERY, 53 ISDICTIONARY, 54 GETCAPACITY, 55 SCAN, 56 GENERATE, 57 AGING, 58 DISTRIBUTE_AGING, 59 DISTRIBUTE_CREATE, 60 INSERT_PERMISSION, 61 }; 62 63 class MediaLibraryCommand { 64 public: 65 explicit MediaLibraryCommand(const Uri &uri); 66 MediaLibraryCommand(const Uri &uri, const NativeRdb::ValuesBucket &value); 67 MediaLibraryCommand(const Uri &uri, const OperationType &oprnType); 68 MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType); 69 MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 70 const NativeRdb::ValuesBucket &value); 71 MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 72 const std::string &networkId); 73 74 MediaLibraryCommand() = delete; 75 ~MediaLibraryCommand(); 76 MediaLibraryCommand(const MediaLibraryCommand &) = delete; 77 MediaLibraryCommand &operator=(const MediaLibraryCommand &) = delete; 78 MediaLibraryCommand(MediaLibraryCommand &&) = delete; 79 MediaLibraryCommand &operator=(MediaLibraryCommand &&) = delete; 80 81 OperationObject GetOprnObject() const; 82 OperationType GetOprnType() const; 83 const std::string &GetTableName(); 84 NativeRdb::ValuesBucket &GetValueBucket(); 85 NativeRdb::AbsRdbPredicates *GetAbsRdbPredicates(); 86 const std::string &GetOprnFileId(); 87 const std::string &GetOprnDevice(); 88 const Uri &GetUri() const; 89 90 void SetOprnAssetId(const std::string &oprnId); 91 void SetValueBucket(const NativeRdb::ValuesBucket &value); 92 void SetTableName(const std::string &tableName); 93 94 private: 95 void SetOprnObject(const OperationObject &oprnObject); 96 void SetOprnType(const OperationType &oprnType); 97 void SetOprnDevice(const std::string &networkId); 98 void ParseOprnObjectFromUri(); 99 void ParseOprnTypeFromUri(); 100 void ParseTableName(); 101 void InitAbsRdbPredicates(); 102 void ParseFileId(); 103 104 Uri uri_{""}; 105 NativeRdb::ValuesBucket insertValue_; 106 std::unique_ptr<NativeRdb::AbsRdbPredicates> absRdbPredicates_; 107 OperationObject oprnObject_{OperationObject::UNKNOWN_OBJECT}; 108 OperationType oprnType_{OperationType::UNKNOWN_TYPE}; 109 std::string oprnFileId_; 110 std::string oprnDevice_; 111 std::string tableName_; 112 }; 113 } // namespace Media 114 } // namespace OHOS 115 116 #endif // OHOS_MEDIALIBRARY_COMMAND_PARSE_H 117