From: hyunuktak Date: Fri, 26 May 2017 01:51:32 +0000 (+0900) Subject: Added some CAPIs to set/unset callback about warn/restriction threshold crossed X-Git-Tag: submit/tizen/20170601.042236~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F131208%2F3;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Added some CAPIs to set/unset callback about warn/restriction threshold crossed Change-Id: Ie89ddb4cc5af3ef7dc3fe24cc369730f8ac8b8d9 Signed-off-by: hyunuktak --- diff --git a/include/stc_internal.h b/include/stc_internal.h index 0ace400..fc4efcc 100755 --- a/include/stc_internal.h +++ b/include/stc_internal.h @@ -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); diff --git a/packaging/capi-network-stc.spec b/packaging/capi-network-stc.spec index 5fa9244..64ac835 100755 --- a/packaging/capi-network-stc.spec +++ b/packaging/capi-network-stc.spec @@ -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 diff --git a/src/internal/include/stc-event.h b/src/internal/include/stc-event.h index 9fb23e9..73fc193 100755 --- a/src/internal/include/stc-event.h +++ b/src/internal/include/stc-event.h @@ -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; diff --git a/src/internal/include/stc-private.h b/src/internal/include/stc-private.h index 48ab79a..a284b47 100755 --- a/src/internal/include/stc-private.h +++ b/src/internal/include/stc-private.h @@ -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 } diff --git a/src/internal/stc-private.c b/src/internal/stc-private.c index e556270..2664c50 100755 --- a/src/internal/stc-private.c +++ b/src/internal/stc-private.c @@ -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; } - diff --git a/src/internal/stc-signal.c b/src/internal/stc-signal.c index a44c00c..97b8941 100755 --- a/src/internal/stc-signal.c +++ b/src/internal/stc-signal.c @@ -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) diff --git a/src/stc-manager.c b/src/stc-manager.c index 387de52..ecbb759 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -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; } diff --git a/test/restriction.c b/test/restriction.c index 7d120bd..27df0dc 100755 --- a/test/restriction.c +++ b/test/restriction.c @@ -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}, diff --git a/test/restriction.h b/test/restriction.h index ec2989f..7991997 100755 --- a/test/restriction.h +++ b/test/restriction.h @@ -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__ */ diff --git a/test/stc_test.c b/test/stc_test.c index 25aeca2..03b13c0 100755 --- a/test/stc_test.c +++ b/test/stc_test.c @@ -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);