Moved application ground status monitor to plugin. 09/150009/2
authorNishant Chaprana <n.chaprana@samsung.com>
Thu, 14 Sep 2017 04:01:10 +0000 (09:31 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Thu, 14 Sep 2017 04:05:13 +0000 (09:35 +0530)
Change-Id: Ie9680b6d25b73b8262529d02a7885e86396dfc32
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
16 files changed:
include/stc-manager-gdbus.h
include/stc-manager-plugin.h
include/stc-manager.h
include/stc-plugin.h
packaging/stc-manager.spec
plugin/CMakeLists.txt
plugin/stc-plugin.c
src/monitor/include/stc-app-ground-status.h [deleted file]
src/monitor/include/stc-app-lifecycle.h
src/monitor/include/stc-default-connection.h
src/monitor/stc-app-ground-status.c [deleted file]
src/monitor/stc-app-lifecycle.c
src/monitor/stc-default-connection.c
src/stc-manager-gdbus.c
src/stc-manager-plugin.c
src/stc-manager.c

index cafca77..045a70c 100755 (executable)
 } while (0)
 
 
-#define RETURN_IF_DBUS_TYPE_MISMATCH(parameters, str) do { \
-       DEBUG_PARAM_TYPE(parameters); \
-       DEBUG_PARAMS(parameters); \
-       if (g_strcmp0(g_variant_get_type_string(parameters), str)) { \
-               STC_LOGE("Dbus type not matching, do not process"); \
-               __STC_LOG_FUNC_EXIT__; \
-               return; \
-       } \
-} while (0)
-
 typedef void(*dbus_dict_cb)(const char *key, GVariant *value,
                            void *user_data);
 
index 6eae115..f4233da 100755 (executable)
@@ -19,6 +19,8 @@
 
 #define STC_PLUGIN_FILEPATH            "/usr/lib/stc-manager-plugin.so"
 
+#include "stc-plugin.h"
+
 void stc_manager_plugin_init(void);
 void stc_manager_plugin_deinit(void);
 
@@ -27,4 +29,9 @@ int stc_send_warn_message_to_net_popup(const char *content,
 int stc_send_restriction_message_to_net_popup(const char *content,
                const char *type, const char *app_id, const char *iftype, const char *limit);
 
+int stc_register_state_changed_cb(stc_s *stc,
+                                 stc_plugin_app_state_changed_cb cb,
+                                 void *data);
+int stc_deregister_state_changed_cb(stc_s *stc);
+
 #endif /* __STC_MANAGER_PLUGIN_H__ */
index 160da59..990db68 100755 (executable)
@@ -36,6 +36,16 @@ typedef enum {
        STC_CONTINUE = 1,  /**< continue */
 } stc_cb_ret_e;
 
+typedef enum {
+       STC_CMD_NONE,
+       STC_CMD_SET_FOREGRD,
+       STC_CMD_SET_BACKGRD,
+       STC_CMD_SET_APP_LAUNCHED,
+       STC_CMD_SET_SERVICE_LAUNCHED,
+       STC_CMD_SET_TERMINATED,
+       STC_CMD_MAX_ELEM
+} stc_cmd_type_e;
+
 /**
  * @brief Monitored application types
  */
index 3bbcedb..4d843b8 100755 (executable)
 #define __STC_PLUGIN_H__
 
 #include <glib.h>
+#include "stc-error.h"
+#include "stc-manager.h"
+
+typedef stc_error_e (*stc_plugin_app_state_changed_cb)(stc_cmd_type_e cmd,
+                                                      pid_t pid,
+                                                      const gchar *app_id,
+                                                      const gchar *pkg_id,
+                                                      stc_app_type_e app_type);
 
 typedef struct {
        int(*send_restriction_message_to_net_popup) (const char *,
-               const char *, const char *, const char *, 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 *);
+                                             const char *,
+                                             const char *,
+                                             const char *,
+                                             const char *);
+       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_s;
 
 #endif /* __STC_PLUGIN_H__ */
index 66b9d54..e08e1cb 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.29
+Version:    0.0.30
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index 74cab33..3e5dcda 100755 (executable)
@@ -17,6 +17,7 @@ FOREACH(flag ${pkgs_plugin_CFLAGS})
 ENDFOREACH(flag)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/monitor/include)
 # INCLUDE_DIRECTORIES(SRCS include)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror -fvisibility=hidden")
