Add support of app_id in GetAll method call on statistics interface
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-statistics.c
index f8db77b..7d13a3f 100755 (executable)
@@ -375,7 +375,9 @@ stc_error_e table_statistics_reset_first_n_entries(int num)
                __STC_LOG_FUNC_EXIT__;
        }
 handle_error:
-       sqlite3_reset(delete_query[4]);
+       if (sqlite3_reset(delete_query[4]) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 //LCOV_EXCL_STOP
@@ -419,7 +421,9 @@ stc_error_e table_statistics_reset(const table_statistics_reset_rule *rule)
 
        STC_LOGD("Entry deleted successfully.");
 handle_error:
-       sqlite3_reset(stmt);
+       if (sqlite3_reset(stmt) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 
@@ -436,13 +440,19 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
                       bind parameters in the query */
        stc_db_tm_interval_s interval;
 
-       memset(&data, 0, sizeof(data));
-
        if (!rule || !info_cb) {
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
+       memset(&data, 0, sizeof(data));
+
+       if (rule->app_id) {
+               int ret = table_statistics_per_app(rule->app_id, rule, info_cb, user_data);
+               __STC_LOG_FUNC_EXIT__;
+               return ret;
+       }
+
        /* pick a statement depending on parameters */
        if (rule->granularity) {
                stmt = __is_iftype_defined(rule->iftype) ?
@@ -495,13 +505,16 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
        } while (rc == SQLITE_ROW);
 
 handle_error:
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
 
-stc_error_e table_statistics_per_app(const char *app_id,
-                                    table_statistics_select_rule *rule,
+API stc_error_e table_statistics_per_app(const char *app_id,
+                                    const table_statistics_select_rule *rule,
                                     table_statistics_info_cb info_cb,
                                     void *user_data)
 {
@@ -573,20 +586,23 @@ stc_error_e table_statistics_per_app(const char *app_id,
        } while (rc == SQLITE_ROW);
 
 handle_error:
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
 
-stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
+API stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                                    stc_db_app_stats *stat,
                                    time_t last_touch_time)
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = update_statistics_query;
        stc_hw_net_protocol_type_e hw_net_protocol_type = STC_PROTOCOL_UNKNOWN;
-       int64_t rcv;
-       int64_t snd;
+       long long int rcv;
+       long long int snd;
 
        if (!stat->rcv_count && !stat->snd_count) {
                error_code = STC_ERROR_INVALID_PARAMETER;
@@ -621,12 +637,14 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                goto handle_error; //LCOV_EXCL_LINE
        }
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGD("App stat recorded [\033[0;34m%s\033[0;m] "
                        "rcv[%lld] snd[%lld]", stat->app_id, rcv, snd);
 
 handle_error:
-       sqlite3_reset(stmt);
+       if (sqlite3_reset(stmt) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }