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 "medialibrary_operation.h" 28 #include "uri.h" 29 #include "values_bucket.h" 30 31 namespace OHOS { 32 namespace Media { 33 #define EXPORT __attribute__ ((visibility ("default"))) 34 class MediaLibraryCommand { 35 public: 36 EXPORT explicit MediaLibraryCommand(const Uri &uri); 37 EXPORT MediaLibraryCommand(const Uri &uri, const NativeRdb::ValuesBucket &value); 38 EXPORT MediaLibraryCommand(const Uri &uri, const OperationType &oprnType); 39 EXPORT MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 40 MediaLibraryApi api = MediaLibraryApi::API_OLD); 41 EXPORT MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 42 const NativeRdb::ValuesBucket &value, MediaLibraryApi api = MediaLibraryApi::API_OLD); 43 EXPORT MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType, 44 const std::string &networkId, MediaLibraryApi api = MediaLibraryApi::API_OLD); 45 EXPORT MediaLibraryCommand() = delete; 46 EXPORT ~MediaLibraryCommand(); 47 EXPORT MediaLibraryCommand(const MediaLibraryCommand &) = delete; 48 EXPORT MediaLibraryCommand &operator=(const MediaLibraryCommand &) = delete; 49 EXPORT MediaLibraryCommand(MediaLibraryCommand &&) = delete; 50 EXPORT MediaLibraryCommand &operator=(MediaLibraryCommand &&) = delete; 51 52 EXPORT OperationObject GetOprnObject() const; 53 EXPORT OperationType GetOprnType() const; 54 EXPORT const std::string &GetTableName(); 55 EXPORT NativeRdb::ValuesBucket &GetValueBucket(); 56 EXPORT NativeRdb::AbsRdbPredicates *GetAbsRdbPredicates(); 57 EXPORT const std::string &GetOprnFileId(); 58 EXPORT const std::string &GetOprnDevice(); 59 EXPORT const Uri &GetUri() const; 60 EXPORT const std::string &GetBundleName(); 61 EXPORT const std::string &GetDeviceName(); 62 EXPORT std::string GetUriStringWithoutSegment() const; 63 EXPORT MediaLibraryApi GetApi(); 64 EXPORT std::string GetQuerySetParam(const std::string &key); 65 EXPORT void SetDataSharePred(const DataShare::DataSharePredicates &pred); 66 EXPORT const DataShare::DataSharePredicates &GetDataSharePred() const; 67 EXPORT const std::string &GetResult(); 68 69 EXPORT void SetOprnObject(OperationObject object); 70 EXPORT void SetOprnAssetId(const std::string &oprnId); 71 EXPORT void SetValueBucket(const NativeRdb::ValuesBucket &value); 72 EXPORT void SetTableName(const std::string &tableName); 73 EXPORT void SetBundleName(const std::string &bundleName); 74 EXPORT void SetDeviceName(const std::string &deviceName); 75 EXPORT void SetResult(const std::string &result); 76 EXPORT bool IsDataSharePredNull() const; 77 78 private: 79 void ParseOprnObjectFromUri(); 80 void ParseOprnTypeFromUri(); 81 void ParseTableName(); 82 void InitAbsRdbPredicates(); 83 void ParseFileId(); 84 void ParseQuerySetMapFromUri(); 85 void SetApiFromQuerySetMap(); 86 void ParseOprnObjectFromFileUri(); 87 88 Uri uri_ {""}; 89 NativeRdb::ValuesBucket insertValue_; 90 std::unique_ptr<NativeRdb::AbsRdbPredicates> absRdbPredicates_; 91 std::unique_ptr<const DataShare::DataSharePredicates> datasharePred_; 92 OperationObject oprnObject_ {OperationObject::UNKNOWN_OBJECT}; 93 OperationType oprnType_ {OperationType::UNKNOWN_TYPE}; 94 std::string oprnFileId_; 95 std::string oprnDevice_; 96 std::string tableName_; 97 std::string bundleName_; 98 std::string deviceName_; 99 std::unordered_map<std::string, std::string> querySetMap_; 100 std::string result_ = ""; 101 MediaLibraryApi api_; 102 }; 103 104 } // namespace Media 105 } // namespace OHOS 106 107 #endif // OHOS_MEDIALIBRARY_COMMAND_PARSE_H 108