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 "datasource_clockid_table.h"
17 #include <cmath>
18
19 namespace SysTuning {
20 namespace TraceStreamer {
21 enum class Index : int32_t { ID = 0, NAME, CLOCK_ID };
DataSourceClockIdTableTable(const TraceDataCache * dataCache)22 DataSourceClockIdTableTable::DataSourceClockIdTableTable(const TraceDataCache* dataCache) : TableBase(dataCache)
23 {
24 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("data_source_name", "TEXT"));
26 tableColumn_.push_back(TableBase::ColumnInfo("clock_id", "INTEGER"));
27 tablePriKey_.push_back("id");
28 }
29
~DataSourceClockIdTableTable()30 DataSourceClockIdTableTable::~DataSourceClockIdTableTable() {}
31
CreateCursor()32 std::unique_ptr<TableBase::Cursor> DataSourceClockIdTableTable::CreateCursor()
33 {
34 return std::make_unique<Cursor>(dataCache_, this);
35 }
36
Cursor(const TraceDataCache * dataCache,TableBase * table)37 DataSourceClockIdTableTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
38 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstDataSourceClockIdData().Size())),
39 dataSourceClockIdData_(dataCache->GetConstDataSourceClockIdData())
40 {
41 }
42
~Cursor()43 DataSourceClockIdTableTable::Cursor::~Cursor() {}
44
Column(int32_t column) const45 int32_t DataSourceClockIdTableTable::Cursor::Column(int32_t column) const
46 {
47 switch (static_cast<Index>(column)) {
48 case Index::ID:
49 sqlite3_result_int64(context_, CurrentRow());
50 break;
51 case Index::NAME:
52 sqlite3_result_text(context_, dataSourceClockIdData_.Names()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
53 nullptr);
54 break;
55 case Index::CLOCK_ID:
56 sqlite3_result_int(context_, static_cast<int64_t>(dataSourceClockIdData_.ClockIds()[CurrentRow()]));
57 break;
58 default:
59 TS_LOGF("Unregistered column : %d", column);
60 break;
61 }
62 return SQLITE_OK;
63 }
64 } // namespace TraceStreamer
65 } // namespace SysTuning
66