[Non-ACR] refactoring - dbus init/deinit in listeners 82/238482/1
authorAbhishek Vijay <abhishek.v@samsung.com>
Tue, 14 Jul 2020 08:36:37 +0000 (14:06 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Tue, 14 Jul 2020 08:36:37 +0000 (14:06 +0530)
Change-Id: Ie431b2684223ece34ea307e1ec2d7273986d3a27

include/bm_util.h
src/battery_dump/bm_listeners.c
src/bm_server.c
src/bm_util.c

index c8686bd..bf2c4b4 100644 (file)
@@ -51,6 +51,10 @@ GVariant* bm_marshal_serialized_data(const bm_total_consumption_h data);
 
 const char *bm_get_resource_id_string(gint resource_id);
 
+int bm_set_dbus_connection_obj(GDBusConnection* conn);
+
+GDBusConnection* bm_get_dbus_connection_obj(void);
+
 void bm_data_free(gpointer data);
 
 void bm_atm_free(gpointer data);
index 2f246ba..a714ee1 100644 (file)
@@ -18,6 +18,7 @@
 #include "bm_listeners.h"
 #include "bm_dbg.h"
 #include <bm_common.h>
+#include <bm_util.h>
 #include <bd_history_item.h>
 #include <vconf.h>
 #include <pthread.h>
@@ -78,7 +79,7 @@ GHashTable *app_list = NULL;
 #define DBUS_DEVICED_SLEEP_MEMBER "sleep"
 #define DBUS_DEVICED_WAKEUP_MEMBER "wakeup"
 
-static GDBusConnection *dbus_connection;
+/*static GDBusConnection *dbus_connection;
 
 static int bm_listener_dbus_init(void)
 {
@@ -116,7 +117,7 @@ int bm_listener_dbus_deinit()
 
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
-}
+}*/
 
 static int fill_AppId_info(char *app_id)
 {
@@ -1902,38 +1903,27 @@ static int bm_powerlock_unlock_subscribe_listener(void)
        ENTER;
        guint ret = 0;
 
-       if (!dbus_connection) {
+       GDBusConnection* dbus_connection = bm_get_dbus_connection_obj();
+       if (dbus_connection == NULL) {
                _ERR("dbus connection is null");
                EXIT;
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection,
-                               NULL,
-                               DBUS_DEVICED_IFACE,
-                               DBUS_DEVICED_PL_MEMBER,
-                               DBUS_DEVICED_PATH,
-                               NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE,
-                               __powerlock_signal_callback,
-                               NULL,
-                               NULL);
+       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, DBUS_DEVICED_IFACE,
+                               DBUS_DEVICED_PL_MEMBER, DBUS_DEVICED_PATH, NULL,
+                               G_DBUS_SIGNAL_FLAGS_NONE, __powerlock_signal_callback,
+                               NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection,
-                                       NULL,
-                                       DBUS_DEVICED_IFACE,
-                                       DBUS_DEVICED_PU_MEMBER,
-                                       DBUS_DEVICED_PATH,
-                                       NULL,
-                                       G_DBUS_SIGNAL_FLAGS_NONE,
-                                       __powerunlock_signal_callback,
-                                       NULL,
-                                       NULL);
+       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, DBUS_DEVICED_IFACE,
+                                       DBUS_DEVICED_PU_MEMBER, DBUS_DEVICED_PATH,
+                                       NULL, G_DBUS_SIGNAL_FLAGS_NONE, __powerunlock_signal_callback,
+                                       NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
@@ -1949,38 +1939,25 @@ static int bm_sleep_wakeup_subscribe_listener(void)
        ENTER;
        guint ret = 0;
 
+       GDBusConnection* dbus_connection = bm_get_dbus_connection_obj();
        if (!dbus_connection) {
                _ERR("dbus connection is null");
                EXIT;
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection,
-                               NULL,
-                               DBUS_DEVICED_IFACE,
-                               DBUS_DEVICED_SLEEP_MEMBER,
-                               DBUS_DEVICED_PATH,
-                               NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE,
-                               __sleep_signal_callback,
-                               NULL,
-                               NULL);
+       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, DBUS_DEVICED_IFACE,
+                               DBUS_DEVICED_SLEEP_MEMBER, DBUS_DEVICED_PATH, NULL,
+                               G_DBUS_SIGNAL_FLAGS_NONE, __sleep_signal_callback, NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection,
-                               NULL,
-                               DBUS_DEVICED_IFACE,
-                               DBUS_DEVICED_WAKEUP_MEMBER,
-                               DBUS_DEVICED_PATH,
-                               NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE,
-                               __wakeup_signal_callback,
-                               NULL,
-                               NULL);
+       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, DBUS_DEVICED_IFACE,
+                               DBUS_DEVICED_WAKEUP_MEMBER, DBUS_DEVICED_PATH, NULL,
+                               G_DBUS_SIGNAL_FLAGS_NONE, __wakeup_signal_callback, NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
@@ -1996,22 +1973,16 @@ static int bm_app_status_listener(void)
        ENTER;
        guint ret = 0;
 
+       GDBusConnection* dbus_connection = bm_get_dbus_connection_obj();
        if (!dbus_connection) {
                _ERR("dbus connection is null");
                EXIT;
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection,
-                               NULL,
-                               "org.tizen.aul.AppStatus",
-                               "AppStatusChange",
-                               "/Org/Tizen/Aul/AppStatus",
-                               NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE,
-                               __app_status_signal_callback,
-                               NULL,
-                               NULL);
+       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, "org.tizen.aul.AppStatus",
+                               "AppStatusChange", "/Org/Tizen/Aul/AppStatus", NULL,
+                               G_DBUS_SIGNAL_FLAGS_NONE, __app_status_signal_callback, NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
@@ -2112,9 +2083,9 @@ int bd_initialize_listeners(void)
        if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
                _ERR("pthread_attr_setdetachstate failed");
 
-       /*Initialize DBus*/
+       /*Initialize DBus*
        if (bm_listener_dbus_init())
-               _ERR("bm_listener_dbus_init failed \n");
+               _ERR("bm_listener_dbus_init failed \n"); */
 
        /*  Wifi callbacks */
        if (!bm_wifi_subscribe_listeners())
@@ -2250,9 +2221,9 @@ int bd_deinitialize_listeners()
                tel_deinit(handle);
        }
 
