Merge "[Add] tethering client monitoring" into tizen
[platform/core/connectivity/stc-manager.git] / src / monitor / stc-monitor.c
old mode 100644 (file)
new mode 100755 (executable)
index fbed5e3..7f28d9c
 
 #define GRANULARITY 10
 #define MAX_INT_LENGTH 128
+
+#ifndef VCONFKEY_STC_BACKGROUND_STATE
 #define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
+#endif
+
+#ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
+#define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
+#endif
 
 typedef struct {
        time_t now;
@@ -58,6 +65,34 @@ typedef struct {
 
 static stc_system_s *g_system = NULL;
 
+//LCOV_EXCL_START
+static int __vconf_get_int(const char *key, int *value)
+{
+       int ret = 0;
+
+       ret = vconf_get_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to get vconfkey [%s] value", key); //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
+       }
+
+       return 0;
+}
+
+static int __vconf_set_int(const char *key, int value)
+{
+       int ret = 0;
+
+       ret = vconf_set_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to set vconfkey [%s] value", key); //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
+       }
+
+       return 0;
+}
+//LCOV_EXCL_STOP
+
 static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter)
 {
        if (counter->intend == NFACCT_WARN)
@@ -795,6 +830,22 @@ static void __del_iptables_rule(int64_t classid, nfacct_rule_intend intend,
        __del_ip6tables_out(&counter);
 }
 
+static void __set_rstn_noti_state(int value)
+{
+       int state = STC_RSTN_STATE_INIT;
+
+       if (__vconf_get_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, &state))
+               return;
+
+       if (state == value) {
+               STC_LOGI("No need to change a restriction status: %d", state);
+               return;
+       }
+
+       vconf_set_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, value);
+       return;
+}
+
 typedef struct {
        time_t month_start_ts;
        time_t week_start_ts;
@@ -940,6 +991,8 @@ static void __process_restriction(enum traffic_restriction_type rstn_type,
                for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++)
                        if (rstn_value->limit[i] >= 0)
                                rstn_value->counter[i] = 0;
+
+               __set_rstn_noti_state(STC_RSTN_STATE_UNSET);
        }
        break;
        default:
@@ -1121,6 +1174,8 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type,
                context->counter->intend = NFACCT_COUNTER;
 
                rstn_value->limit_exceeded |= (1 << limit_type);
+
+               __set_rstn_noti_state(STC_RSTN_STATE_SET);
        }
        break;
        default:
@@ -2058,33 +2113,6 @@ static void __add_application_by_interface(const char *app_id)
        FREE(app_key.app_id);
 }
 
-static int __vconf_get_int(const char *key, int *value)
-{
-       int ret = 0;
-
-       ret = vconf_get_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to get vconfkey [%s] value", key); //LCOV_EXCL_LINE
-               return -1; //LCOV_EXCL_LINE
-       }
-
-       return 0;
-}
-
-//LCOV_EXCL_START
-static int __vconf_set_int(const char *key, int value)
-{
-       int ret = 0;
-
-       ret = vconf_set_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to set vconfkey [%s] value", key); //LCOV_EXCL_LINE
-               return -1; //LCOV_EXCL_LINE
-       }
-
-       return 0;
-}
-
 static guint __get_background_state(void)
 {
        return g_system->background_state;;