Added some CAPIs to set/unset callback about warn/restriction threshold crossed 08/131208/3
authorhyunuktak <hyunuk.tak@samsung.com>
Fri, 26 May 2017 01:51:32 +0000 (10:51 +0900)
committerNishant Chaprana <n.chaprana@samsung.com>
Mon, 29 May 2017 09:51:52 +0000 (15:21 +0530)
Change-Id: Ie89ddb4cc5af3ef7dc3fe24cc369730f8ac8b8d9
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
include/stc_internal.h
packaging/capi-network-stc.spec
src/internal/include/stc-event.h
src/internal/include/stc-private.h
src/internal/stc-private.c
src/internal/stc-signal.c
src/stc-manager.c
test/restriction.c
test/restriction.h
test/stc_test.c

index 0ace400f9cf95afe078d01a0ffff8ab03d27daeb..fc4efcce99217a4cc12421ec6a8eb535d32319a5 100755 (executable)
@@ -134,10 +134,10 @@ typedef enum {
  * @see        stc_get_restriction()
  * @see        stc_foreach_restriction()
  */
-typedef stc_callback_ret_e(*stc_restriction_info_cb)(stc_error_e result,
+typedef stc_callback_ret_e (*stc_restriction_info_cb)(stc_error_e result,
                stc_restriction_info_h info, void *user_data);
 
-typedef stc_callback_ret_e(*stc_threshold_clossed_cb)(stc_restriction_info_h info,
+typedef void (*stc_threshold_crossed_cb)(stc_restriction_info_h info,
                void *user_data);
 
 /**
@@ -389,12 +389,12 @@ int stc_get_restriction(stc_h stc, stc_restriction_rule_h rule,
                stc_restriction_info_cb info_cb, void *user_data);
 
 int stc_set_restriction_threshold_crossed_cb(stc_h stc,
-               stc_threshold_clossed_cb clossed_cb, void *user_data);
+               stc_threshold_crossed_cb crossed_cb, void *user_data);
 
 int stc_unset_restriction_threshold_crossed_cb(stc_h stc);
 
 int stc_set_warn_threshold_crossed_cb(stc_h stc,
-               stc_threshold_clossed_cb clossed_cb, void *user_data);
+               stc_threshold_crossed_cb crossed_cb, void *user_data);
 
 int stc_unset_warn_threshold_crossed_cb(stc_h stc);
 
index 5fa924423dec75869aa2526189b4411faacbe1af..64ac83598f8707fa6d9b379844884efbeb0bbd58 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-network-stc
 Summary:    A Smart Traffic Control (STC) libraries in Native API
-Version:    0.0.6
+Version:    0.0.7
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 9fb23e986337b9c492d1b95b397d1b58330fdc6a..73fc1937479c71f15241bfcb523ae7c58a7aafcf 100755 (executable)
@@ -57,6 +57,8 @@ typedef enum {
        STC_EVENT_STATS_GET_TOTAL_RSP,
        STC_EVENT_RESTRICTION_GET_RSP,
        STC_EVENT_RESTRICTION_GET_ALL_RSP,
+       STC_EVENT_WARN_THRESHOLD_CROSSED_RSP,
+       STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP,
        STC_EVENT_LAST_ELEM,
 } stc_event_e;
 
index 48ab79a0fd495c32306be92ac82afc25436431c6..a284b47c88002ce0c2d1db44d226c6fa38284276 100755 (executable)
@@ -70,9 +70,9 @@ typedef struct {
        stc_restriction_info_cb restriction_all_cb;
        void *restriction_all_user_data;
 
-       stc_threshold_clossed_cb restriction_crossed_cb;
+       stc_threshold_crossed_cb restriction_crossed_cb;
        void *restriction_crossed_user_data;
-       stc_threshold_clossed_cb warn_crossed_cb;
+       stc_threshold_crossed_cb warn_crossed_cb;
        void *warn_crossed_user_data;
 } stc_handle_s;
 
@@ -126,9 +126,9 @@ void _stc_callback_set_restriction_all_info(stc_h stc,
                        stc_restriction_info_cb user_cb, void *user_data);
 
 void _stc_callback_set_restriction_threshold_crossed(stc_h stc,
-                       stc_threshold_clossed_cb user_cb, void *user_data);
+                       stc_threshold_crossed_cb user_cb, void *user_data);
 void _stc_callback_set_warn_threshold_crossed(stc_h stc,
-                       stc_threshold_clossed_cb user_cb, void *user_data);
+                       stc_threshold_crossed_cb user_cb, void *user_data);
 
 #ifdef __cplusplus
 }
index e556270a43c4910be23d1012d6e9e3202d33ce26..2664c50e1a0b85c46295a5c83a15eae60fb94cb7 100755 (executable)
@@ -373,6 +373,30 @@ static void __stc_callback_foreach(stc_event_e e,
        }
 }
 
+static void __stc_signal_callback(stc_event_e e, void *info_data)
+{
+       GSList *list;
+       int ret = STC_ERROR_NONE;
+
+       for (list = g_stc_handle_list; list; list = list->next) {
+               stc_handle_s *handle = (stc_handle_s *)list->data;
+               switch (e) {
+               case STC_EVENT_WARN_THRESHOLD_CROSSED_RSP:
+                       if (handle->warn_crossed_cb)
+                               handle->warn_crossed_cb((stc_restriction_info_h)info_data,
+                                                       handle->warn_crossed_user_data);
+                       break;
+               case STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP:
+                       if (handle->restriction_crossed_cb)
+                               handle->restriction_crossed_cb((stc_restriction_info_h)info_data,
+                                                              handle->restriction_crossed_user_data);
+                       break;
+               default:
+                       break;
+               }
+       }
+}
+
 static void __stc_event_cb(stc_event_info_s *event_info, void *user_data)
 {
        STC_LOGI("STC event callback [%d]", event_info->event);
@@ -386,12 +410,19 @@ static void __stc_event_cb(stc_event_info_s *event_info, void *user_data)
                {
                        stc_error_e error = event_info->error;
                        GSList *info_data = (GSList *)event_info->info_data;
-                       __stc_callback_foreach(
-                               event_info->event,
-                               error, info_data);
+                       __stc_callback_foreach(event_info->event,
+                                              error, info_data);
                        g_slist_free(info_data);
                }
                break;
+       case STC_EVENT_WARN_THRESHOLD_CROSSED_RSP:
+       case STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP:
+               {
+                       __stc_signal_callback(event_info->event,
+                               event_info->info_data);
+                       g_free(event_info->info_data);
+               }
+               break;
        default:
                break;
        }
@@ -512,7 +543,7 @@ void _stc_callback_set_restriction_all_info(stc_h stc,
 }
 
 void _stc_callback_set_restriction_threshold_crossed(stc_h stc,
-                       stc_threshold_clossed_cb user_cb, void *user_data)
+                       stc_threshold_crossed_cb user_cb, void *user_data)
 {
        stc_handle_s *handle = (stc_handle_s *)stc;
 
@@ -521,11 +552,10 @@ void _stc_callback_set_restriction_threshold_crossed(stc_h stc,
 }
 
 void _stc_callback_set_warn_threshold_crossed(stc_h stc,
-                       stc_threshold_clossed_cb user_cb, void *user_data)
+                       stc_threshold_crossed_cb user_cb, void *user_data)
 {
        stc_handle_s *handle = (stc_handle_s *)stc;
 
        handle->warn_crossed_cb = user_cb;
        handle->warn_crossed_user_data = user_data;
 }
-
index a44c00ca97f306d4d2c1585aed8ceea04ba8c25d..97b894169223d2601335601d050977d95a4b983d 100755 (executable)
@@ -44,6 +44,8 @@
 #include "stc-dbus.h"
 #include "stc-log.h"
 #include "stc-util.h"
+#include "stc-event.h"
+#include "stc-info.h"
 
 #include "stc-signal.h"
 
@@ -61,16 +63,54 @@ static __thread guint gdbus_subscribe_id_stc_manager_restriction = 0;
  *  Local Functions Definition
  *****************************************************************************/
 
-static int __stc_handle_stats(GVariant *param)
+static void __stc_handle_stats(GVariant *param)
 {
        return STC_ERROR_NONE;
 }
 
-static int __stc_handle_restriction(GVariant *param)
+static void __stc_handle_restriction(GVariant *param)
 {
        return STC_ERROR_NONE;
 }
 
+static void __stc_handle_warn_threshold_crossed(GVariant *param)
+{
+       const char *app_id = NULL;
+       stc_event_info_s event_data = { 0, };
+       stc_restriction_info_s *info = NULL;
+
+       g_variant_get(param, "(&s)", &app_id);
+
+       info = g_try_malloc0(sizeof(stc_restriction_info_s));
+       if (info != NULL) {
+               g_strlcpy(info->app_id, app_id, STC_APP_ID_LEN);
+
+               event_data.event = STC_EVENT_WARN_THRESHOLD_CROSSED_RSP;
+               event_data.info_data = (stc_restriction_info_h)info;
+
+               _stc_event_add_client_idle_cb(&event_data, NULL);
+       }
+}
+
+static void __stc_handle_restriction_threshold_crossed(GVariant *param)
+{
+       const char *app_id = NULL;
+       stc_event_info_s event_data = { 0, };
+       stc_restriction_info_s *info = NULL;
+
+       g_variant_get(param, "(&s)", &app_id);
+
+       info = g_try_malloc0(sizeof(stc_restriction_info_s));
+       if (info != NULL) {
+               g_strlcpy(info->app_id, app_id, STC_APP_ID_LEN);
+
+               event_data.event = STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP;
+               event_data.info_data = (stc_restriction_info_h)info;
+
+               _stc_event_add_client_idle_cb(&event_data, NULL);
+       }
+}
+
 static void __stc_stats_signal_filter(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
@@ -85,6 +125,12 @@ static void __stc_restriction_signal_filter(GDBusConnection *conn,
 {
        if (g_strcmp0(sig, STC_SIGNAL_RESTRICTION) == 0)
                __stc_handle_restriction(param);
+       else if (g_strcmp0(sig, STC_SIGNAL_WARN_THRESHOLD_CROSSED) == 0)
+               __stc_handle_warn_threshold_crossed(param);
+       else if (g_strcmp0(sig, STC_SIGNAL_RESTRICTION_THRESHOLD_CROSSED) == 0)
+               __stc_handle_restriction_threshold_crossed(param);
+       else
+               ;//Do Nothing
 }
 
 int _stc_register_signal(void)
index 387de524dad30ec6938a3eee27cd6ed7eb8102b9..ecbb759ae8a4267fff7074741f524698ab6993cb 100755 (executable)
@@ -328,7 +328,7 @@ EXPORT_API int stc_get_restriction(stc_h stc, stc_restriction_rule_h rule,
 }
 
 EXPORT_API int stc_set_restriction_threshold_crossed_cb(stc_h stc,
-               stc_threshold_clossed_cb clossed_cb, void *user_data)
+               stc_threshold_crossed_cb crossed_cb, void *user_data)
 {
        CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
 
@@ -337,12 +337,12 @@ EXPORT_API int stc_set_restriction_threshold_crossed_cb(stc_h stc,
                return STC_ERROR_INVALID_PARAMETER;
        }
 
-       if (clossed_cb == NULL) {
+       if (crossed_cb == NULL) {
                STC_LOGE("Invalid parameter");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
-       _stc_callback_set_restriction_threshold_crossed(stc, clossed_cb, user_data);
+       _stc_callback_set_restriction_threshold_crossed(stc, crossed_cb, user_data);
 
        return STC_ERROR_NONE;
 }
@@ -362,7 +362,7 @@ EXPORT_API int stc_unset_restriction_threshold_crossed_cb(stc_h stc)
 }
 
 EXPORT_API int stc_set_warn_threshold_crossed_cb(stc_h stc,
-               stc_threshold_clossed_cb clossed_cb, void *user_data)
+               stc_threshold_crossed_cb crossed_cb, void *user_data)
 {
        CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
 
@@ -371,12 +371,12 @@ EXPORT_API int stc_set_warn_threshold_crossed_cb(stc_h stc,
                return STC_ERROR_INVALID_PARAMETER;
        }
 
-       if (clossed_cb == NULL) {
+       if (crossed_cb == NULL) {
                STC_LOGE("Invalid parameter");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
-       _stc_callback_set_warn_threshold_crossed(stc, clossed_cb, user_data);
+       _stc_callback_set_warn_threshold_crossed(stc, crossed_cb, user_data);
 
        return STC_ERROR_NONE;
 }
index 7d120bd7ad43de894b1d433472212ebf8e4ad49c..27df0dc9458c9e4f2e552a2c5381f42fc85f1706 100755 (executable)
@@ -124,6 +124,36 @@ static stc_callback_ret_e __test_stc_restriction_info_cb(
        return STC_CALLBACK_CONTINUE;
 }
 
+static void __test_stc_warn_threshold_crossed_cb(stc_restriction_info_h info,
+                       void *user_data)
+{
+       int ret = STC_ERROR_NONE;
+       char *app_id;
+
+       msg(HR_SINGLE);
+
+       ret = stc_restriction_info_get_app_id(info, &app_id);
+       if (ret == STC_ERROR_NONE)
+               msg("Warn threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id);
+
+       msg(HR_SINGLE);
+}
+
+static void __test_stc_restriction_threshold_crossed_cb(stc_restriction_info_h info,
+                       void *user_data)
+{
+       int ret = STC_ERROR_NONE;
+       char *app_id;
+
+       msg(HR_SINGLE);
+
+       ret = stc_restriction_info_get_app_id(info, &app_id);
+       if (ret == STC_ERROR_NONE)
+               msg("Restriction threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id);
+
+       msg(HR_SINGLE);
+}
+
 static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu)
 {
        stc_iface_type_e iface_type = (int)strtol(g_iface_type, NULL, 10);
@@ -394,6 +424,50 @@ int test_stc_restriction_rule_destroy(void)
        return ret;
 }
 
+int test_stc_restriction_register_cb(void)
+{
+       int ret = stc_set_warn_threshold_crossed_cb(g_stc,
+                       __test_stc_warn_threshold_crossed_cb, NULL);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to register warn threshold crossed cb" LOG_END);
+       else
+               msg("Fail to register warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       ret = stc_set_restriction_threshold_crossed_cb(g_stc,
+                       __test_stc_restriction_threshold_crossed_cb, NULL);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to register restriction threshold crossed cb" LOG_END);
+       else
+               msg("Fail to register restriction threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       return ret;
+}
+
+int test_stc_restriction_unregister_cb(void)
+{
+       int ret = stc_unset_warn_threshold_crossed_cb(g_stc);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to unregister warn threshold crossed cb" LOG_END);
+       else
+               msg("Fail to unregister warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       ret = stc_unset_restriction_threshold_crossed_cb(g_stc);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to unregister warn threshold crossed cb" LOG_END);
+       else
+               msg("Fail to unregister warn threshold crossed cb " LOG_RED "[%s]" LOG_END,
+                       test_stc_convert_error_type_to_string(ret));
+
+       return ret;
+}
+
 static struct menu_data menu_restriction_rule[] = {
        { "1", "Application ID", NULL, NULL, g_app_id},
        { "2", "Imsi", NULL, NULL, g_imsi},
index ec2989f4a0616f39747498277559c2049b75629b..799199717b7b83f42919c18058e4a07cdbc2fa2b 100755 (executable)
@@ -33,6 +33,8 @@
  *****************************************************************************/
 int test_stc_restriction_rule_create(void);
 int test_stc_restriction_rule_destroy(void);
+int test_stc_restriction_register_cb(void);
+int test_stc_restriction_unregister_cb(void);
 
 #endif /** __TEST_STC_RESTRICTION_H__ */
 
index 25aeca26ad6915e80a1132efe063689fffad91fb..03b13c0ea7118560706ae024e529946745173c7e 100755 (executable)
@@ -240,6 +240,7 @@ static int __test_stc_initialize(MManager *mm, struct menu_data *menu)
        test_stc_reset_rule_create();
        test_stc_stats_rule_create();
        test_stc_restriction_rule_create();
+       test_stc_restriction_register_cb();
 
        menu_manager_set_user_data(mm, g_stc);
 
@@ -253,6 +254,7 @@ static int __test_stc_deinitialize(void)
        test_stc_reset_rule_destroy();
        test_stc_stats_rule_destroy();
        test_stc_restriction_rule_destroy();
+       test_stc_restriction_unregister_cb();
 
        if (g_stc) {
                ret = stc_deinitialize(g_stc);