#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
#include <sys/stat.h>
#include <glib.h>
#include <db-util.h>
return count;
}
-static int bm_query_app_usage_convert_to_sql(const char *str, long s_t, bm_stmt hstmt)
-{
- ENTER;
-
- int count = 1;
- bm_query_bind_text(hstmt, count++, str);
- bm_query_bind_int(hstmt, count++, s_t);
-
- EXIT;
- return count;
-}
-
static int bm_appid_map_usage_convert_to_sql(const char* app_id, bm_stmt hstmt, char *sql_value)
{
ENTER;
return NULL;
}
-static appid_usage_s* bm_query_usage_by_appid(sqlite3 *bm_db_handle, const char *app_id, int *error_code, int period_type)
-{
- ENTER;
-
- long int duration = 0;
- duration = bm_get_time_bias(period_type);
- if (duration == 0) {
- _ERR("Invalid period_type [%d]", period_type);
- return NULL;
- }
- _DBG("Value for duration is [%ld]", duration);
-
- bm_stmt hstmt = NULL;
- char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
- int rc = 0;
- *error_code = BATTERY_MONITOR_ERROR_NONE;
-
- BM_RETURN_VAL((app_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; },
- NULL, ("APP ID IS NULL"));
- BM_RETURN_VAL((bm_db_handle != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; },
- NULL, ("The database isn't connected."));
- BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
-
- BM_SNPRINTF(query, sizeof(query), "SELECT AppId, sum(rId_ble), sum(rId_wifi), sum(rId_cpu), \
- sum(rId_display), sum(rId_device_network), sum(rId_gps) FROM %s WHERE \
- AppId = ? AND log_time >= ?", BATTERY_MONITOR_APP_ID_USAGE_TABLE);
-
- hstmt = bm_prepare_query(bm_db_handle, query);
- if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
- _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
- *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
- return NULL;
- }
-
- bm_query_app_usage_convert_to_sql(app_id, duration, hstmt);
- appid_usage_s *bm_app_type = NULL;
- rc = bm_query_step(hstmt);
- BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND,
- ("The record isn't found.(%s)\n", app_id));
-
- bm_app_type = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
- if (bm_app_type == NULL) {
- _ERR("memory allocation failed");
- if (hstmt != NULL) {
- rc = bm_query_finalize(hstmt);
- BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), { *error_code = rc; },
- NULL, ("finalize error"));
- hstmt = NULL;
- }
- *error_code = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bm_convert_column_to_appid_usage(hstmt, bm_app_type);
-
- rc = bm_query_finalize(hstmt);
- BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
- *error_code = BATTERY_MONITOR_ERROR_NONE;
-
-CATCH:
- if (hstmt != NULL) {
- rc = bm_query_finalize(hstmt);
- if (rc != BATTERY_MONITOR_ERROR_NONE) {
- *error_code = rc;
- _ERR("finalize error");
- }
- hstmt = NULL;
- }
- if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_app_type) {
- BM_FREE(bm_app_type);
- bm_app_type = NULL;
- }
- if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_app_type != NULL) {
- _INFO("Returning appid usage");
- return bm_app_type;
- }
-
- EXIT;
- return NULL;
-}
-
static appid_usage_s* bm_query_usage_by_appid_ci(sqlite3 *bm_db_handle, const char *app_id, long long s_time, long long e_time, int *error_code)
{
ENTER;
return error_code;
}
-static resourceid_usage_s* bm_query_usage_by_resourceid(sqlite3 *bm_db_handle, const char *resource_id, int *error_code, int period_type)
-{
- ENTER;
-
- long int duration = 0;
- duration = bm_get_time_bias(period_type);
- if (duration == 0) {
- _ERR("Invalid period_type [%d]", period_type);
- return NULL;
- }
-
- _DBG("Value for duration is [%ld]", duration);
-
- bm_stmt hstmt = NULL;
- char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
- int rc = 0;
- *error_code = BATTERY_MONITOR_ERROR_NONE;
-
- BM_RETURN_VAL((resource_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; },
- NULL, ("RESOURCE ID IS NULL"));
- BM_RETURN_VAL((bm_db_handle != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; },
- NULL, ("The database isn't connected."));
- BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
- BM_SNPRINTF(query, sizeof(query), "SELECT ResourceId, sum(usage) FROM %s WHERE ResourceId = '%s' \
- AND log_time >= %ld", BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE, resource_id, duration);
-
- hstmt = bm_prepare_query(bm_db_handle, query);
- if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
- _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
- *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
- return NULL;
- }
-
- resourceid_usage_s *bm_resource_type = NULL;
-
- rc = bm_query_step(hstmt);
- BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", resource_id));
-
- bm_resource_type = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
- if (bm_resource_type == NULL) {
- _ERR("memory allocation failed");
- if (hstmt != NULL) {
- rc = bm_query_finalize(hstmt);
- BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
- hstmt = NULL;
- }
- *error_code = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bm_convert_column_to_resourceid_usage(hstmt, bm_resource_type);
-
- rc = bm_query_finalize(hstmt);
- BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
- hstmt = NULL;
-
- *error_code = BATTERY_MONITOR_ERROR_NONE;
-
-CATCH:
- if (hstmt != NULL) {
- rc = bm_query_finalize(hstmt);
- if (rc != BATTERY_MONITOR_ERROR_NONE) {
- *error_code = rc;
- _ERR("finalize error");
- }
- hstmt = NULL;
- }
- if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
- BM_FREE(bm_resource_type);
- bm_resource_type = NULL;
- }
- if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
- _INFO("Returning appid usage");
- return bm_resource_type;
- }
-
- EXIT;
- return NULL;
-}
-
static resourceid_usage_s* bm_query_usage_by_resourceid_ci(sqlite3 *bm_db_handle, const char *resource_id, long long s_time, long long e_time, int *error_code)
{
ENTER;
}
/* For App usage related queries */
-appid_usage_s *bm_server_query_app_usage_by_appid(const char *app_id, int period_type, int *error_code)
-{
- ENTER;
-
- appid_usage_s *bm_app_type = NULL;
- *error_code = BATTERY_MONITOR_ERROR_NONE;
-
- BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
- BM_RETURN_VAL((app_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; }, NULL, ("The Battery Monitor Handle is NULL"));
-
- bm_app_type = bm_query_usage_by_appid(g_hBatteryMonitorDB, app_id, error_code, period_type);
-
- EXIT;
- return bm_app_type;
-}
-
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)
{
ENTER;
}
/* For Resource usage related queries */
-resourceid_usage_s *bm_server_query_resource_usage_resourceid(const char *resource_id, int period_type, int *error_code)
-{
- ENTER;
-
- resourceid_usage_s *bm_resource_type = NULL;
- *error_code = BATTERY_MONITOR_ERROR_NONE;
-
- BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
- BM_RETURN_VAL((resource_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; }, NULL, ("The Battery Monitor Handle is NULL"));
-
- bm_resource_type = bm_query_usage_by_resourceid(g_hBatteryMonitorDB, resource_id, error_code, period_type);
-
- EXIT;
- return bm_resource_type;
-}
-
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)
{
resourceid_usage_s *bm_resource_type = NULL;