1 /* 2 * Copyright (c) 2022-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 HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_EVENT_DB_HELPER_H 17 #define HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_EVENT_DB_HELPER_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 23 #include "logger_event.h" 24 #include "rdb_store.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 class EventDbHelper { 29 public: 30 EventDbHelper(const std::string workPath); 31 ~EventDbHelper(); 32 int InsertPluginStatsEvent(std::shared_ptr<LoggerEvent> event); 33 int InsertSysUsageEvent(std::shared_ptr<LoggerEvent> event, const std::string& table); 34 int QueryPluginStatsEvent(std::vector<std::shared_ptr<LoggerEvent>>& events, const std::string& pluginName = ""); 35 int QuerySysUsageEvent(std::shared_ptr<LoggerEvent>& events, const std::string& table); 36 int DeletePluginStatsEvent(); 37 int DeleteSysUsageEvent(const std::string& table); 38 39 private: 40 void InitDbStore(); 41 int CreateTable(const std::string& table, const std::vector<std::pair<std::string, std::string>>& fields); 42 int CreatePluginStatsTable(const std::string& table); 43 int CreateSysUsageTable(const std::string& table); 44 int InsertPluginStatsTable(const std::string& pluginName, const std::string& eventStr); 45 int InsertSysUsageTable(const std::string& table, const std::string& eventStr); 46 int UpdatePluginStatsTable(const std::string& pluginName, const std::string& eventStr); 47 int UpdateSysUsageTable(const std::string& table, const std::string& eventStr); 48 int QueryPluginStatsTable(std::vector<std::string>& eventStrs, const std::string& pluginName); 49 int QuerySysUsageTable(std::string& eventStr, const std::string& table); 50 int QueryDb(std::vector<std::string>& eventStrs, const std::string& table, 51 const std::vector<std::pair<std::string, std::string>>& queryConds); 52 int DeleteTableData(const std::string& table); 53 54 private: 55 std::string dbPath_; 56 std::shared_ptr<NativeRdb::RdbStore> rdbStore_; 57 }; 58 } // namespace HiviewDFX 59 } // namespace OHOS 60 #endif // HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_EVENT_DB_HELPER_H 61