Use libsyscommon for gdbus implementation 67/265267/10
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 13 Oct 2021 10:19:01 +0000 (19:19 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Thu, 14 Oct 2021 06:06:28 +0000 (15:06 +0900)
Change-Id: Id40c6aefd3137e6b4077ee01353f6f52a9f84bb5
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
CMakeLists.txt
include/bm_common.h
include/bm_server.h [deleted file]
include/bm_util.h
packaging/batterymonitor.spec
src/battery_dump/bm_listeners.c
src/bm_server.c
src/bm_util.c

index a4d135c..18f3021 100644 (file)
@@ -26,6 +26,7 @@ pkg_check_modules(pkgs REQUIRED
        vconf
        tapi
        capi-appfw-app-manager
+       libsyscommon
 )
 
 ADD_CUSTOM_COMMAND(
index 33140eb..c279547 100755 (executable)
@@ -34,6 +34,8 @@
 extern "C" {
 #endif
 
+#define ARRAY_SIZE(name)  (sizeof(name)/sizeof(name[0]))
+
 /**
  * @brief      Enumeration for error codes for battery monitor
  * @since_tizen  5.5
diff --git a/include/bm_server.h b/include/bm_server.h
deleted file mode 100644 (file)
index 6719efb..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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 __BM_SERVER_H__
-#define __BM_SERVER_H__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <glib.h>
-
-#include "../battery_monitor_stub.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-BatteryMonitor *batterymonitor_obj = NULL;
-
-gboolean bm_get_mah_usage_by_app_id_for_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               const gchar *app_id, gint resource_id, gint64 start_time, gint64 end_time, gint uid);
-
-gboolean bm_get_total_mah_usage_by_app_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               const gchar *app_id, gint64 start_time, gint64 end_time, gint uid);
-
-gboolean bm_get_total_mah_usage_by_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               gint resource_id, gint64 start_time, gint64 end_time, gint uid);
-
-gboolean bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               const gchar *app_id, gint64 start_time, gint64 end_time, gint uid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __BM_SERVER_H__ */
index dd7ee04..4997b10 100755 (executable)
@@ -57,10 +57,6 @@ const char *bm_get_resource_id_string(gint resource_id);
 
 void bm_get_name_for_pid(pid_t pid, char **pname);
 
-int bm_set_dbus_connection_obj(GDBusConnection* conn);
-
-GDBusConnection* bm_get_dbus_connection_obj(void);
-
 void bd_get_focussed_app_id(char **app_name);
 
 void bm_get_symlink_for_pid(pid_t pid, char **pname);
index 047e2ea..0302184 100644 (file)
@@ -33,6 +33,7 @@ BuildRequires:  pkgconfig(capi-network-connection)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(tapi)
 BuildRequires:  pkgconfig(capi-appfw-app-manager)
+BuildRequires:  pkgconfig(libsyscommon)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index 63c796e..cb90d99 100644 (file)
@@ -22,6 +22,7 @@
 #include <ITapiNetwork.h>
 #include <glib.h>
 #include <device/battery-internal.h>
+#include <libsyscommon/libgdbus.h>
 
 #include "bm_listeners.h"
 #include "bm_dbg.h"
@@ -2298,26 +2299,17 @@ static int bd_subscribe_powerlock_unlock_listener(void)
        ENTER;
        guint ret = 0;
 
-       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, _bd_listener_powerlock_signal_cb,
-                               NULL, NULL);
+       ret = gdbus_signal_subscribe(NULL, DBUS_DEVICED_PATH, DBUS_DEVICED_IFACE,
+                                       DBUS_DEVICED_PL_MEMBER, _bd_listener_powerlock_signal_cb,
+                                       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, _bd_listener_powerunlock_signal_cb,
+       ret = gdbus_signal_subscribe(NULL, DBUS_DEVICED_PATH, DBUS_DEVICED_IFACE,
+                                       DBUS_DEVICED_PU_MEMBER, _bd_listener_powerunlock_signal_cb,
                                        NULL, NULL);
 
        if (ret == 0) {
@@ -2334,25 +2326,18 @@ static int bd_subscribe_sleep_wakeup_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, _bd_listener_sleep_signal_cb, NULL, NULL);
+       ret = gdbus_signal_subscribe(NULL, DBUS_DEVICED_PATH, DBUS_DEVICED_IFACE,
+                                       DBUS_DEVICED_SLEEP_MEMBER, _bd_listener_sleep_signal_cb,
+                                       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, _bd_listener_wakeup_signal_cb, NULL, NULL);
+       ret = gdbus_signal_subscribe(NULL, DBUS_DEVICED_PATH, DBUS_DEVICED_IFACE,
+                                       DBUS_DEVICED_WAKEUP_MEMBER, _bd_listener_wakeup_signal_cb,
+                                       NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscrive bus signal"); //LCOV_EXCL_LINE System Error
@@ -2368,36 +2353,27 @@ static int bd_subscribe_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, DBUS_AUL_APP,
-                               DBUS_AUL_APP_STATUS_CHANGE_MEMBER, DBUS_AUL_APP_PATH, NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE, _bd_listener_app_status_signal_cb, NULL, NULL);
+       ret = gdbus_signal_subscribe(NULL, DBUS_AUL_APP_PATH, DBUS_AUL_APP,
+                                       DBUS_AUL_APP_STATUS_CHANGE_MEMBER, _bd_listener_app_status_signal_cb,
+                                       NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscribe signal - appStatusChange"); //LCOV_EXCL_LINE System Error
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, DBUS_AUL_APP,
-                               DBUS_AUL_APP_TERMINATE_MEMBER, DBUS_AUL_APP_PATH, NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE, _bd_listener_app_terminate_signal_cb,
-                               NULL, NULL);
+       ret = gdbus_signal_subscribe(NULL, DBUS_AUL_APP_PATH, DBUS_AUL_APP,
+                                       DBUS_AUL_APP_TERMINATE_MEMBER, _bd_listener_app_terminate_signal_cb,
+                                       NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscribe signal - appTerminate"); //LCOV_EXCL_LINE System Error
                return 1;
        }
 
-       ret = g_dbus_connection_signal_subscribe(dbus_connection, NULL, DBUS_AUL_APP,
-                               DBUS_AUL_APP_LAUNCH_MEMBER, DBUS_AUL_APP_PATH, NULL,
-                               G_DBUS_SIGNAL_FLAGS_NONE, _bd_listener_app_launch_signal_cb,
-                               NULL, NULL);
+       ret = gdbus_signal_subscribe(NULL, DBUS_AUL_APP_PATH, DBUS_AUL_APP,
+                                       DBUS_AUL_APP_LAUNCH_MEMBER, _bd_listener_app_launch_signal_cb,
+                                       NULL, NULL);
 
        if (ret == 0) {
                _ERR("Failed to subscribe signal - appLaunch"); //LCOV_EXCL_LINE System Error
@@ -2566,7 +2542,8 @@ int bd_initialize_listeners(void)
                _ERR("pthread_attr_init failed");
                return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
        }
-               if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
+
+       if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
                _ERR("pthread_attr_setdetachstate failed");
 
        /*  Wifi callbacks */
index 3d0f149..8defd9a 100644 (file)
@@ -19,9 +19,9 @@
 #include <cynara-client.h>
 #include <cynara-session.h>
 #include <cynara-creds-gdbus.h>
+#include <libsyscommon/libgdbus.h>
 
 #include "bm_dbg.h"
-#include "bm_server.h"
 #include "bm_plugin_manager.h"
 #include "bm_server_db.h"
 #include "bm_power_engine.h"
@@ -67,18 +67,26 @@ static void bm_set_signal_handling_info()
        return;
 }
 
-gboolean
-bm_get_mah_usage_by_app_id_for_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation, const gchar *app_id,
-                                                       gint resource_id, gint64 start_time, gint64 end_time, gint uid)
+static GVariant *bm_get_mah_usage_by_app_id_for_resource_id_custom_interval
+       (GDBusConnection *conn, const gchar *sender, const gchar *path,
+       const gchar *iface, const gchar *name, GVariant *param,
+       GDBusMethodInvocation *invocation, gpointer user_data)
 {
        ENTER;
 
+       gchar *app_id;
+       gint resource_id, uid;
+       gint64 start_time, end_time;
+       double battery_usage = 0;
+
+       g_variant_get(param, "(sixxi)", &app_id, &resource_id, &start_time, &end_time, &uid);
+
        _INFO("app_id [%s], resource_id [%d], start_time [%ld] end_time [%ld]", \
                        app_id, resource_id, (long int)start_time, (long int)end_time);
 
        if (!app_id || (resource_id >= BM_PLUGIN_ID_MAX)) {
                _ERR("invalid function param");
-               return false;
+               goto exit;
        }
 
        int ret_val = bm_check_privilege_battery(invocation);
@@ -87,7 +95,6 @@ bm_get_mah_usage_by_app_id_for_resource_id_custom_interval(BatteryMonitor *obj,
                goto RETURN;
        }
 
-       double battery_usage = 0;
        ret_val = bm_engine_get_mah_usage_by_app_id_for_resource_id_ci(app_id, resource_id, start_time, end_time, &battery_usage);
        if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
                _ERR("failed to get battery usage");
@@ -102,25 +109,34 @@ RETURN:
                g_dbus_method_invocation_return_gerror(invocation, error);
                g_error_free(error);
        } else {
-               battery_monitor_complete_get_mah_usage_by_app_id_for_resource_id_custom_interval(obj, invocation, battery_usage);
+               battery_monitor_complete_get_mah_usage_by_app_id_for_resource_id_custom_interval(NULL, invocation, battery_usage);
        }
 
        EXIT;
-       return true;
+exit:
+       return g_variant_new("(d)", battery_usage);
 }
 
