Add some chains to separate monitoring and restriction
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-statistics.c
old mode 100755 (executable)
new mode 100644 (file)
index 49856b4..5983ad7
@@ -327,8 +327,6 @@ static void __finalize_insert(void)
 
 static int __is_iftype_defined(const stc_iface_type_e iftype)
 {
-       __STC_LOG_FUNC_ENTER__;
-       __STC_LOG_FUNC_EXIT__;
        return iftype < STC_IFACE_LAST_ELEM &&
                iftype > STC_IFACE_UNKNOWN &&
                iftype != STC_IFACE_ALL;
@@ -352,11 +350,9 @@ static sqlite3_stmt **details_stms[] = {
 static sqlite3_stmt *__select_statement(const char *app_id,
                                        const table_statistics_select_rule *rule)
 {
-       __STC_LOG_FUNC_ENTER__;
        const int stm_index = __is_iftype_defined(rule->iftype) |
                ((strlen(app_id) > 0) ? 0 : 2) | (rule->granularity ? 4 : 0);
        STC_LOGD("stm index %d", stm_index);
-       __STC_LOG_FUNC_EXIT__;
        return *details_stms[stm_index];
 }
 
@@ -488,15 +484,12 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
 
                        if (info_cb(&data, user_data) == STC_CANCEL)
                                rc = SQLITE_DONE; //LCOV_EXCL_LINE
-                       __STC_LOG_FUNC_EXIT__;
                        break;
                case SQLITE_DONE:
-                       __STC_LOG_FUNC_EXIT__;
                        break;
                case SQLITE_ERROR:
                default:
                        error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
-                       __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                        break; //LCOV_EXCL_LINE
                }
        } while (rc == SQLITE_ROW);
@@ -569,15 +562,12 @@ stc_error_e table_statistics_per_app(const char *app_id,
 
                        if (info_cb(&data, user_data) == STC_CANCEL)
                                rc = SQLITE_DONE; //LCOV_EXCL_LINE
-                       __STC_LOG_FUNC_EXIT__;
                        break;
                case SQLITE_DONE:
-                       __STC_LOG_FUNC_EXIT__;
                        break;
                case SQLITE_ERROR:
                default:
                        error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
-                       __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
                        break; //LCOV_EXCL_LINE
                }
        } while (rc == SQLITE_ROW);
@@ -594,7 +584,9 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
 {
        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_NONE;
+       stc_hw_net_protocol_type_e hw_net_protocol_type = STC_PROTOCOL_UNKNOWN;
+       int64_t rcv;
+       int64_t snd;
 
        if (!stat->rcv_count && !stat->snd_count) {
                error_code = STC_ERROR_INVALID_PARAMETER;
@@ -605,19 +597,20 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                                    SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_int(stmt, 2, stat->rcv_count));
        DB_ACTION(sqlite3_bind_int(stmt, 3, stat->snd_count));
-       DB_ACTION(sqlite3_bind_int64(stmt, 4,
-                                    (sqlite3_int64)(last_touch_time)));
+       DB_ACTION(sqlite3_bind_int64(stmt, 4, (sqlite3_int64)last_touch_time));
        DB_ACTION(sqlite3_bind_int(stmt, 5, (int)(stat_key->iftype)));
        DB_ACTION(sqlite3_bind_int(stmt, 6, (int)(stat->is_roaming)));
        DB_ACTION(sqlite3_bind_int(stmt, 7, (int)hw_net_protocol_type));
-       DB_ACTION(sqlite3_bind_text(stmt, 8, stat_key->ifname, -1,
-                                   SQLITE_STATIC));
+       DB_ACTION(sqlite3_bind_text(stmt, 8, stat_key->ifname ? stat_key->ifname : "",
+                                       -1, SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_text(stmt, 9,
-                                   stat_key->subscriber_id ? stat_key->subscriber_id : "" , -1,
-                                   SQLITE_STATIC));
+                                   stat_key->subscriber_id ? stat_key->subscriber_id : "" ,
+                                   -1, SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_int(stmt, 10, (int)stat->ground));
 
        /*we want to reuse tree*/
+       rcv = stat->rcv_count;
+       snd = stat->snd_count;
        stat->rcv_count = 0;
        stat->snd_count = 0;
        if (sqlite3_step(stmt) != SQLITE_DONE) {
@@ -628,7 +621,9 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                goto handle_error; //LCOV_EXCL_LINE
        }
 
-       STC_LOGD("App stat recorded [%s]", stat->app_id);
+       if (STC_DEBUG_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);