index 13f0306..a566388 100755 (executable)
 #include <bundle.h>
 #include <bundle_internal.h>
 #include <dlog.h>
+#include <gio/gio.h>
 
 #include "stc-plugin.h"
+#include "stc-manager.h"
+#include "stc-manager-util.h"
 
-#ifdef USE_DLOG
-#include <dlog.h>
+/*
+ * AUL
+ */
+#define AUL_APP_STATUS_DBUS_PATH                   "/Org/Tizen/Aul/AppStatus"
+#define AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE       "org.tizen.aul.AppStatus"
+#define AUL_APP_STATUS_BUS_NAME                    AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE
+
+#define AUL_APP_STATUS_DBUS_STATUS_CHANGE          "AppStatusChange"
+#define AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE     "(issss)"
+
+typedef struct {
+       guint sub_id;
+       const gchar *path;
+       const gchar *interface;
+       const gchar *member;
+       const gchar *param_type;
+       GDBusSignalCallback callback;
+       gpointer user_data;
+} signal_map_s;
+
+stc_error_e(*state_changed_cb)(stc_cmd_type_e cmd, pid_t pid,
+                              const gchar *app_id, const gchar *pkg_id,
+                              stc_app_type_e app_type);
+
+static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
+                                              const gchar *sender_name,
+                                              const gchar *object_path,
+                                              const gchar *interface_name,
+                                              const gchar *signal_name,
+                                              GVariant *parameters,
+                                              gpointer user_data)
+{
+       __STC_LOG_FUNC_ENTER__;
+       pid_t pid;
+       stc_cmd_type_e status;
+       stc_app_type_e apptype;
+       gchar *appid, *pkgid, *statstr, *pkgtype;
+
+       if (g_strcmp0(g_variant_get_type_string(parameters),
+                     AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE)) {
+               STC_LOGE("Dbus type not matching, do not process");
+               __STC_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       g_variant_get(parameters, AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
+                     &pid, &appid, &pkgid, &statstr, &pkgtype);
+
+       if (!strncmp(statstr, "fg", 2)) {
+               status = STC_CMD_SET_FOREGRD;
+       } else if (!strncmp(statstr, "bg", 2)) {
+               status = STC_CMD_SET_BACKGRD;
+       } else {
+               __STC_LOG_FUNC_EXIT__;
+               goto out;
+       }
+
+       if (!strncmp(pkgtype, "svc", 3))
+               apptype = STC_APP_TYPE_SERVICE;
+       else if (!strncmp(pkgtype, "widget", 6))
+               apptype = STC_APP_TYPE_WIDGET;
+       else if (!strncmp(pkgtype, "watch", 5))
+               apptype = STC_APP_TYPE_WATCH;
+       else
+               apptype = STC_APP_TYPE_GUI;
+
+       if (state_changed_cb)
+               state_changed_cb(status, pid, appid, pkgid, apptype);
+
+       __STC_LOG_FUNC_EXIT__;
+out:
+       FREE(appid);
+       FREE(pkgid);
+       FREE(statstr);
+       FREE(pkgtype);
+}
 
-#undef LOG_TAG
-#define LOG_TAG "STC_MANAGER"
+signal_map_s signal_map[] = {
+
+       /* AMD DBUS */
+       {
+               0,
+               AUL_APP_STATUS_DBUS_PATH,
+               AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+               AUL_APP_STATUS_DBUS_STATUS_CHANGE,
+               AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
+               __stc_gdbus_handle_aul_changestate,
+               NULL
+       },
+       {
+               0,
+               NULL,
+               NULL,
+               NULL,
+               NULL
+       }
+};
 
-#define STC_LOGD(format, args...) LOGD(format, ##args)
-#define STC_LOGI(format, args...) LOGI(format, ##args)
-#define STC_LOGW(format, args...) LOGW(format, ##args)
-#define STC_LOGE(format, args...) LOGE(format, ##args)
 
-#define __STC_LOG_FUNC_ENTER__ LOGD("Enter")
-#define __STC_LOG_FUNC_EXIT__ LOGD("Quit")
+static stc_error_e __ground_status_monitor_init(stc_s *stc)
+{
+       guint i = 0;
+
+       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
+
+       for (i = 0; signal_map[i].member != NULL; i++) {
+               signal_map[i].sub_id =
+                       g_dbus_connection_signal_subscribe(stc->connection,
+                                                          NULL,
+                                                          signal_map[i].interface,
+                                                          signal_map[i].member,
+                                                          signal_map[i].path,
+                                                          NULL,
+                                                          G_DBUS_SIGNAL_FLAGS_NONE,
+                                                          signal_map[i].callback,
+                                                          signal_map[i].user_data,
+                                                          NULL);
+               STC_LOGI("Successfully subscribed [%s] signal",
+                        signal_map[i].member);
+       }
+
+       return STC_ERROR_NONE;
+}
 
-#else /* USE_DLOG */
+static stc_error_e __ground_status_monitor_deinit(stc_s *stc)
+{
+       guint i = 0;
 
-#define STC_LOGD(format, args...)
-#define STC_LOGI(format, args...)
-#define STC_LOGW(format, args...)
-#define STC_LOGE(format, args...)
+       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
 
-#define __STC_LOG_FUNC_ENTER__
-#define __STC_LOG_FUNC_EXIT__
+       for (i = 0; signal_map[i].member != NULL; i++) {
+               g_dbus_connection_signal_unsubscribe(stc->connection,
+                                                    signal_map[i].sub_id);
+               signal_map[i].sub_id = 0;
+               STC_LOGD("Successfully unsubscribed [%s] signal",
+                        signal_map[i].member);
+       }
 
-#endif /* USE_DLOG */
+       return STC_ERROR_NONE;
+}
 
 static int __stc_send_warn_message_to_net_popup(const char *content,
                const char *type, const char *app_id, const char *iftype, const char *warn)
@@ -95,11 +213,29 @@ static int __stc_send_restriction_message_to_net_popup(const char *content,
        return ret;
 }
 
+static int __register_state_changed_cb(stc_s *stc,
+                                      stc_plugin_app_state_changed_cb cb,
+                                      void *data)
+{
+       state_changed_cb = cb;
+       __ground_status_monitor_init(stc);
+
+       return 0;
+}
+
+int __deregister_state_changed_cb(stc_s *stc)
+{
+       state_changed_cb = NULL;
+       __ground_status_monitor_deinit(stc);
+       return 0;
+}
 
 API stc_plugin_s stc_plugin = {
        .send_warn_message_to_net_popup =
                __stc_send_warn_message_to_net_popup,
        .send_restriction_message_to_net_popup =
-               __stc_send_restriction_message_to_net_popup
+               __stc_send_restriction_message_to_net_popup,
+       .register_state_changed_cb = __register_state_changed_cb,
+       .deregister_state_changed_cb = __deregister_state_changed_cb
 };
 
diff --git a/src/monitor/include/stc-app-ground-status.h b/src/monitor/include/stc-app-ground-status.h
deleted file mode 100755 (executable)
index fb02abc..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __STC_APP_GROUND_STATUS_H__
-#define __STC_APP_GROUND_STATUS_H__
-
-#include "stc-error.h"
-#include "stc-manager.h"
-#include "stc-manager-gdbus.h"
-#include "stc-manager-util.h"
-#include "stc-monitor.h"
-
-stc_error_e stc_app_ground_status_monitor_init(stc_s *stc);
-stc_error_e stc_app_ground_status_monitor_deinit(stc_s *stc);
-
-#endif /* __STC_APP_GROUND_STATUS_H__ */
index fae72ec..3946c3e 100755 (executable)
 
 #include "stc-error.h"
 #include "stc-manager.h"
-#include "stc-manager-gdbus.h"
 #include "stc-manager-util.h"
 #include "stc-monitor.h"
 
-typedef enum {
-       STC_CMD_NONE,
-       STC_CMD_SET_FOREGRD,
-       STC_CMD_SET_BACKGRD,
-       STC_CMD_SET_APP_LAUNCHED,
-       STC_CMD_SET_SERVICE_LAUNCHED,
-       STC_CMD_SET_TERMINATED,
-       STC_CMD_MAX_ELEM
-} stc_cmd_type_e;
-
 stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
                                           pid_t pid,
                                           gchar *app_id,
index 861e58d..b3326de 100755 (executable)
@@ -20,7 +20,6 @@
 #include <glib.h>
 #include "stc-error.h"
 #include "stc-manager.h"
-#include "stc-manager-gdbus.h"
 #include "stc-manager-util.h"
 
 #define IMSI_LENGTH 16
diff --git a/src/monitor/stc-app-ground-status.c b/src/monitor/stc-app-ground-status.c
deleted file mode 100755 (executable)
index a5c24ec..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "stc-app-lifecycle.h"
-#include "stc-app-ground-status.h"
-
-/*
- * AUL
- */
-#define AUL_APP_STATUS_DBUS_PATH                   "/Org/Tizen/Aul/AppStatus"
-#define AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE       "org.tizen.aul.AppStatus"
-#define AUL_APP_STATUS_BUS_NAME                    AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE
-
-#define AUL_APP_STATUS_DBUS_STATUS_CHANGE          "AppStatusChange"
-#define AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE     "(issss)"
-
-typedef struct {
-       guint sub_id;
-       const gchar *path;
-       const gchar *interface;
-       const gchar *member;
-       const gchar *param_type;
-       GDBusSignalCallback callback;
-       gpointer user_data;
-} signal_map_s;
-
-static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
-                                              const gchar *sender_name,
-                                              const gchar *object_path,
-                                              const gchar *interface_name,
-                                              const gchar *signal_name,
-                                              GVariant *parameters,
-                                              gpointer user_data)
-{
-       __STC_LOG_FUNC_ENTER__;
-       pid_t pid;
-       stc_cmd_type_e status;
-       stc_app_type_e apptype;
-       gchar *appid, *pkgid, *statstr, *pkgtype;
-
-       RETURN_IF_DBUS_TYPE_MISMATCH(parameters,
-                                    AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE);
-
-       g_variant_get(parameters, AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
-                     &pid, &appid, &pkgid, &statstr, &pkgtype);
-
-       if (!strncmp(statstr, "fg", 2)) {
-               status = STC_CMD_SET_FOREGRD;
-       } else if (!strncmp(statstr, "bg", 2)) {
-               status = STC_CMD_SET_BACKGRD;
-       } else {
-               __STC_LOG_FUNC_EXIT__;
-               goto handle_error;
-       }
-
-       if (!strncmp(pkgtype, "svc", 3))
-               apptype = STC_APP_TYPE_SERVICE;
-       else if (!strncmp(pkgtype, "widget", 6))
-               apptype = STC_APP_TYPE_WIDGET;
-       else if (!strncmp(pkgtype, "watch", 5))
-               apptype = STC_APP_TYPE_WATCH;
-       else
-               apptype = STC_APP_TYPE_GUI;
-
-       stc_manager_app_status_changed(status, pid, appid, pkgid, apptype);
-
-       __STC_LOG_FUNC_EXIT__;
-handle_error:
-       FREE(appid);
-       FREE(pkgid);
-       FREE(statstr);
-       FREE(pkgtype);
-}
-
-signal_map_s signal_map[] = {
-
-       /* AMD DBUS */
-       {
-               0,
-               AUL_APP_STATUS_DBUS_PATH,
-               AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
-               AUL_APP_STATUS_DBUS_STATUS_CHANGE,
-               AUL_APP_STATUS_DBUS_STATUS_CHANGE_TYPE,
-               __stc_gdbus_handle_aul_changestate,
-               NULL
-       },
-       {
-               0,
-               NULL,
-               NULL,
-               NULL,
-               NULL
-       }
-};
-
-stc_error_e stc_app_ground_status_monitor_init(stc_s *stc)
-{
-       guint i = 0;
-       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-
-       for (i = 0; signal_map[i].member != NULL; i++) {
-               signal_map[i].sub_id =
-                       stc_manager_gdbus_subscribe_signal(stc->connection,
-                                                          NULL,
-                                                          signal_map[i].interface,
-                                                          signal_map[i].member,
-                                                          signal_map[i].path,
-                                                          NULL,
-                                                          G_DBUS_SIGNAL_FLAGS_NONE,
-                                                          signal_map[i].callback,
-                                                          signal_map[i].user_data,
-                                                          NULL);
-               STC_LOGI("Successfully subscribed [%s] signal",
-                        signal_map[i].member);
-       }
-
-       return STC_ERROR_NONE;
-}
-
-stc_error_e stc_app_ground_status_monitor_deinit(stc_s *stc)
-{
-       guint i = 0;
-       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-
-       for (i = 0; signal_map[i].member != NULL; i++) {
-               stc_manager_gdbus_unsubscribe_signal(stc->connection,
-                                                    signal_map[i].sub_id);
-               signal_map[i].sub_id = 0;
-               STC_LOGD("Successfully unsubscribed [%s] signal",
-                        signal_map[i].member);
-       }
-
-       return STC_ERROR_NONE;
-}
index 6036098..3192c28 100755 (executable)
@@ -27,6 +27,7 @@
 #include <linux/cn_proc.h>
 #include <glib.h>
 
