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 "animation_table.h"
17
18 #include <cmath>
19
20 namespace SysTuning {
21 namespace TraceStreamer {
22 enum Index { ID = 0, INPUT_TIME, START_POINT, END_POINT };
AnimationTable(const TraceDataCache * dataCache)23 AnimationTable::AnimationTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("input_time", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("start_point", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("end_point", "INTEGER"));
29 tablePriKey_.push_back("id");
30 }
31
~AnimationTable()32 AnimationTable::~AnimationTable() {}
33
CreateCursor()34 std::unique_ptr<TableBase::Cursor> AnimationTable::CreateCursor()
35 {
36 return std::make_unique<Cursor>(dataCache_, this);
37 }
38
Cursor(const TraceDataCache * dataCache,TableBase * table)39 AnimationTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
40 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstAnimation().Size())),
41 animationObj_(dataCache->GetConstAnimation())
42 {
43 }
44
~Cursor()45 AnimationTable::Cursor::~Cursor() {}
46
Column(int32_t col) const47 int32_t AnimationTable::Cursor::Column(int32_t col) const
48 {
49 switch (col) {
50 case ID:
51 sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.IdsData()[CurrentRow()]));
52 break;
53 case INPUT_TIME: {
54 if (animationObj_.InputTimes()[CurrentRow()] != INVALID_TIME) {
55 sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.InputTimes()[CurrentRow()]));
56 }
57 break;
58 }
59 case START_POINT: {
60 if (animationObj_.StartPoints()[CurrentRow()] != INVALID_TIME) {
61 sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.StartPoints()[CurrentRow()]));
62 }
63 break;
64 }
65 case END_POINT:
66 if (animationObj_.EndPoints()[CurrentRow()] != INVALID_TIME) {
67 sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.EndPoints()[CurrentRow()]));
68 }
69 break;
70 default:
71 TS_LOGF("Unregistered column : %d", col);
72 break;
73 }
74 return SQLITE_OK;
75 }
76 } // namespace TraceStreamer
77 } // namespace SysTuning
78