#include <ITapiNetwork.h>
#include <glib.h>
#include <device/battery-internal.h>
+#include <libsyscommon/libgdbus.h>
#include "bm_listeners.h"
#include "bm_dbg.h"
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) {
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
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
_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 */
#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"
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);
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");
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);
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");
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);
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");
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;
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;
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");
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;
}