Add cumulative data usage by start timestamp 25/183525/1 accepted/tizen/4.0/unified/20180707.102306 submit/tizen_4.0/20180706.084834
authorhyunuktak <hyunuk.tak@samsung.com>
Fri, 6 Jul 2018 08:33:38 +0000 (17:33 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Fri, 6 Jul 2018 08:33:42 +0000 (17:33 +0900)
Change-Id: I375863f506af4b761dfe80cc8d408ddcfef92af3
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
packaging/stc-manager.spec
src/database/tables/table-statistics.c [changed mode: 0644->0755]
src/monitor/stc-monitor.c [changed mode: 0644->0755]

index 4facd80..eaea7f2 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.52
+Version:    0.0.53
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 2b58133..f953db4
@@ -33,6 +33,7 @@
 #include "stc-manager-plugin-popup.h"
 #include "stc-time.h"
 
+#define GRANULARITY 10
 #define MAX_INT_LENGTH 128
 #define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
 
@@ -493,6 +494,32 @@ static void __print_rstn(stc_rstn_key_s *rstn_key, stc_rstn_value_s *rstn_value)
                 rstn_key->roaming, rstn_key->subscriber_id);
 }
 
+typedef struct {
+       time_t month_start_ts;
+       time_t week_start_ts;
+       time_t day_start_ts;
+       int64_t monthly_stat;
+       int64_t weekly_stat;
+       int64_t daily_stat;
+} saved_stat_s;
+
+static stc_cb_ret_e __statistics_info_cb(const table_statistics_info *info,
+                                       void *user_data)
+{
+       saved_stat_s *stat = (saved_stat_s *)user_data;
+       int64_t counters = 0;
+
+       counters = info->cnt.in_bytes + info->cnt.out_bytes;
+
+       stat->monthly_stat += counters;
+       if (stat->week_start_ts <= info->interval->from)
+               stat->weekly_stat += counters;
+       if (stat->day_start_ts <= info->interval->from)
+               stat->daily_stat += counters;
+
+       return STC_CONTINUE;
+}
+
 static void __process_restriction(enum traffic_restriction_type rst_type,
                                  stc_rstn_key_s *rstn_key,
                                  stc_rstn_value_s *rstn_value, void *data)
@@ -540,13 +567,30 @@ static void __process_restriction(enum traffic_restriction_type rst_type,
                    (rstn_value->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
                     rstn_value->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
 
-                       table_counters_get(rstn_value->restriction_id, &info);
+                        time_t current_time = 0;
+                        table_statistics_select_rule select_rule;
+                        saved_stat_s stat;
 
-                       rstn_value->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
-                       rstn_value->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
-                       rstn_value->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter;
-                       rstn_value->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter;
-                       rstn_value->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter;
+                        memset(&stat, 0, sizeof(saved_stat_s));
+                        stat.month_start_ts = rstn_value->month_start_ts;
+                        stat.week_start_ts = g_system->last_week_ts;
+                        stat.day_start_ts = g_system->last_day_ts;
+
+                        select_rule.from = rstn_value->month_start_ts;
+                        time(&current_time);
+                        select_rule.to = current_time;
+                        select_rule.iftype = rstn_key->iftype;
+                        select_rule.granularity = GRANULARITY;
+
+                        table_statistics_per_app(rstn_key->app_id, &select_rule, __statistics_info_cb, &stat);
+
+                        table_counters_get(rstn_value->restriction_id, &info);
+
+                        rstn_value->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
+                        rstn_value->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
+                        rstn_value->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter + stat.monthly_stat;
+                        rstn_value->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter + stat.weekly_stat;
+                        rstn_value->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter + stat.daily_stat;
                }
 
                for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {