1
2 /*
3 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "device_state_table.h"
18
19 namespace SysTuning {
20 namespace TraceStreamer {
21 enum class Index : int32_t {
22 ID = 0,
23 BRIGHTNESS,
24 BT_STATE,
25 LOCATION,
26 WIFI,
27 STREAM_DEFAULT,
28 VOICE_CALL,
29 MUSIC,
30 STREAM_RING,
31 MEDIA,
32 VOICE_ASSISTANT,
33 SYSTEM,
34 ALARM,
35 NOTIFICATION,
36 BT_SCO,
37 ENFORCED_AUDIBLE,
38 STREAM_DTMF,
39 STREAM_TTS,
40 ACCESSIBILITY,
41 RECORDING,
42 STREAM_ALL
43 };
DeviceStateTable(const TraceDataCache *dataCache)44 DeviceStateTable::DeviceStateTable(const TraceDataCache *dataCache) : TableBase(dataCache)
45 {
46 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
47 tableColumn_.push_back(TableBase::ColumnInfo("brightness", "INTEGER"));
48 tableColumn_.push_back(TableBase::ColumnInfo("bt_state", "INTEGER"));
49 tableColumn_.push_back(TableBase::ColumnInfo("location", "INTEGER"));
50 tableColumn_.push_back(TableBase::ColumnInfo("wifi", "INTEGER"));
51 tableColumn_.push_back(TableBase::ColumnInfo("stream_default", "INTEGER"));
52 tableColumn_.push_back(TableBase::ColumnInfo("voice_call", "INTEGER"));
53 tableColumn_.push_back(TableBase::ColumnInfo("music", "INTEGER"));
54 tableColumn_.push_back(TableBase::ColumnInfo("stream_ring", "INTEGER"));
55 tableColumn_.push_back(TableBase::ColumnInfo("media", "INTEGER"));
56 tableColumn_.push_back(TableBase::ColumnInfo("voice_assistant", "INTEGER"));
57 tableColumn_.push_back(TableBase::ColumnInfo("system", "INTEGER"));
58 tableColumn_.push_back(TableBase::ColumnInfo("alarm", "INTEGER"));
59 tableColumn_.push_back(TableBase::ColumnInfo("notification", "INTEGER"));
60 tableColumn_.push_back(TableBase::ColumnInfo("bt_sco", "INTEGER"));
61 tableColumn_.push_back(TableBase::ColumnInfo("enforced_audible", "INTEGER"));
62 tableColumn_.push_back(TableBase::ColumnInfo("stream_dtmf", "INTEGER"));
63 tableColumn_.push_back(TableBase::ColumnInfo("stream_tts", "INTEGER"));
64 tableColumn_.push_back(TableBase::ColumnInfo("accessibility", "INTEGER"));
65 tableColumn_.push_back(TableBase::ColumnInfo("recording", "INTEGER"));
66 tableColumn_.push_back(TableBase::ColumnInfo("stream_all", "INTEGER"));
67 tablePriKey_.push_back("id");
68 }
69
~DeviceStateTable()70 DeviceStateTable::~DeviceStateTable() {}
71
CreateCursor()72 std::unique_ptr<TableBase::Cursor> DeviceStateTable::CreateCursor()
73 {
74 return std::make_unique<Cursor>(dataCache_, this);
75 }
76
Cursor(const TraceDataCache *dataCache, TableBase *table)77 DeviceStateTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
78 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstHiSysEventDeviceStateData().Size())),
79 deviceStateData_(dataCache->GetConstHiSysEventDeviceStateData())
80 {
81 }
82
~Cursor()83 DeviceStateTable::Cursor::~Cursor() {}
84
Column(int32_t column) const85 int32_t DeviceStateTable::Cursor::Column(int32_t column) const
86 {
87 switch (static_cast<Index>(column)) {
88 case Index::ID:
89 sqlite3_result_int64(context_, deviceStateData_.IdsData()[CurrentRow()]);
90 break;
91 case Index::BRIGHTNESS:
92 sqlite3_result_int(context_, deviceStateData_.Brightness()[CurrentRow()]);
93 break;
94 case Index::BT_STATE:
95 sqlite3_result_int(context_, deviceStateData_.BtState()[CurrentRow()]);
96 break;
97 case Index::LOCATION:
98 sqlite3_result_int(context_, deviceStateData_.Location()[CurrentRow()]);
99 break;
100 case Index::WIFI:
101 sqlite3_result_int(context_, deviceStateData_.Wifi()[CurrentRow()]);
102 break;
103 case Index::STREAM_DEFAULT:
104 sqlite3_result_int(context_, deviceStateData_.StreamDefault()[CurrentRow()]);
105 break;
106 case Index::VOICE_CALL:
107 sqlite3_result_int(context_, deviceStateData_.VoiceCall()[CurrentRow()]);
108 break;
109 case Index::MUSIC:
110 sqlite3_result_int(context_, deviceStateData_.Music()[CurrentRow()]);
111 break;
112 case Index::STREAM_RING:
113 sqlite3_result_int(context_, deviceStateData_.StreamRing()[CurrentRow()]);
114 break;
115 case Index::MEDIA:
116 sqlite3_result_int(context_, deviceStateData_.Media()[CurrentRow()]);
117 break;
118 case Index::VOICE_ASSISTANT:
119 sqlite3_result_int(context_, deviceStateData_.VoiceAssistant()[CurrentRow()]);
120 break;
121 case Index::SYSTEM:
122 sqlite3_result_int(context_, deviceStateData_.System()[CurrentRow()]);
123 break;
124 default:
125 HandleTypeColumns(column);
126 }
127 return SQLITE_OK;
128 }
HandleTypeColumns(int32_t column) const129 void DeviceStateTable::Cursor::HandleTypeColumns(int32_t column) const
130 {
131 switch (static_cast<Index>(column)) {
132 case Index::ALARM:
133 sqlite3_result_int(context_, deviceStateData_.Alarm()[CurrentRow()]);
134 break;
135 case Index::NOTIFICATION:
136 sqlite3_result_int(context_, deviceStateData_.Notification()[CurrentRow()]);
137 break;
138 case Index::BT_SCO:
139 sqlite3_result_int(context_, deviceStateData_.BtSco()[CurrentRow()]);
140 break;
141 case Index::ENFORCED_AUDIBLE:
142 sqlite3_result_int(context_, deviceStateData_.EnforcedAudible()[CurrentRow()]);
143 break;
144 case Index::STREAM_DTMF:
145 sqlite3_result_int(context_, deviceStateData_.StreamDtmf()[CurrentRow()]);
146 break;
147 case Index::STREAM_TTS:
148 sqlite3_result_int(context_, deviceStateData_.StreamTts()[CurrentRow()]);
149 break;
150 case Index::ACCESSIBILITY:
151 sqlite3_result_int(context_, deviceStateData_.Accessibility()[CurrentRow()]);
152 break;
153 case Index::RECORDING:
154 sqlite3_result_int(context_, deviceStateData_.Recordings()[CurrentRow()]);
155 break;
156 case Index::STREAM_ALL:
157 sqlite3_result_int(context_, deviceStateData_.StreamAll()[CurrentRow()]);
158 break;
159 default:
160 TS_LOGF("Unregistered column : %d", column);
161 break;
162 }
163 }
164 } // namespace TraceStreamer
165 } // namespace SysTuning
166