Add callback in monitor plugin to stop stc-manager 80/235980/3
authorNishant Chaprana <n.chaprana@samsung.com>
Thu, 11 Jun 2020 15:04:55 +0000 (20:34 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Fri, 12 Jun 2020 04:28:07 +0000 (09:58 +0530)
Change-Id: I88c9d9275620ee1ee32ee62e853e88c46c535a3f
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/stc-manager-plugin-monitor.h
packaging/stc-manager.spec
plugin/monitor/include/stc-plugin-monitor.h
plugin/monitor/stc-plugin-monitor.c
src/stc-manager-plugin-monitor.c
src/stc-manager.c

index 3830608..76a65bd 100755 (executable)
@@ -21,7 +21,7 @@
 
 #include "stc-plugin-monitor.h"
 
-int stc_plugin_monitor_init(void);
+int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb);
 int stc_plugin_monitor_deinit(void);
 
 int stc_plugin_monitor_add_app(uint32_t classid,
index a418017..f8690c2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.1.0
+Version:    0.1.1
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index 35509c8..0cc8c42 100755 (executable)
 #define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
 #endif
 
+typedef void (*stc_manager_stop_cb)(void);
+
 typedef struct {
-       int (*initialize_plugin) (void);
+       int (*initialize_plugin) (stc_manager_stop_cb stop_cb);
        int (*deinitialize_plugin) (void);
 
        int (*add_application) (uint32_t classid,
@@ -68,7 +70,7 @@ typedef struct {
        int (*check_excn_by_cmdline) (char *cmdline);
 } stc_plugin_monitor_s;
 
-stc_error_e stc_plugin_monitor_initialize(void);
+stc_error_e stc_plugin_monitor_initialize(stc_manager_stop_cb stop_cb);
 stc_error_e stc_plugin_monitor_deinitialize(void);
 
 GHashTable *stc_monitor_get_system_apps(void);
index 1f08dc3..ab06816 100755 (executable)
@@ -32,6 +32,7 @@
 #include "stc-manager-plugin-exception.h"
 
 static stc_system_s *g_system = NULL;
+static stc_manager_stop_cb g_stop_cb = NULL;
 
 static int __vconf_get_int(const char *key, int *value)
 {
@@ -101,6 +102,7 @@ static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
                STC_LOGE("failed to open socket");
                __free_system(system);
                g_system = NULL;
+               g_stop_cb();
                return STC_ERROR_FAIL;
        }
 
@@ -337,7 +339,7 @@ static void __fill_exceptions_list(void)
        stc_plugin_fill_exception_list();
 }
 
-stc_error_e stc_plugin_monitor_initialize(void)
+stc_error_e stc_plugin_monitor_initialize(stc_manager_stop_cb stop_cb)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -347,6 +349,11 @@ stc_error_e stc_plugin_monitor_initialize(void)
        ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY,
                                "stc_system_s malloc fail!");
 
+       ret_value_msg_if(stop_cb == NULL, STC_ERROR_INVALID_PARAMETER,
+                               "stop_cb callback is NULL");
+
+       g_stop_cb = stop_cb;
+
        /* initializing current classid */
        init_current_classid();
 
@@ -362,6 +369,7 @@ stc_error_e stc_plugin_monitor_initialize(void)
        if (system->contr_sock < 0) {
                STC_LOGE("failed to open socket");
                __free_system(system);
+               g_stop_cb();
                return STC_ERROR_FAIL;
        }
 
@@ -417,6 +425,7 @@ stc_error_e stc_plugin_monitor_deinitialize(void)
 
        __free_system(g_system);
        g_system = NULL;
+       g_stop_cb = NULL;
 
        return STC_ERROR_NONE;
 }
index 209b1a1..efdf759 100755 (executable)
@@ -24,7 +24,7 @@ static void *handle_plugin;
 static stc_plugin_monitor_s *stc_plugin;
 
 //LCOV_EXCL_START
-API int stc_plugin_monitor_init(void)
+API int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -43,7 +43,7 @@ API int stc_plugin_monitor_init(void)
                return STC_ERROR_UNINITIALIZED;
        }
 
-       stc_plugin->initialize_plugin();
+       stc_plugin->initialize_plugin(stop_cb);
        stc_plugin_enabled = TRUE;
 
        __STC_LOG_FUNC_EXIT__;
index a376e7f..0011c97 100755 (executable)
@@ -38,6 +38,7 @@
 #define BUF_SIZE_FOR_ERR 100
 
 static stc_s *g_stc = NULL;
+static gboolean g_is_fail_exit = FALSE;
 
 static gboolean __validate_ident(const char *ident)
 {
@@ -100,6 +101,15 @@ static void __stc_manager_deinit(void)
        __STC_LOG_FUNC_EXIT__;
 }
 
+void __stc_manager_stop_with_fail(void)
+{
+       STC_LOGI("plugin needs stc-manager to exit");
+
+       g_is_fail_exit = TRUE;
+
+       stc_stop_manager();
+}
+
 static stc_s *__stc_manager_init(void)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -134,7 +144,7 @@ static stc_s *__stc_manager_init(void)
        stc_plugin_tether_init();
        if (stc_plugin_pcap_init() == STC_ERROR_NONE)
                g_stc->ondemand_mode = FALSE;
-       if (stc_plugin_monitor_init() == STC_ERROR_NONE)
+       if (stc_plugin_monitor_init(__stc_manager_stop_with_fail) == STC_ERROR_NONE)
                g_stc->ondemand_mode = FALSE;
        stc_plugin_firewall_init();
 
@@ -265,6 +275,9 @@ gint32 main(gint32 argc, gchar *argv[])
        if (!g_stc)
                goto fail;
 
+       if (g_is_fail_exit == TRUE)
+               goto fail;
+
        /* Crate the GLIB main loop */
        main_loop = g_main_loop_new(NULL, FALSE);
        g_stc->main_loop = main_loop;
@@ -283,5 +296,8 @@ fail:
        if (main_loop)
                g_main_loop_unref(main_loop);
 
+       if (g_is_fail_exit == TRUE)
+               exit(-1);
+
        return 0;
 }