• 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 "demo_meta_table.h"
17 #include "trace_stdtype.h"
18 
19 namespace SysTuning {
20 namespace TraceStreamer {
21 enum class Index : int32_t { NAMEINDEX = 0, VALUE };
DemoMetaTable(const TraceDataCache * dataCache)22 DemoMetaTable::DemoMetaTable(const TraceDataCache *dataCache) : DemoTableBase(dataCache)
23 {
24     demoTableColumn_.push_back(DemoTableBase::ColumnInfo("name", "TEXT"));
25     demoTableColumn_.push_back(DemoTableBase::ColumnInfo("value", "TEXT"));
26     demoTablePriKey_.push_back("name");
27 }
28 
~DemoMetaTable()29 DemoMetaTable::~DemoMetaTable() {}
30 
CreateCursor()31 std::unique_ptr<DemoTableBase::Cursor> DemoMetaTable::CreateCursor()
32 {
33     return std::make_unique<Cursor>(demoTraceDataCache_, this);
34 }
35 
Cursor(const TraceDataCache * dataCache,DemoTableBase * table)36 DemoMetaTable::Cursor::Cursor(const TraceDataCache *dataCache, DemoTableBase *table)
37     : DemoTableBase::Cursor(dataCache, table, MetaDataItem::METADATA_ITEM_MAX)
38 {
39 }
40 
~Cursor()41 DemoMetaTable::Cursor::~Cursor() {}
42 
Column(int32_t demoMetaColumn) const43 int32_t DemoMetaTable::Cursor::Column(int32_t demoMetaColumn) const
44 {
45     switch (static_cast<Index>(demoMetaColumn)) {
46         case Index::NAMEINDEX:
47             sqlite3_result_text(demoContext_, demoDataCache_->GetConstMetaData().Name(CurrentRow()).c_str(),
48                                 STR_DEFAULT_LEN, nullptr);
49             break;
50         case Index::VALUE:
51             sqlite3_result_text(demoContext_, demoDataCache_->GetConstMetaData().Value(CurrentRow()).c_str(),
52                                 STR_DEFAULT_LEN, nullptr);
53             break;
54         default:
55             TS_LOGF("Unregistered demoMetaColumn : %d", demoMetaColumn);
56             break;
57     }
58     return SQLITE_OK;
59 }
60 } // namespace TraceStreamer
61 } // namespace SysTuning
62