-gboolean
-bm_get_total_mah_usage_by_app_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               const gchar *app_id, gint64 start_time, gint64 end_time, gint uid)
+static GVariant *bm_get_total_mah_usage_by_app_id_custom_interval
+       (GDBusConnection *conn, const gchar *sender, const gchar *path,
+       const gchar *iface, const gchar *name, GVariant *param,
+       GDBusMethodInvocation *invocation, gpointer user_data)
 {
        ENTER;
 
+       gchar *app_id;
+       gint uid;
+       gint64 start_time, end_time;
+       double battery_usage = 0;
+
+       g_variant_get(param, "(sxxi)", &app_id, &start_time, &end_time, &uid);
+
        _INFO("app_id(%s), start_time (%ld), end_time (%ld)", \
                                app_id, (long int)start_time, (long int)end_time);
 
        if (!app_id) {
                _ERR("invalid function param");
-               return false;
+               goto exit;
        }
 
        int ret_val = bm_check_privilege_battery(invocation);
@@ -129,7 +145,6 @@ bm_get_total_mah_usage_by_app_id_custom_interval(BatteryMonitor *obj, GDBusMetho
                goto RETURN;
        }
 
-       double battery_usage = 0;
        ret_val = bm_engine_get_total_mah_usage_by_app_id_ci(app_id, start_time, end_time, &battery_usage);
        if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
                _ERR("failed to get battery usage");
@@ -144,25 +159,33 @@ RETURN:
                g_dbus_method_invocation_return_gerror(invocation, error);
                g_error_free(error);
        } else {
-               battery_monitor_complete_get_total_mah_usage_by_app_id_custom_interval(obj, invocation, battery_usage);
+               battery_monitor_complete_get_total_mah_usage_by_app_id_custom_interval(NULL, invocation, battery_usage);
        }
 
        EXIT;
