1 /* 2 * Copyright (c) 2021 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 TRACE_DATA_DB_H 17 #define TRACE_DATA_DB_H 18 19 #include <functional> 20 #include <list> 21 #include <string> 22 23 extern "C" { 24 #include "sqlite3.h" 25 } 26 27 namespace SysTuning { 28 namespace TraceStreamer { 29 class TraceDataDB { 30 public: 31 TraceDataDB(); 32 TraceDataDB(const TraceDataDB&) = delete; 33 TraceDataDB& operator=(const TraceDataDB&) = delete; 34 virtual ~TraceDataDB(); 35 virtual void InitDB() = 0; 36 void Prepare(); 37 public: 38 int ExportDatabase(const std::string& outputName); 39 int SearchData(); 40 int OperateDatabase(const std::string& sql); 41 using ResultCallBack = std::function<void(const std::string /* json result */)>; 42 int SearchDatabase(const std::string& sql, ResultCallBack resultCallBack); 43 int SearchDatabase(const std::string& sql, uint8_t* out, int outLen); 44 void AppendNewTable(std::string tableName); 45 void EnableMetaTable(bool enabled); 46 47 public: 48 sqlite3* db_; 49 50 private: 51 void ExecuteSql(const std::string_view& sql); 52 void GetRowString(sqlite3_stmt* stmt, int colCount, std::string& rowStr); 53 std::list<std::string> internalTables_ = {}; 54 bool exportMetaTable_ = false; 55 bool pared_ = false; 56 }; 57 } // namespace TraceStreamer 58 } // namespace SysTuning 59 #endif 60