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", "STRING"));
26 tableColumn_.push_back(TableBase::ColumnInfo("value", "STRING"));
27 tablePriKey_.push_back("name");
28 }
29
~MetaTable()30 MetaTable::~MetaTable() {}
31
CreateCursor()32 void MetaTable::CreateCursor()
33 {
34 cursor_ = std::make_unique<Cursor>(dataCache_);
35 }
36
Cursor(const TraceDataCache * dataCache)37 MetaTable::Cursor::Cursor(const TraceDataCache* dataCache) : TableBase::Cursor(dataCache, 0, METADATA_ITEM_MAX) {}
38
~Cursor()39 MetaTable::Cursor::~Cursor() {}
40
Column(int column) const41 int MetaTable::Cursor::Column(int column) const
42 {
43 switch (column) {
44 case NAMEINDEX:
45 sqlite3_result_text(context_, dataCache_->GetConstMetaData().Name(CurrentRow()).c_str(), STR_DEFAULT_LEN,
46 nullptr);
47 break;
48 case VALUE:
49 sqlite3_result_text(context_, dataCache_->GetConstMetaData().Value(CurrentRow()).c_str(), STR_DEFAULT_LEN,
50 nullptr);
51 break;
52 default:
53 TS_LOGF("Unregistered column : %d", column);
54 break;
55 }
56 return SQLITE_OK;
57 }
58 } // namespace TraceStreamer
59 } // namespace SysTuning
60