+#include "stc-manager-gdbus.h"
 #include "stc-app-lifecycle.h"
 #include "helper-procfs.h"
 
index 8b32a3e..e524970 100755 (executable)
@@ -17,6 +17,7 @@
 #include <vconf/vconf.h>
 
 #include "stc-monitor.h"
+#include "stc-manager-gdbus.h"
 #include "stc-default-connection.h"
 
 /* connman service dbus details */
index 31a808d..aee4c9e 100755 (executable)
@@ -18,7 +18,8 @@
 #include "stc-statistics.h"
 #include "stc-restriction.h"
 #include "stc-default-connection.h"
-#include "stc-app-ground-status.h"
+#include "stc-manager-plugin.h"
+#include "stc-app-lifecycle.h"
 
 static gboolean __stc_manager_gdbus_statistics_init(stc_s *stc)
 {
@@ -153,8 +154,8 @@ static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection,
        g_dbus_object_manager_server_set_connection(stc->obj_mgr,
                                                    stc->connection);
 
-       stc_app_ground_status_monitor_init(stc);
        stc_default_connection_monitor_init(stc);
+       stc_register_state_changed_cb(stc, stc_manager_app_status_changed, NULL);
 
        __STC_LOG_FUNC_EXIT__;
 }
@@ -194,9 +195,12 @@ void stc_manager_gdbus_deinit(gpointer stc_data)
 {
        __STC_LOG_FUNC_ENTER__;
        stc_s *stc = (stc_s *)stc_data;
-       stc_app_ground_status_monitor_deinit(stc);
+
+       stc_deregister_state_changed_cb(stc);
        stc_default_connection_monitor_deinit(stc);
+
        g_bus_unown_name(stc->gdbus_owner_id);
+
        stc->statistics_obj = NULL;
        stc->restriction_obj = NULL;
        __STC_LOG_FUNC_EXIT__;
index d25b1a8..9a8d96b 100755 (executable)
@@ -31,6 +31,7 @@ void stc_manager_plugin_init(void)
        handle_plugin = dlopen(STC_PLUGIN_FILEPATH, RTLD_NOW);
        if (!handle_plugin) {
                STC_LOGE("Can't load %s: %s", STC_PLUGIN_FILEPATH, dlerror());
+               __STC_LOG_FUNC_EXIT__;
                return;
        }
 
@@ -38,11 +39,11 @@ void stc_manager_plugin_init(void)
        if (!stc_plugin) {
                STC_LOGE("Can't load symbol: %s", dlerror());
                dlclose(handle_plugin);
+               __STC_LOG_FUNC_EXIT__;
                return;
        }
 
        stc_plugin_enabled = TRUE;
-
        __STC_LOG_FUNC_EXIT__;
 }
 