-       return true;
+exit:
+       return g_variant_new("(d)", battery_usage);
 }
 
-gboolean
-bm_get_total_mah_usage_by_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               gint resource_id, gint64 start_time, gint64 end_time, gint uid)
+static GVariant *bm_get_total_mah_usage_by_resource_id_custom_interval
+       (GDBusConnection *conn, const gchar *sender, const gchar *path,
+       const gchar *iface, const gchar *name, GVariant *param,
+       GDBusMethodInvocation *invocation, gpointer user_data)
 {
        ENTER;
 
+       gint resource_id, uid;
+       gint64 start_time, end_time;
+       double battery_usage = 0;
+
+       g_variant_get(param, "(ixxi)", &resource_id, &start_time, &end_time, &uid);
+
        _INFO("resource_id [%d], start_time [%ld] end_time [%ld]", \
                                        resource_id, (long int)start_time, (long int)end_time);
 
        if (resource_id >= BM_PLUGIN_ID_MAX) {
                _ERR("invalid function param");
-               return false;
+               goto exit;
        }
 
        int ret_val = bm_check_privilege_battery(invocation);
@@ -171,7 +194,6 @@ bm_get_total_mah_usage_by_resource_id_custom_interval(BatteryMonitor *obj, GDBus
                goto RETURN;
        }
 
-       double battery_usage = 0;
        ret_val = bm_engine_get_total_mah_usage_by_resource_id_ci(resource_id, start_time, end_time, &battery_usage);
        if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
                _ERR("failed to get battery usage");
@@ -186,25 +208,34 @@ RETURN:
                g_dbus_method_invocation_return_gerror(invocation, error);
                g_error_free(error);
        } else {
-               battery_monitor_complete_get_total_mah_usage_by_resource_id_custom_interval(obj, invocation, battery_usage);
+               battery_monitor_complete_get_total_mah_usage_by_resource_id_custom_interval(NULL, invocation, battery_usage);
        }
 
        EXIT;
