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 "appname_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { ID = 0, FLAG, APP_NAME, APP_KEY };
22 }
AppnameTable(const TraceDataCache * dataCache)23 AppnameTable:: AppnameTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("flag", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("app_name", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("app_key", "INTEGER"));
29 tablePriKey_.push_back("id");
30 }
31
~AppnameTable()32 AppnameTable::~AppnameTable() {}
33
CreateCursor()34 std::unique_ptr<TableBase::Cursor> AppnameTable::CreateCursor()
35 {
36 return std::make_unique<Cursor>(dataCache_, this);
37 }
38
Cursor(const TraceDataCache * dataCache,TableBase * table)39 AppnameTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
40 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstAppNamesData().Size())),
41 appName_(dataCache->GetConstAppNamesData())
42 {
43 }
44
~Cursor()45 AppnameTable::Cursor::~Cursor() {}
46
Column(int column) const47 int AppnameTable::Cursor::Column(int column) const
48 {
49 switch (column) {
50 case ID:
51 sqlite3_result_int64(context_, dataCache_->GetConstAppNamesData().IdsData()[CurrentRow()]);
52 break;
53 case FLAG:
54 sqlite3_result_int(context_, dataCache_->GetConstAppNamesData().Falgs()[CurrentRow()]);
55 break;
56 case APP_NAME:
57 sqlite3_result_int64(context_, dataCache_->GetConstAppNamesData().EventSourceId()[CurrentRow()]);
58 break;
59 case APP_KEY:
60 sqlite3_result_int64(context_, dataCache_->GetConstAppNamesData().AppName()[CurrentRow()]);
61 break;
62 default:
63 TS_LOGF("Unregistered column : %d", column);
64 break;
65 }
66 return SQLITE_OK;
67 }
68 } // namespace TraceStreamer
69 } // namespace SysTuning
70