@@ -50,48 +51,101 @@ void stc_manager_plugin_deinit(void)
 {
        __STC_LOG_FUNC_ENTER__;
 
-       if (!stc_plugin_enabled)
+       if (!stc_plugin_enabled) {
+               __STC_LOG_FUNC_EXIT__;
                return;
+       }
 
        stc_plugin_enabled = FALSE;
        dlclose(handle_plugin);
-
        __STC_LOG_FUNC_EXIT__;
 }
 
-int stc_send_warn_message_to_net_popup(const char *content,
-               const char *type, const char *app_id, const char *iftype, const char *warn)
+int stc_send_warn_message_to_net_popup(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 0;
        }
 
        if (!stc_plugin) {
                STC_LOGE("Plugin wasn't loaded");
+               __STC_LOG_FUNC_EXIT__;
                return 0;
        }
 
-       return stc_plugin->send_warn_message_to_net_popup(content, type, app_id, iftype, warn);
+       __STC_LOG_FUNC_EXIT__;
+       return stc_plugin->send_warn_message_to_net_popup(content, type, app_id,
+                                                         iftype, warn);
 }
 
 int stc_send_restriction_message_to_net_popup(const char *content,
-               const char *type, const char *app_id, const char *iftype, const char *limit)
+                                             const char *type,
+                                             const char *app_id,
+                                             const char *iftype,
+                                             const char *limit)
 {
        __STC_LOG_FUNC_ENTER__;
 
        if (!stc_plugin_enabled) {
                STC_LOGE("Plugin wasn't enabled");
+               __STC_LOG_FUNC_EXIT__;
                return 0;
        }
 
        if (!stc_plugin) {
                STC_LOGE("Plugin wasn't loaded");
+               __STC_LOG_FUNC_EXIT__;
                return 0;
        }
 
-       return stc_plugin->send_restriction_message_to_net_popup(content, type, app_id, iftype, limit);
+       __STC_LOG_FUNC_EXIT__;
+       return stc_plugin->send_restriction_message_to_net_popup(content, type,
+                                                                app_id, iftype,
+                                                                limit);
 }
 
