2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. 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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __BM_SERVER_DB_H__
19 #define __BM_SERVER_DB_H__
23 #include <tzplatform_config.h>
25 #include "bm_private.h"
32 /* THIS DB IS THE DEFAULT DB TO BE USED FOR LOGGING APP BASED USAGE AND RESOURCE BASED USAGE IT WILL BE USED TO STORE PROCESSED VALUE OF THE USAGE, AND WILL BE REFERRED FOR ANSWERING API CALLS */
35 BM_RESOURCE_ID_BLE ==> rId_ble,
38 BM_RESOURCE_ID_DISPLAY,
39 BM_RESOURCE_ID_DEVICE_NETWORK,
40 BM_RESOURCE_ID_GPS_SENSOR,
41 BM_RESOURCE_ID_ID_HRM_SENSOR,
42 BM_RESOURCE_ID_BATTERY,
46 /* Battery Monitor AppId Vs Integer Map */
47 /* TO DO: Cleaning of redundant records from DB */
48 #define APP_ID_MAP_SCHEMA "create table appid_map \n"\
50 "id INTEGER PRIMARY KEY AUTOINCREMENT, "\
54 /* Battery Monitor APPID Vs RESOURCE ID */
55 #define APP_ID_USAGE_SCHEMA "create table appid_usage \n"\
63 "rId_device_network INT, "\
69 /* Battery Monitor RESOURCE ID Vs TIME */
70 /* TO DO: Adding Enum for Resources */
71 #define RESOURCE_ID_USAGE_SCHEMA "create table resourceid_usage \n"\
78 #define GBL_BLE_STAT_SCHEMA "create table gble_stat \n"\
81 "ble_idle_time INT, "\
88 #define GBL_WFL_STAT_SCHEMA "create table gwfl_stat \n"\
92 "wifi_conn_time INT, "\
93 "wifi_idle_time INT, "\
99 #define GBL_NT_STAT_SCHEMA "create table gn_stat \n"\
114 #define GBL_BR_STAT_SCHEMA "create table gbr_stat \n"\
124 #define GBL_SGT_STAT_SCHEMA "create table gsgt_stat \n"\
135 #define GBL_WST_STAT_SCHEMA "create table gwst_stat \n"\
146 #define GBL_BST_STAT_SCHEMA "create table gbst_stat \n"\
155 #define GBL_CPU_STAT_SCHEMA "create table gcpu_stat \n"\
164 /* Macros of Time Duration */
165 #define BM_DURATION_1DAY 86400 /*One Day in Seconds*/
166 #define BM_DURATION_1WEEK 604800 /*One Week(7 Days) in Seconds*/
168 /* #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) */
170 #define BATTERY_MONITOR_APP_ID_MAP_TABLE "appid_map"
171 #define BATTERY_MONITOR_APP_ID_USAGE_TABLE "appid_usage"
172 #define BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE "resourceid_usage"
173 #define BATTERY_MONITOR_GBL_BLE_STAT_TABLE "gble_stat"
174 #define BATTERY_MONITOR_GBL_WFL_STAT_TABLE "gwfl_stat"
175 #define BATTERY_MONITOR_GBL_NT_STAT_TABLE "gn_stat"
176 #define BATTERY_MONITOR_GBL_BR_STAT_TABLE "gbr_stat"
177 #define BATTERY_MONITOR_GBL_SGT_STAT_TABLE "gsgt_stat"
178 #define BATTERY_MONITOR_GBL_WST_STAT_TABLE "gwst_stat"
179 #define BATTERY_MONITOR_GBL_BST_STAT_TABLE "gbst_stat"
180 #define BATTERY_MONITOR_GBL_CPU_STAT_TABLE "gcpu_stat"
181 #define BATTERY_MONITOR_SQLITE_SEQ "sqlite_sequence"
182 #define BATTERY_MONITOR_SQL_LEN_MAX 1024
183 #define BATTERY_MONITOR_TABLE_COUNT 11
185 typedef sqlite3_stmt *bm_stmt;
187 /* Server Functions */
188 int initialize_database(void);
190 int deinitialize_database(void);
192 appid_usage_s *bm_server_query_app_usage_by_appid(const char *app_id, int period_type, int *error_code);
194 appid_usage_s *bm_server_query_app_usage_by_appid_ci(const char *app_id, long long s_time, long long e_time, int *error_code);
196 int bm_server_app_usage_insert_to_db(appid_usage_s *bm_app_type);
198 resourceid_usage_s *bm_server_query_resource_usage_resourceid(const char *resource_id, int period_type, int *error_code);
200 resourceid_usage_s *bm_server_query_resource_usage_resourceid_ci(const char *resource_id, long long s_time, long long e_time, int *error_code);
202 int bm_server_resource_usage_insert_to_db(resourceid_usage_s *bm_resource_type);
204 int bm_server_battery_dump_insert_to_db(void* str_data, int type);
206 int bm_server_battery_dump_query_from_db(void *str_data, int type, long int duration);
208 int bm_server_delete_table_by_appid(const char* app_id);
210 int bm_server_delete_table_by_time_interval(void);
212 int bm_server_appid_insert_to_db(const char* app_id);
214 GSList* bm_server_query_appid_map(int *error_code);
219 #endif /* __BM_SERVER_DB_H__ */