1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 #include "trace_config_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, TRACE_SOURCE, KEY, VALUE };
TraceConfigTable(const TraceDataCache * dataCache)21 TraceConfigTable::TraceConfigTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("trace_source", "TEXT"));
25 tableColumn_.push_back(TableBase::ColumnInfo("key", "TEXT"));
26 tableColumn_.push_back(TableBase::ColumnInfo("value", "TEXT"));
27 tablePriKey_.push_back("id");
28 }
29
~TraceConfigTable()30 TraceConfigTable::~TraceConfigTable() {}
31
CreateCursor()32 std::unique_ptr<TableBase::Cursor> TraceConfigTable::CreateCursor()
33 {
34 return std::make_unique<Cursor>(dataCache_, this);
35 }
36
Cursor(const TraceDataCache * dataCache,TableBase * table)37 TraceConfigTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
38 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstTraceConfigData().Size())),
39 TraceConfigData_(dataCache->GetConstTraceConfigData())
40 {
41 }
42
~Cursor()43 TraceConfigTable::Cursor::~Cursor() {}
44
Column(int32_t traceCfgColumn) const45 int32_t TraceConfigTable::Cursor::Column(int32_t traceCfgColumn) const
46 {
47 switch (static_cast<Index>(traceCfgColumn)) {
48 case Index::ID:
49 sqlite3_result_int64(context_, static_cast<sqlite3_int64>(CurrentRow()));
50 break;
51 case Index::TRACE_SOURCE:
52 sqlite3_result_text(context_, dataCache_->GetConstTraceConfigData().TraceSource()[CurrentRow()].c_str(),
53 STR_DEFAULT_LEN, nullptr);
54 break;
55 case Index::KEY:
56 sqlite3_result_text(context_, dataCache_->GetConstTraceConfigData().Key()[CurrentRow()].c_str(),
57 STR_DEFAULT_LEN, nullptr);
58 break;
59 case Index::VALUE:
60 sqlite3_result_text(context_, dataCache_->GetConstTraceConfigData().Value()[CurrentRow()].c_str(),
61 STR_DEFAULT_LEN, nullptr);
62 break;
63 default:
64 TS_LOGF("Unregistered traceCfgColumn : %d", traceCfgColumn);
65 break;
66 }
67 return SQLITE_OK;
68 }
69 } // namespace TraceStreamer
70 } // namespace SysTuning
71