#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"
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)
(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(¤t_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++) {