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