-       return true;
+exit:
+       return g_variant_new("(d)", battery_usage);
 }
 
-gboolean
-bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
-                               const gchar *app_id, gint64 start_time, gint64 end_time, gint uid)
+static GVariant *bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval
+       (GDBusConnection *conn, const gchar *sender, const gchar *path,
+       const gchar *iface, const gchar *name, GVariant *param,
+       GDBusMethodInvocation *invocation, gpointer user_data)
 {
        ENTER;
 
+       gchar *app_id;
+       gint uid;
+       gint64 start_time, end_time;
+       GVariant *battery_variant = NULL;
+
+       g_variant_get(param, "(sxxi)", &app_id, &start_time, &end_time, &uid);
+
        _INFO("app_id [%s], start_time [%ld] end_time [%ld]", \
                        app_id, (long int)start_time, (long int)end_time);
 
        if (!app_id) {
                _ERR("invalid function param");
-               return false;
+               goto exit;
        }
 
        bm_total_consumption_h battery_data = NULL;
@@ -214,7 +245,6 @@ bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(BatteryMonitor
                goto RETURN;
        }
 
-       GVariant *battery_variant = NULL;
        battery_data = (bm_total_consumption_h)calloc(1, sizeof(struct battery_total_consumption_s));
        if (battery_data == NULL) {
                ret_val = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
@@ -243,78 +273,46 @@ RETURN:
                g_dbus_method_invocation_return_gerror(invocation, error);
                g_error_free(error);
        } else {
-               battery_monitor_complete_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(obj, invocation, battery_variant);
+               battery_monitor_complete_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(NULL, invocation, battery_variant);
        }
 
        BM_FREE(battery_data);
 
        EXIT;
-       return true;
-}
-
-static int bm_set_dbus_interface_handles(BatteryMonitorIface *iface)
-{
-       ENTER;
-
-       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_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_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;
+exit:
+       return battery_variant;
 }
 
-static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
+static const dbus_method_s dbus_methods[] = {
+       {"get_mah_usage_by_app_id_for_resource_id_custom_interval", "sixxi", "d",
+               bm_get_mah_usage_by_app_id_for_resource_id_custom_interval},
+       {"get_total_mah_usage_by_app_id_custom_interval", "sxxi", "d",
+               bm_get_total_mah_usage_by_app_id_custom_interval},
+       {"get_total_mah_usage_by_resource_id_custom_interval", "ixxi", "d",
+               bm_get_total_mah_usage_by_resource_id_custom_interval},
+       {"get_usage_handle_by_app_id_for_all_resource_id_custom_interval", "sxxi", "a{sv}",
+               bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval},
+};
+
+static const dbus_interface_u dbus_interface = {
+       .oh     = NULL,
+       .name = BATTERY_MONITOR_DBUS_NAME,
+       .methods = dbus_methods,
+       .nr_methods = ARRAY_SIZE(dbus_methods),
+};
+
+static void after_bus_acquired()
 {
        ENTER;
 
-       _INFO("on_bus_acquired [%s]", name);
-
-       GDBusInterfaceSkeleton* interface = NULL;
+       int ret_val;
 
-       batterymonitor_obj = battery_monitor_skeleton_new();
-       if (batterymonitor_obj == NULL) {
-               _ERR("batterymonitor_obj NULL!!");
-               return;
-       }
-
-       interface = G_DBUS_INTERFACE_SKELETON(batterymonitor_obj);
-       if (!g_dbus_interface_skeleton_export(interface, connection, BATTERY_MONITOR_DBUS_PATH, NULL)) {
-               _ERR("export failed!!");
-               return;
-       }
-
-       BatteryMonitorIface *iface = BATTERY_MONITOR_GET_IFACE(batterymonitor_obj);
-       if (iface == NULL) {
-               _ERR("Failed to get interface");
-               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)) {
-               _ERR("failed to set dbus interface handles");
-               return;
-       }
+       ret_val = gdbus_add_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface);
+       if (ret_val < 0)
+               _ERR("fail to init dbus method(%d)", ret_val);
 
        _INFO("connecting battery-monitor signals end");
 
