• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "device_state_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index {
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 };
44 }
DeviceStateTable(const TraceDataCache * dataCache)45 DeviceStateTable::DeviceStateTable(const TraceDataCache* dataCache) : TableBase(dataCache)
46 {
47     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
48     tableColumn_.push_back(TableBase::ColumnInfo("brightness", "INTEGER"));
49     tableColumn_.push_back(TableBase::ColumnInfo("bt_state", "INTEGER"));
50     tableColumn_.push_back(TableBase::ColumnInfo("location", "INTEGER"));
51     tableColumn_.push_back(TableBase::ColumnInfo("wifi", "INTEGER"));
52     tableColumn_.push_back(TableBase::ColumnInfo("stream_default", "INTEGER"));
53     tableColumn_.push_back(TableBase::ColumnInfo("voice_call", "INTEGER"));
54     tableColumn_.push_back(TableBase::ColumnInfo("music", "INTEGER"));
55     tableColumn_.push_back(TableBase::ColumnInfo("stream_ring", "INTEGER"));
56     tableColumn_.push_back(TableBase::ColumnInfo("media", "INTEGER"));
57     tableColumn_.push_back(TableBase::ColumnInfo("voice_assistant", "INTEGER"));
58     tableColumn_.push_back(TableBase::ColumnInfo("system", "INTEGER"));
59     tableColumn_.push_back(TableBase::ColumnInfo("alarm", "INTEGER"));
60     tableColumn_.push_back(TableBase::ColumnInfo("notification", "INTEGER"));
61     tableColumn_.push_back(TableBase::ColumnInfo("bt_sco", "INTEGER"));
62     tableColumn_.push_back(TableBase::ColumnInfo("enforced_audible", "INTEGER"));
63     tableColumn_.push_back(TableBase::ColumnInfo("stream_dtmf", "INTEGER"));
64     tableColumn_.push_back(TableBase::ColumnInfo("stream_tts", "INTEGER"));
65     tableColumn_.push_back(TableBase::ColumnInfo("accessibility", "INTEGER"));
66     tableColumn_.push_back(TableBase::ColumnInfo("recording", "INTEGER"));
67     tableColumn_.push_back(TableBase::ColumnInfo("stream_all", "INTEGER"));
68     tablePriKey_.push_back("id");
69 }
70 
~DeviceStateTable()71 DeviceStateTable::~DeviceStateTable() {}
72 
CreateCursor()73 std::unique_ptr<TableBase::Cursor> DeviceStateTable::CreateCursor()
74 {
75     return std::make_unique<Cursor>(dataCache_, this);
76 }
77 
Cursor(const TraceDataCache * dataCache,TableBase * table)78 DeviceStateTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
79     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstDeviceStateData().Size())),
80       deviceStateData_(dataCache->GetConstDeviceStateData())
81 {
82 }
83 
~Cursor()84 DeviceStateTable::Cursor::~Cursor() {}
85 
Column(int column) const86 int DeviceStateTable::Cursor::Column(int column) const
87 {
88     switch (column) {
89         case ID:
90             sqlite3_result_int64(context_, dataCache_->GetConstDeviceStateData().IdsData()[CurrentRow()]);
91             break;
92         case BRIGHTNESS:
93             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Brightness()[CurrentRow()]);
94             break;
95         case BT_STATE:
96             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().BtState()[CurrentRow()]);
97             break;
98         case LOCATION:
99             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Location()[CurrentRow()]);
100             break;
101         case WIFI:
102             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Wifi()[CurrentRow()]);
103             break;
104         case STREAM_DEFAULT:
105             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().StreamDefault()[CurrentRow()]);
106             break;
107         case VOICE_CALL:
108             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().VoiceCall()[CurrentRow()]);
109             break;
110         case MUSIC:
111             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Music()[CurrentRow()]);
112             break;
113         case STREAM_RING:
114             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().StreamRing()[CurrentRow()]);
115             break;
116         case MEDIA:
117             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Media()[CurrentRow()]);
118             break;
119         case VOICE_ASSISTANT:
120             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().VoiceAssistant()[CurrentRow()]);
121             break;
122         case SYSTEM:
123             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().System()[CurrentRow()]);
124             break;
125         case ALARM:
126             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Alarm()[CurrentRow()]);
127             break;
128         case NOTIFICATION:
129             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Notification()[CurrentRow()]);
130             break;
131         case BT_SCO:
132             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().BtSco()[CurrentRow()]);
133             break;
134         case ENFORCED_AUDIBLE:
135             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().EnforcedAudible()[CurrentRow()]);
136             break;
137         case STREAM_DTMF:
138             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().StreamDtmf()[CurrentRow()]);
139             break;
140         case STREAM_TTS:
141             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().StreamTts()[CurrentRow()]);
142             break;
143         case ACCESSIBILITY:
144             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Accessibility()[CurrentRow()]);
145             break;
146         case RECORDING:
147             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().Recording()[CurrentRow()]);
148             break;
149         case STREAM_ALL:
150             sqlite3_result_int(context_, dataCache_->GetConstDeviceStateData().StreamAll()[CurrentRow()]);
151             break;
152         default:
153             TS_LOGF("Unregistered column : %d", column);
154             break;
155     }
156     return SQLITE_OK;
157 }
158 } // namespace TraceStreamer
159 } // namespace SysTuning
160