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 #include "meta_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { NAMEINDEX = 0, VALUE };
22 }
MetaTable(const TraceDataCache * dataCache)23 MetaTable::MetaTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("name", "TEXT"));
26 tableColumn_.push_back(TableBase::ColumnInfo("value", "TEXT"));
27 tablePriKey_.push_back("name");
28 }
29
~MetaTable()30 MetaTable::~MetaTable() {}
31
CreateCursor()32 std::unique_ptr<TableBase::Cursor> MetaTable::CreateCursor()
33 {
34 return std::make_unique<Cursor>(dataCache_, this);
35 }
36
Cursor(const TraceDataCache * dataCache,TableBase * table)37 MetaTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
38 : TableBase::Cursor(dataCache, table, METADATA_ITEM_MAX)
39 {
40 }
41
~Cursor()42 MetaTable::Cursor::~Cursor() {}
43
Column(int column) const44 int MetaTable::Cursor::Column(int column) const
45 {
46 switch (column) {
47 case NAMEINDEX:
48 sqlite3_result_text(context_, dataCache_->GetConstMetaData().Name(CurrentRow()).c_str(), STR_DEFAULT_LEN,
49 nullptr);
50 break;
51 case VALUE:
52 sqlite3_result_text(context_, dataCache_->GetConstMetaData().Value(CurrentRow()).c_str(), STR_DEFAULT_LEN,
53 nullptr);
54 break;
55 default:
56 TS_LOGF("Unregistered column : %d", column);
57 break;
58 }
59 return SQLITE_OK;
60 }
61 } // namespace TraceStreamer
62 } // namespace SysTuning
63