[STC Manager] Support set/get for total data usage(Tx + Rx) in restriction.
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-counters.c
index 9fb6fba..f8946f7 100755 (executable)
 
 #define DELETE_COUNTER "DELETE FROM counters WHERE restriction_id=?"
 
-#define SELECT_COUNTER "SELECT sent_bytes, rcv_bytes FROM counters WHERE restriction_id=?"
+#define SELECT_COUNTER "SELECT data_counter FROM counters WHERE restriction_id=?"
 
-#define INSERT_COUNTER "INSERT INTO counters (restriction_id, sent_bytes, rcv_bytes) " \
-       " VALUES (?, ?, ?)"
+#define INSERT_COUNTER "INSERT INTO counters (restriction_id, data_counter) " \
+       " VALUES (?, ?)"
 
-#define UPDATE_COUNTER "REPLACE INTO counters (restriction_id, sent_bytes, rcv_bytes) " \
-       " VALUES (?, ?, ?)"
+#define UPDATE_COUNTER "REPLACE INTO counters (restriction_id, data_counter) " \
+       " VALUES (?, ?)"
 
 static void __finalize_delete(void);
 
@@ -175,6 +175,8 @@ stc_error_e table_counters_get(uint64_t restriction_id,
        if (info == NULL)
                goto handle_error;
 
+       info->restriction_id = restriction_id;
+
        DB_ACTION(sqlite3_bind_int64(stmt, 1, restriction_id));
 
        do {
@@ -184,12 +186,10 @@ stc_error_e table_counters_get(uint64_t restriction_id,
                case SQLITE_DONE:
                        break;
                case SQLITE_ROW:
-                       info->sent_bytes = sqlite3_column_int64(stmt, 0);
-                       info->rcv_bytes = sqlite3_column_int64(stmt, 1);
+                       info->data_counter = sqlite3_column_int64(stmt, 0);
 
-                       STC_LOGD("rstn_id [%llu] counters [sent = %lld rcv = %lld]",
-                                restriction_id, info->sent_bytes,
-                                info->rcv_bytes);
+                       STC_LOGD("rstn_id [%llu] data_counters [%lld] bytes",
+                                restriction_id, info->data_counter);
                        break;
                case SQLITE_ERROR:
                default:
@@ -210,14 +210,13 @@ stc_error_e table_counters_update_counters(const table_counters_info *info)
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = update_counter;
 
-       if (!info->rcv_bytes && !info->sent_bytes) {
+       if (!info->data_counter) {
                error_code = STC_ERROR_INVALID_PARAMETER;
                goto handle_error;
        }
 
        DB_ACTION(sqlite3_bind_int64(stmt, 1, info->restriction_id));
-       DB_ACTION(sqlite3_bind_int64(stmt, 2, info->sent_bytes));
-       DB_ACTION(sqlite3_bind_int64(stmt, 3, info->rcv_bytes));
+       DB_ACTION(sqlite3_bind_int64(stmt, 2, info->data_counter));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                STC_LOGE("Failed to update counter: %s\n",