+int stc_register_state_changed_cb(stc_s *stc,
+                                 stc_plugin_app_state_changed_cb cb,
+                                 void *data)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       if (!stc_plugin_enabled) {
+               __STC_LOG_FUNC_EXIT__;
+               STC_LOGE("Plugin wasn't enabled");
+               return 0;
+       }
+
+       if (!stc_plugin) {
+               STC_LOGE("Plugin wasn't loaded");
+               __STC_LOG_FUNC_EXIT__;
+               return 0;
+       }
+
+       return stc_plugin->register_state_changed_cb(stc, cb, data);
+}
+int stc_deregister_state_changed_cb(stc_s *stc)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       if (!stc_plugin_enabled) {
+               __STC_LOG_FUNC_EXIT__;
+               STC_LOGE("Plugin wasn't enabled");
+               return 0;
+       }
+
+       if (!stc_plugin) {
+               __STC_LOG_FUNC_EXIT__;
+               STC_LOGE("Plugin wasn't loaded");
+               return 0;
+       }
+       __STC_LOG_FUNC_EXIT__;
+
+       return stc_plugin->deregister_state_changed_cb(stc);
+}
index 0b91ce4..cfee380 100755 (executable)
@@ -17,8 +17,6 @@
 #include <signal.h>
 #include "stc-manager.h"
 #include "stc-emulator.h"
-#include "stc-statistics.h"
-#include "stc-restriction.h"
 #include "stc-manager-gdbus.h"
 #include "stc-db.h"
 #include "counter.h"
@@ -40,11 +38,12 @@ static void __stc_manager_deinit(void)
                return;
        }
 
-       stc_app_lifecycle_monitor_deinit();
        stc_monitor_deinit();
        stc_deinit_db_guard();
        stc_db_deinitialize();
+
        stc_manager_gdbus_deinit((gpointer)g_stc);
+       stc_app_lifecycle_monitor_deinit();
        stc_manager_plugin_deinit();
 
        STC_LOGI("stc manager deinitialized");
@@ -73,9 +72,9 @@ static stc_s *__stc_manager_init(void)
        if (err != STC_ERROR_NONE)
                goto handle_error;
 
-       stc_manager_gdbus_init((gpointer)stc);
        stc_manager_plugin_init();
        stc_app_lifecycle_monitor_init();
+       stc_manager_gdbus_init((gpointer)stc);
 
        STC_LOGI("stc manager initialized");
        __STC_LOG_FUNC_EXIT__;