1 /* 2 * Copyright (C) 2024 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 RINGTONE_SCANNER_DB_H 17 #define RINGTONE_SCANNER_DB_H 18 19 #include "result_set.h" 20 #include "ringtone_data_command.h" 21 #include "ringtone_metadata.h" 22 23 namespace OHOS { 24 namespace Media { 25 #define EXPORT __attribute__ ((visibility ("default"))) 26 class RingtoneScannerDb { 27 public: 28 EXPORT RingtoneScannerDb() = default; 29 EXPORT RingtoneScannerDb(RingtoneScannerDb &other) = delete; 30 EXPORT void operator=(const RingtoneScannerDb &) = delete; 31 EXPORT ~RingtoneScannerDb() = default; 32 33 EXPORT static int32_t InsertMetadata(const RingtoneMetadata &metadata, std::string &tableName); 34 EXPORT static int32_t UpdateMetadata(const RingtoneMetadata &metadata, std::string &tableName); 35 EXPORT static int32_t GetFileBasicInfo(const std::string &path, std::unique_ptr<RingtoneMetadata> &ptr); 36 EXPORT static int32_t UpdateRingtoneRdb(NativeRdb::ValuesBucket &values, std::string &whereClause, 37 std::vector<std::string> &whereArgs); 38 EXPORT static int32_t QueryRingtoneRdb(std::string &whereClause, std::vector<std::string> &whereArgs, 39 const std::vector<std::string> &columns, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 40 EXPORT static int32_t FillMetadata(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 41 std::unique_ptr<RingtoneMetadata> &ptr); 42 private: 43 static bool InsertData(const NativeRdb::ValuesBucket values, const std::string &tableName, int64_t &rowNum); 44 static int32_t GetFileSet(RingtoneDataCommand &cmd, const std::vector<std::string> &columns, 45 std::shared_ptr<NativeRdb::ResultSet> &resultSet); 46 static void ExtractMetaFromColumn(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 47 std::unique_ptr<RingtoneMetadata> &metadata, const std::string &col); 48 static int32_t BuildToneSettingTypeQuery(ToneSettingType type, RingtoneDataCommand &cmd); 49 static int32_t GetToneSettingType(ToneSettingType type, std::vector<std::shared_ptr<RingtoneMetadata>> &metas); 50 }; 51 } // namespace Media 52 } // namespace OHOS 53 #endif // RINGTONE_SCANNER_DB_H 54