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 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 "store_manager.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 class EventDbHelper { 29 public: 30 EventDbHelper(const std::string workPath); 31 ~EventDbHelper(); 32 int InsertPluginStatsEvent(const std::shared_ptr<LoggerEvent>& event); 33 int InsertSysUsageEvent(const std::shared_ptr<LoggerEvent>& event, const std::string& coll); 34 int QueryPluginStatsEvent(std::vector<std::shared_ptr<LoggerEvent>>& events, const std::string& pluginName = ""); 35 int QuerySysUsageEvent(std::vector<std::shared_ptr<LoggerEvent>>& events, const std::string& coll); 36 int DeletePluginStatsEvent(); 37 int DeleteSysUsageEvent(const std::string& coll); 38 39 private: 40 void InitDbPath(); 41 void InitDbStoreMgr(); 42 std::shared_ptr<DocStore> GetDocStore(); 43 int CloseDocStore(); 44 int InsertDb(const std::string& jsonStr, const std::string& coll); 45 void BuildQuery(DataQuery& query, const std::map<std::string, std::string>& condMap = {}); 46 int QueryDb(const DataQuery& query, std::vector<Entry>& entries, const std::string& coll); 47 int UpdateDb(int id, const std::string& value, const std::string& coll); 48 int DeleteDb(const DataQuery& query, const std::string& coll); 49 50 private: 51 std::string dbPath_; 52 std::unique_ptr<StoreManager> storeMgr_; 53 }; 54 } // namespace HiviewDFX 55 } // namespace OHOS 56 #endif // HIVIEW_PLUGINS_USAGE_EVENT_REPORT_SREVICE_EVENT_DB_HELPER_H 57