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 "device_info_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { PHYSICAL_WIDTH = 0, PHYSICAL_HEIGHT, PHYSICAL_FRAME_RATE };
DeviceInfoTable(const TraceDataCache * dataCache)21 DeviceInfoTable::DeviceInfoTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("physical_width", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("physical_height", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("physical_frame_rate", "INTEGER"));
26 tablePriKey_.push_back("physical_width");
27 }
28
~DeviceInfoTable()29 DeviceInfoTable::~DeviceInfoTable() {}
30
CreateCursor()31 std::unique_ptr<TableBase::Cursor> DeviceInfoTable::CreateCursor()
32 {
33 return std::make_unique<Cursor>(dataCache_, this);
34 }
35
Cursor(const TraceDataCache * dataCache,TableBase * table)36 DeviceInfoTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
37 : TableBase::Cursor(dataCache, table, 1), deviceInfoObj_(dataCache->GetConstDeviceInfo())
38 {
39 }
40
~Cursor()41 DeviceInfoTable::Cursor::~Cursor() {}
42
Column(int32_t devInfoColumn) const43 int32_t DeviceInfoTable::Cursor::Column(int32_t devInfoColumn) const
44 {
45 switch (static_cast<Index>(devInfoColumn)) {
46 case Index::PHYSICAL_WIDTH:
47 if (deviceInfoObj_.PhysicalWidth() != INVALID_UINT32) {
48 sqlite3_result_int(context_, static_cast<int32_t>(deviceInfoObj_.PhysicalWidth()));
49 }
50 break;
51 case Index::PHYSICAL_HEIGHT:
52 if (deviceInfoObj_.PhysicalHeight() != INVALID_UINT32) {
53 sqlite3_result_int(context_, static_cast<int32_t>(deviceInfoObj_.PhysicalHeight()));
54 }
55 break;
56 case Index::PHYSICAL_FRAME_RATE:
57 if (deviceInfoObj_.PhysicalFrameRate() != INVALID_UINT32) {
58 sqlite3_result_int(context_, static_cast<int32_t>(deviceInfoObj_.PhysicalFrameRate()));
59 }
60 break;
61 default:
62 TS_LOGF("Unregistered devInfoColumn : %d", devInfoColumn);
63 break;
64 }
65 return SQLITE_OK;
66 }
67 } // namespace TraceStreamer
68 } // namespace SysTuning
69