-       _INFO("on_bus_acquired end [%s]", name);
-
        /* History-Listener initialization after acquiring dbus */
        if (BATTERY_MONITOR_ERROR_NONE !=  bd_initialize_listeners()) {
                _ERR("dump-listeners initialization failed");
@@ -337,28 +335,30 @@ static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointe
 
 static bool initialize_dbus()
 {
+       dbus_handle_h handle = NULL;
+
        ENTER;
 
        _INFO("__initialize_dbus Enter");
 
-       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                       BATTERY_MONITOR_DBUS_NAME,
-                       G_BUS_NAME_OWNER_FLAGS_NONE,
-                       on_bus_acquired,
-                       on_name_acquired,
-                       on_name_lost,
-                       NULL,
-                       NULL);
+       handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, FALSE);
+       if (!handle)
+               _ERR("Failed to get dbus connection.");
+
+       owner_id = gdbus_request_name(handle, BATTERY_MONITOR_DBUS_NAME,
+                               on_name_acquired, on_name_lost);
 
        _INFO("owner_id=[%d]", owner_id);
 
-       if (owner_id == 0) {
+       if (owner_id <= 0) {
                _INFO("gdbus own failed!!");
                return BATTERY_MONITOR_ERROR_NOT_INITIALIZED;
        }
 
        _INFO("g_bus_own_name SUCCESS");
 
+       after_bus_acquired();
+
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
index efefc0f..49ed932 100755 (executable)
@@ -19,6 +19,7 @@
 #include <cynara-client.h>
 #include <cynara-session.h>
 #include <cynara-creds-gdbus.h>
+#include <libsyscommon/libgdbus.h>
 
 #include <errno.h>
 #include <string.h>
@@ -28,7 +29,6 @@
 #include "bm_common.h"
 
 static cynara *p_cynara;
-GDBusConnection* connection_obj = NULL;
 
 enum { PATH_BUFFER_SIZE = 64, BUFFERSIZE = 1024 };
 
@@ -54,43 +54,26 @@ GDBusErrorEntry bm_svc_errors[] = {
        {BATTERY_MONITOR_ERROR_DATABASE_BUSY, BATTERY_MONITOR_SVC_ERROR_PREFIX".DatabaseBusy"},
 };
 
+
 static guint bm_get_client_pid(GDBusMethodInvocation* invoc)
 {
-       const char *name = NULL;
-       name = g_dbus_method_invocation_get_sender(invoc);
-       if (name == NULL) {
+       const char *sender = NULL;
+       sender = g_dbus_method_invocation_get_sender(invoc);
+       if (sender == NULL) {
                _ERR("g_dbus_method_invocation_get_sender failed");
                return -1;
        }
 
-       _INFO("sender=[%s]", name);
-
-       guint pid = -1;
-       GError *error = NULL;
-       GVariant *_ret;
+       _INFO("sender=[%s]", sender);
 
        _INFO("calling GetConnectionUnixProcessID");
-
        GDBusConnection* conn = g_dbus_method_invocation_get_connection(invoc);
-       _ret = g_dbus_connection_call_sync(conn,
-                       FREE_DESKTOP_BUS_NAME,
-                       FREE_DESKTOP_OBJECT_PATH,
-                       FREE_DESKTOP_INTERFACE_NAME,
-                       FREE_DESKTOP_METHOD_NAME,
-                       g_variant_new("(s)", name),
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       &error);
-
-       if (_ret != NULL) {
-               g_variant_get(_ret, "(u)", &pid);
-               g_variant_unref(_ret);
-       }
-
-       _INFO("process Id = [%u]", pid);
-       return pid;
+       if (conn == NULL) {
+               _ERR("g_dbus_method_invocation_get_connection failed");
+               return -1;
+       }
+
+       return gdbus_connection_get_sender_pid(conn, sender);
 }
 
 GQuark bm_error_quark(void)
@@ -368,25 +351,6 @@ void bm_get_symlink_for_pid(pid_t pid, char **pname)
        return;
 }
 
-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 bd_get_focussed_app_id(char **app_name)
 {
        ENTER;