* @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);
/**
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);
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
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;
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;
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
}
}
}
+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);
{
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;
}
}
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;
}
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;
}
-
#include "stc-dbus.h"
#include "stc-log.h"
#include "stc-util.h"
+#include "stc-event.h"
+#include "stc-info.h"
#include "stc-signal.h"
* 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)
{
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)
}
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);
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;
}
}
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);
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;
}
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);
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},
*****************************************************************************/
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__ */
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);
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);