-       /*Dbus Deinitialize*/
+       /*Dbus Deinitialize*
        if (bm_listener_dbus_deinit())
-               _ERR("failed to de-init dbus ");
+               _ERR("failed to de-init dbus "); */
 
        /* de-initialize pthread attributes */
        if (pthread_attr_destroy(&attr) != 0)
index 177d9c6..3142f2f 100644 (file)
@@ -258,15 +258,20 @@ static int bm_set_dbus_interface_handles(BatteryMonitorIface *iface)
 {
        ENTER;
 
-       BM_RETURN_VAL((iface != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, "interface handle is null");
+       BM_RETURN_VAL((iface != NULL), {}, \
+               BATTERY_MONITOR_ERROR_INVALID_PARAMETER, "interface handle is null");
 
-       iface->handle_get_mah_usage_by_app_id_for_resource_id_custom_interval = &bm_get_mah_usage_by_app_id_for_resource_id_custom_interval;
+       iface->handle_get_mah_usage_by_app_id_for_resource_id_custom_interval = \
+                               &bm_get_mah_usage_by_app_id_for_resource_id_custom_interval;
 
-       iface->handle_get_total_mah_usage_by_app_id_custom_interval = &bm_get_total_mah_usage_by_app_id_custom_interval;
+       iface->handle_get_total_mah_usage_by_app_id_custom_interval = \
+                               &bm_get_total_mah_usage_by_app_id_custom_interval;
 
-       iface->handle_get_total_mah_usage_by_resource_id_custom_interval = &bm_get_total_mah_usage_by_resource_id_custom_interval;
+       iface->handle_get_total_mah_usage_by_resource_id_custom_interval = \
+                               &bm_get_total_mah_usage_by_resource_id_custom_interval;
 
-       iface->handle_get_usage_handle_by_app_id_for_all_resource_id_custom_interval = &bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval;
+       iface->handle_get_usage_handle_by_app_id_for_all_resource_id_custom_interval = \
+                               &bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval;
 
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
@@ -298,6 +303,9 @@ static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpoi
                return;
        }
 
+       /* set dbus connection object */
+       bm_set_dbus_connection_obj(g_dbus_interface_skeleton_get_connection(interface));
+
        _INFO("connecting battery-monitor signals start");
 
        if (BATTERY_MONITOR_ERROR_NONE != bm_set_dbus_interface_handles(iface)) {
index 7961a56..af27291 100644 (file)
@@ -23,6 +23,7 @@
 #include "bm_common.h"
 
 static cynara *p_cynara;
+GDBusConnection* connection_obj = NULL;
 
 GDBusErrorEntry bm_svc_errors[] = {
        {BATTERY_MONITOR_ERROR_NONE, BATTERY_MONITOR_SVC_ERROR_PREFIX".NoError"},
@@ -311,6 +312,25 @@ const char *bm_get_resource_id_string(gint resource_id)
        }
 }
 
+int bm_set_dbus_connection_obj(GDBusConnection* conn)
+{
+       BM_CHECK_INPUT_PARAM(conn);
+
+       connection_obj = conn;
+
+       return BATTERY_MONITOR_ERROR_NONE;
+}
+
+GDBusConnection* bm_get_dbus_connection_obj(void)
+{
+       if (connection_obj == NULL) {
+               _ERR("connection object not available");
+               return NULL;
+       }
+
+       return connection_obj;
+}
+
 void bm_data_free(gpointer data)
 {
        ENTER;