From 5aa578ed04c81e50cb42743ce41825b3d4050162 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Thu, 12 Jul 2018 14:38:00 +0900 Subject: [PATCH 1/1] Modified to send message to net popup Change-Id: I0ffbc76a3fc0ecee7eb9ba295a32f32f6f8391c4 Signed-off-by: hyunuktak --- include/stc-manager-plugin-appstatus.h | 4 +-- packaging/stc-manager.spec | 2 +- plugin/appstatus/include/stc-plugin-appstatus.h | 10 ++---- plugin/appstatus/stc-plugin-appstatus.c | 44 ++++++++----------------- src/monitor/stc-monitor.c | 25 +++++++------- src/stc-manager-plugin-appstatus.c | 28 ++-------------- 6 files changed, 32 insertions(+), 81 deletions(-) mode change 100644 => 100755 include/stc-manager-plugin-appstatus.h mode change 100644 => 100755 plugin/appstatus/include/stc-plugin-appstatus.h mode change 100644 => 100755 plugin/appstatus/stc-plugin-appstatus.c mode change 100644 => 100755 src/stc-manager-plugin-appstatus.c diff --git a/include/stc-manager-plugin-appstatus.h b/include/stc-manager-plugin-appstatus.h old mode 100644 new mode 100755 index b177bd7..1140199 --- a/include/stc-manager-plugin-appstatus.h +++ b/include/stc-manager-plugin-appstatus.h @@ -24,9 +24,7 @@ int stc_plugin_appstatus_init(void); int stc_plugin_appstatus_deinit(void); -int stc_plugin_appstatus_send_warn_message(const char *content, - const char *type, const char *app_id, const char *iftype, const char *warn); -int stc_plugin_appstatus_send_restriction_message(const char *content, +int stc_plugin_appstatus_send_message(const char *content, const char *type, const char *app_id, const char *iftype, const char *limit); int stc_plugin_appstatus_register_state_changed_cb(stc_s *stc, diff --git a/packaging/stc-manager.spec b/packaging/stc-manager.spec index bcad233..6b837c0 100644 --- a/packaging/stc-manager.spec +++ b/packaging/stc-manager.spec @@ -1,6 +1,6 @@ Name: stc-manager Summary: STC(Smart Traffic Control) manager -Version: 0.0.70 +Version: 0.0.71 Release: 0 Group: Network & Connectivity/Other License: Apache-2.0 diff --git a/plugin/appstatus/include/stc-plugin-appstatus.h b/plugin/appstatus/include/stc-plugin-appstatus.h old mode 100644 new mode 100755 index ed4a7b4..45025be --- a/plugin/appstatus/include/stc-plugin-appstatus.h +++ b/plugin/appstatus/include/stc-plugin-appstatus.h @@ -29,19 +29,15 @@ typedef stc_error_e (*stc_plugin_app_state_changed_cb)(stc_cmd_type_e cmd, typedef struct { /* popup */ - int (*send_restriction_message_to_net_popup) (const char *, - const char *, const char *, const char *, const char *); - int (*send_warn_message_to_net_popup) (const char *, - const char *, const char *, const char *, const char *); + int (*send_message_to_net_popup) (const char *, const char *, + const char *, const char *, const char *); /* app status */ int (*register_state_changed_cb) (stc_s *stc, stc_plugin_app_state_changed_cb cb, void *data); int (*deregister_state_changed_cb) (stc_s *stc); } stc_plugin_appstatus_s; -int stc_plugin_popup_send_restriction_message(const char *content, - const char *type, const char *app_id, const char *iftype, const char *limit); -int stc_plugin_popup_send_restriction_message(const char *content, +int stc_plugin_popup_send_message(const char *content, const char *type, const char *app_id, const char *iftype, const char *limit); int stc_plugin_appstatus_register_changed_cb(stc_s *stc, diff --git a/plugin/appstatus/stc-plugin-appstatus.c b/plugin/appstatus/stc-plugin-appstatus.c old mode 100644 new mode 100755 index d9764b4..672eb8c --- a/plugin/appstatus/stc-plugin-appstatus.c +++ b/plugin/appstatus/stc-plugin-appstatus.c @@ -183,42 +183,26 @@ int stc_plugin_appstatus_deregister_changed_cb(stc_s *stc) return 0; } -int stc_plugin_popup_send_warn_message(const char *content, - const char *type, const char *app_id, const char *iftype, const char *warn) -{ - int ret = 0; - bundle *b = bundle_create(); - - STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] warn[%s]", - content, type, app_id, warn); - - bundle_add(b, "_SYSPOPUP_CONTENT_", content); - bundle_add(b, "_SYSPOPUP_TYPE_", type); - bundle_add(b, "_APP_ID_", app_id); - bundle_add(b, "_IF_TYPE_", iftype); - bundle_add(b, "_WARN_LIMIT_", warn); - - ret = syspopup_launch("net-popup", b); - - bundle_free(b); - - return ret; -} - -int stc_plugin_popup_send_restriction_message(const char *content, +int stc_plugin_popup_send_message(const char *content, const char *type, const char *app_id, const char *iftype, const char *limit) { int ret = 0; bundle *b = bundle_create(); - STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]", - content, type, app_id, limit); - bundle_add(b, "_SYSPOPUP_CONTENT_", content); bundle_add(b, "_SYSPOPUP_TYPE_", type); bundle_add(b, "_APP_ID_", app_id); bundle_add(b, "_IF_TYPE_", iftype); - bundle_add(b, "_RESTRICTION_LIMIT_", limit); + + if (g_strcmp0(type, "warning_noti") == 0) { + bundle_add(b, "_WARN_LIMIT_", limit); + STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] limit[%s]", + content, type, app_id, limit); + } else { + bundle_add(b, "_RESTRICTION_LIMIT_", limit); + STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]", + content, type, app_id, limit); + } ret = syspopup_launch("net-popup", b); @@ -228,10 +212,8 @@ int stc_plugin_popup_send_restriction_message(const char *content, } API stc_plugin_appstatus_s stc_plugin_appstatus = { - .send_warn_message_to_net_popup = - stc_plugin_popup_send_warn_message, - .send_restriction_message_to_net_popup = - stc_plugin_popup_send_restriction_message, + .send_message_to_net_popup = + stc_plugin_popup_send_message, .register_state_changed_cb = stc_plugin_appstatus_register_changed_cb, .deregister_state_changed_cb = diff --git a/src/monitor/stc-monitor.c b/src/monitor/stc-monitor.c index 4210441..5885fc9 100755 --- a/src/monitor/stc-monitor.c +++ b/src/monitor/stc-monitor.c @@ -894,6 +894,8 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type, char iftype[MAX_INT_LENGTH]; char byte[MAX_INT_LENGTH]; const char *signal_name; + const char *net_popup_content; + const char *net_popup_type; stc_s *stc = (stc_s *)stc_get_manager(); if (stc == NULL) { @@ -905,13 +907,8 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type, case STC_RSTN_LIMIT_TYPE_DATA_WARN: { signal_name = "WarnThresholdCrossed"; - - snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype); - snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit[limit_type]); - stc_plugin_appstatus_send_warn_message("warn threshold crossed", - "warning_noti", - rstn_key->app_id, - iftype, byte); + net_popup_content = "warn threshold crossed"; + net_popup_type = "warning_noti"; } break; case STC_RSTN_LIMIT_TYPE_DATA: @@ -920,6 +917,8 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type, case STC_RSTN_LIMIT_TYPE_DAILY: { signal_name = "RestrictionThresholdCrossed"; + net_popup_content = "restriction threshold crossed"; + net_popup_type = "restriction_noti"; /* block immediately */ context->counter->intend = NFACCT_BLOCK; @@ -935,13 +934,6 @@ 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); - - snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype); - snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit[limit_type]); - stc_plugin_appstatus_send_restriction_message("restriction threshold crossed", - "restriction_noti", - rstn_key->app_id, - iftype, byte); } break; default: @@ -959,6 +951,11 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type, if (rv == TRUE) rstn_value->limit_notified |= (1 << limit_type); + + snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype); + snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit[limit_type]); + stc_plugin_appstatus_send_message(net_popup_content, + net_popup_type, rstn_key->app_id, iftype, byte); } static gboolean __rstn_counter_update(stc_rstn_key_s *rstn_key, diff --git a/src/stc-manager-plugin-appstatus.c b/src/stc-manager-plugin-appstatus.c old mode 100644 new mode 100755 index 8bc067b..cab52ad --- a/src/stc-manager-plugin-appstatus.c +++ b/src/stc-manager-plugin-appstatus.c @@ -64,29 +64,7 @@ int stc_plugin_appstatus_deinit(void) return STC_ERROR_NONE; } -int stc_plugin_appstatus_send_warn_message(const char *content, - const char *type, const char *app_id, const char *iftype, const char *warn) -{ - __STC_LOG_FUNC_ENTER__; - - if (!stc_plugin_enabled) { - STC_LOGE("Plugin wasn't enabled"); - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_UNINITIALIZED; - } - - if (!stc_plugin) { - STC_LOGE("Plugin wasn't loaded"); - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_UNINITIALIZED; - } - - __STC_LOG_FUNC_EXIT__; - return stc_plugin->send_warn_message_to_net_popup(content, - type, app_id, iftype, warn); -} - -int stc_plugin_appstatus_send_restriction_message(const char *content, +int stc_plugin_appstatus_send_message(const char *content, const char *type, const char *app_id, const char *iftype, const char *limit) { __STC_LOG_FUNC_ENTER__; @@ -104,8 +82,8 @@ int stc_plugin_appstatus_send_restriction_message(const char *content, } __STC_LOG_FUNC_EXIT__; - return stc_plugin->send_restriction_message_to_net_popup(content, - type, app_id, iftype, limit); + return stc_plugin->send_message_to_net_popup(content, + type, app_id, iftype, limit); } int stc_plugin_appstatus_register_state_changed_cb(stc_s *stc, -- 2.7.4