1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ci#include "animation_table.h" 17fb726d48Sopenharmony_ci 18fb726d48Sopenharmony_ci#include <cmath> 19fb726d48Sopenharmony_ci 20fb726d48Sopenharmony_cinamespace SysTuning { 21fb726d48Sopenharmony_cinamespace TraceStreamer { 22fb726d48Sopenharmony_cienum class Index : int32_t { ID = 0, INPUT_TIME, START_POINT, END_POINT, FRAME_INFO, NAME }; 23fb726d48Sopenharmony_ciAnimationTable::AnimationTable(const TraceDataCache *dataCache) : TableBase(dataCache) 24fb726d48Sopenharmony_ci{ 25fb726d48Sopenharmony_ci tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER")); 26fb726d48Sopenharmony_ci tableColumn_.push_back(TableBase::ColumnInfo("input_time", "INTEGER")); 27fb726d48Sopenharmony_ci tableColumn_.push_back(TableBase::ColumnInfo("start_point", "INTEGER")); 28fb726d48Sopenharmony_ci tableColumn_.push_back(TableBase::ColumnInfo("end_point", "INTEGER")); 29fb726d48Sopenharmony_ci tableColumn_.push_back(TableBase::ColumnInfo("frame_info", "TEXT")); 30fb726d48Sopenharmony_ci tableColumn_.push_back(TableBase::ColumnInfo("name", "TEXT")); 31fb726d48Sopenharmony_ci tablePriKey_.push_back("id"); 32fb726d48Sopenharmony_ci} 33fb726d48Sopenharmony_ci 34fb726d48Sopenharmony_ciAnimationTable::~AnimationTable() {} 35fb726d48Sopenharmony_ci 36fb726d48Sopenharmony_cistd::unique_ptr<TableBase::Cursor> AnimationTable::CreateCursor() 37fb726d48Sopenharmony_ci{ 38fb726d48Sopenharmony_ci return std::make_unique<Cursor>(dataCache_, this); 39fb726d48Sopenharmony_ci} 40fb726d48Sopenharmony_ci 41fb726d48Sopenharmony_ciAnimationTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table) 42fb726d48Sopenharmony_ci : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstAnimation().Size())), 43fb726d48Sopenharmony_ci animationObj_(dataCache->GetConstAnimation()) 44fb726d48Sopenharmony_ci{ 45fb726d48Sopenharmony_ci} 46fb726d48Sopenharmony_ci 47fb726d48Sopenharmony_ciAnimationTable::Cursor::~Cursor() {} 48fb726d48Sopenharmony_ci 49fb726d48Sopenharmony_ciint32_t AnimationTable::Cursor::Column(int32_t col) const 50fb726d48Sopenharmony_ci{ 51fb726d48Sopenharmony_ci switch (static_cast<Index>(col)) { 52fb726d48Sopenharmony_ci case Index::ID: 53fb726d48Sopenharmony_ci sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.IdsData()[CurrentRow()])); 54fb726d48Sopenharmony_ci break; 55fb726d48Sopenharmony_ci case Index::INPUT_TIME: { 56fb726d48Sopenharmony_ci if (animationObj_.InputTimes()[CurrentRow()] != INVALID_TIME) { 57fb726d48Sopenharmony_ci sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.InputTimes()[CurrentRow()])); 58fb726d48Sopenharmony_ci } 59fb726d48Sopenharmony_ci break; 60fb726d48Sopenharmony_ci } 61fb726d48Sopenharmony_ci case Index::START_POINT: { 62fb726d48Sopenharmony_ci if (animationObj_.StartPoints()[CurrentRow()] != INVALID_TIME) { 63fb726d48Sopenharmony_ci sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.StartPoints()[CurrentRow()])); 64fb726d48Sopenharmony_ci } 65fb726d48Sopenharmony_ci break; 66fb726d48Sopenharmony_ci } 67fb726d48Sopenharmony_ci case Index::END_POINT: 68fb726d48Sopenharmony_ci if (animationObj_.EndPoints()[CurrentRow()] != INVALID_TIME) { 69fb726d48Sopenharmony_ci sqlite3_result_int64(context_, static_cast<sqlite3_int64>(animationObj_.EndPoints()[CurrentRow()])); 70fb726d48Sopenharmony_ci } 71fb726d48Sopenharmony_ci break; 72fb726d48Sopenharmony_ci case Index::FRAME_INFO: 73fb726d48Sopenharmony_ci sqlite3_result_text(context_, dataCache_->GetDataFromDict(animationObj_.FrameInfos()[CurrentRow()]).c_str(), 74fb726d48Sopenharmony_ci STR_DEFAULT_LEN, nullptr); 75fb726d48Sopenharmony_ci break; 76fb726d48Sopenharmony_ci case Index::NAME: 77fb726d48Sopenharmony_ci sqlite3_result_text(context_, dataCache_->GetDataFromDict(animationObj_.Names()[CurrentRow()]).c_str(), 78fb726d48Sopenharmony_ci STR_DEFAULT_LEN, nullptr); 79fb726d48Sopenharmony_ci break; 80fb726d48Sopenharmony_ci default: 81fb726d48Sopenharmony_ci TS_LOGF("Unregistered column : %d", col); 82fb726d48Sopenharmony_ci break; 83fb726d48Sopenharmony_ci } 84fb726d48Sopenharmony_ci return SQLITE_OK; 85fb726d48Sopenharmony_ci} 86fb726d48Sopenharmony_ci} // namespace TraceStreamer 87fb726d48Sopenharmony_ci} // namespace SysTuning 88