Apply check_async_call_rate to each function 64/244764/4
authorlokilee73 <changjoo.lee@samsung.com>
Thu, 24 Sep 2020 05:09:54 +0000 (14:09 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Thu, 24 Sep 2020 10:41:48 +0000 (10:41 +0000)
Currently, check_async_call_rate is applied to power and display.
If power related api is blocked, display related api is blocked as well.
So, devide them.

Change-Id: I7132448f2aaf29fe26fcd1c4f3e7f7d421732fd6
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/common.c
src/common.h
src/display.c
src/power.c

index 39b5944..893c7b9 100644 (file)
@@ -182,10 +182,9 @@ tizen_profile_t _get_tizen_profile()
        return profile;
 }
 
-int check_async_call_rate(void)
+int check_async_call_rate(long *num_calls)
 {
        static int status;
-       static long num_calls;
        static struct timeval prev;
        struct timeval cur;
        int ret;
@@ -197,13 +196,13 @@ int check_async_call_rate(void)
        if (ret < 0)
                return 0;
 
-       if (num_calls > 0) {
+       if (*num_calls > 0) {
                long rate;
                struct timeval diff;
                timersub(&cur, &prev, &diff);
 
                if (diff.tv_sec > 0) {
-                       rate = num_calls / diff.tv_sec;
+                       rate = *num_calls / diff.tv_sec;
 
                        if (rate > CHECK_RATE_THRESHOLD) {
                                status = -1;
@@ -212,7 +211,7 @@ int check_async_call_rate(void)
 
                        if (diff.tv_sec > CHECK_RATE_PERIOD_LEN) {
                                /* Reset the check period */
-                               num_calls = 0;
+                               *num_calls = 0;
                                return 0;
                        }
                }
@@ -221,7 +220,7 @@ int check_async_call_rate(void)
                prev = cur;
        }
 
-       num_calls++;
+       *num_calls += 1;
        return 0;
 }
 
index 524fdc7..273ed79 100644 (file)
@@ -78,7 +78,7 @@ extern tizen_profile_t _get_tizen_profile();
 
 #define CHECK_RATE_THRESHOLD   100
 #define CHECK_RATE_PERIOD_LEN  5
-int check_async_call_rate(void);
+int check_async_call_rate(long *num_calls);
 
 #define TIZEN_FEATURE_TRACKER (_get_tizen_profile() == TIZEN_PROFILE_TV)
 
index 80f6465..1d8dd15 100644 (file)
@@ -247,12 +247,13 @@ int device_display_change_state(display_state_e state)
        char *str;
        int ret;
        static int privilege = -1;
+       static long num_calls = 0;
 
        ret = is_display_state_supported();
        if (!ret)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
-       if (check_async_call_rate() < 0) {
+       if (check_async_call_rate(&num_calls) < 0) {
 //LCOV_EXCL_START System Error
                _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
                                , CHECK_RATE_THRESHOLD);
index 2d4762c..f41ca3d 100644 (file)
@@ -439,10 +439,11 @@ static int unlock_state(display_state_e state, unsigned int flag)
 int device_power_request_lock(power_lock_e type, int timeout_ms)
 {
        int ret;
+       static long num_calls = 0;
 
        _I("power_lock_e = %d", type);
 
-       if (check_async_call_rate() < 0) {
+       if (check_async_call_rate(&num_calls) < 0) {
 //LCOV_EXCL_START System Error
                _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
                                , CHECK_RATE_THRESHOLD);