summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlokilee73 <changjoo.lee@samsung.com>2021-02-16 16:53:55 +0900
committerlokilee73 <changjoo.lee@samsung.com>2021-02-17 13:33:53 +0900
commit3294e2d04708ce91ce4bcb94dc2aee34490eb91b (patch)
treed899d46ba9ae67fd1aaf32afee769e795eecddb3
parent07bd14990fbbdc4b08545b19d2fdb9dcdd3ea498 (diff)
downloaddevice-emulator-3294e2d04708ce91ce4bcb94dc2aee34490eb91b.tar.gz
device-emulator-3294e2d04708ce91ce4bcb94dc2aee34490eb91b.tar.bz2
device-emulator-3294e2d04708ce91ce4bcb94dc2aee34490eb91b.zip
Use libsyscommon for dbus
Change-Id: Ic17d0180d14107f631d5c77d4f69fa3e9394a53b Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
-rw-r--r--hw/battery/CMakeLists.txt4
-rw-r--r--hw/battery/battery.c13
-rw-r--r--hw/dbus.c76
-rw-r--r--hw/dbus.h30
-rw-r--r--hw/external_connection/CMakeLists.txt4
-rw-r--r--hw/external_connection/external_connection.c15
6 files changed, 18 insertions, 124 deletions
diff --git a/hw/battery/CMakeLists.txt b/hw/battery/CMakeLists.txt
index cbea257..e17fce4 100644
--- a/hw/battery/CMakeLists.txt
+++ b/hw/battery/CMakeLists.txt
@@ -4,7 +4,7 @@ PROJECT(hal-backend-device-battery C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-battery_pkgs REQUIRED hal-backend-device-common glib-2.0 gio-2.0)
+pkg_check_modules(hal-backend-device-battery_pkgs REQUIRED hal-backend-device-common glib-2.0 gio-2.0 libsyscommon)
FOREACH(flag ${hal-backend-device-battery_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +13,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE battery.c ../dbus.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE battery.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-battery_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/battery/battery.c b/hw/battery/battery.c
index 0fd3b4c..fa45c73 100644
--- a/hw/battery/battery.c
+++ b/hw/battery/battery.c
@@ -28,7 +28,7 @@
#include <hal/hal-common-interface.h>
#include <libsyscommon/file.h>
-#include "../dbus.h"
+#include <libsyscommon/dbus-system.h>
#include </hal/include/device/hal-backend-common.h>
@@ -47,7 +47,7 @@ static struct signal_data {
void *data;
} sdata = { 0, };
-static int id; /* signal handler id */
+static guint signal_id; /* signal handler id */
static int get_power_source(int online, char **src)
{
@@ -135,10 +135,10 @@ static int battery_register_changed_event(
return -EEXIST;
}
- ret = register_dbus_signal(BATTERY_OBJECT,
+ signal_id = subscribe_dbus_signal(NULL, BATTERY_OBJECT,
BATTERY_IFACE, BATTERY_SIGNAL,
- signal_delivered, &sdata, &id);
- if (ret < 0) {
+ signal_delivered, &sdata, NULL);
+ if (signal_id < 0) {
_E("Failed to register signal");
return -ENOMEM;
}
@@ -152,7 +152,8 @@ static int battery_register_changed_event(
static void battery_unregister_changed_event(
BatteryUpdated updated_cb)
{
- unregister_dbus_signal(&id);
+ unsubscribe_dbus_signal(NULL, signal_id);
+ signal_id = 0;
sdata.updated_cb = NULL;
sdata.data = NULL;
}
diff --git a/hw/dbus.c b/hw/dbus.c
deleted file mode 100644
index a7eeaeb..0000000
--- a/hw/dbus.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * device-node
- *
- * 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 "dbus.h"
-
-#include </hal/include/device/hal-backend-common.h>
-
-int register_dbus_signal(const char *object,
- const char *iface, const char *signal,
- GDBusSignalCallback callback, void *data, int *id)
-{
- GError *err = NULL;
- GDBusConnection *conn;
- int sid;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
-
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!conn) {
- _E("fail to get dbus connection : %s", err->message);
- g_clear_error(&err);
- return -EPERM;
- }
-
- /* subscribe signal */
- sid = g_dbus_connection_signal_subscribe(conn,
- NULL, iface, signal, object,
- NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- callback, data, NULL);
- if (sid == 0) {
- _E("fail to connect %s signal", signal);
- return -EPERM;
- }
-
- if (id)
- *id = sid;
-
- return 0;
-}
-
-void unregister_dbus_signal(int *id)
-{
- GError *err = NULL;
- GDBusConnection *conn;
-
- if (!id || *id <= 0)
- return;
-
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!conn) {
- _E("fail to get dbus connection : %s", err->message);
- g_clear_error(&err);
- return;
- }
-
- /* unsubscribe signal */
- g_dbus_connection_signal_unsubscribe(conn, *id);
- *id = 0;
-}
diff --git a/hw/dbus.h b/hw/dbus.h
deleted file mode 100644
index 9198633..0000000
--- a/hw/dbus.h
+++ /dev/null
@@ -1,30 +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 __HW_DEFAULT_DBUS_H__
-#define __HW_DEFAULT_DBUS_H__
-
-#include <stdio.h>
-#include <errno.h>
-#include <gio/gio.h>
-
-int register_dbus_signal(const char *object,
- const char *iface, const char *signal,
- GDBusSignalCallback callback, void *data, int *id);
-void unregister_dbus_signal(int *id);
-
-#endif
diff --git a/hw/external_connection/CMakeLists.txt b/hw/external_connection/CMakeLists.txt
index ca1da2f..70b2fed 100644
--- a/hw/external_connection/CMakeLists.txt
+++ b/hw/external_connection/CMakeLists.txt
@@ -4,7 +4,7 @@ PROJECT(hal-backend-device-external-connection C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-external-connection_pkgs REQUIRED hal-backend-device-common glib-2.0 gio-2.0)
+pkg_check_modules(hal-backend-device-external-connection_pkgs REQUIRED hal-backend-device-common glib-2.0 gio-2.0 libsyscommon)
FOREACH(flag ${hal-backend-device-external-connection_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +13,6 @@ ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-ADD_LIBRARY(${PROJECT_NAME} MODULE external_connection.c ../dbus.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE external_connection.c)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-external-connection_pkgs_LDFLAGS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/external_connection/external_connection.c b/hw/external_connection/external_connection.c
index 7fe0127..e1a09e0 100644
--- a/hw/external_connection/external_connection.c
+++ b/hw/external_connection/external_connection.c
@@ -29,7 +29,7 @@
#include <hal/hal-common-interface.h>
#include <libsyscommon/file.h>
-#include "../dbus.h"
+#include <libsyscommon/dbus-system.h>
#include </hal/include/device/hal-backend-common.h>
@@ -57,7 +57,7 @@ struct extcon_device {
{ EXTCON_EARJACK, EXTERNAL_CONNECTION_HEADPHONE, EXTCON_EARJACK_PATH, },
};
-static int id; /* signal handler id */
+static guint signal_id; /* signal handler id */
static struct signal_data {
ConnectionUpdated updated_cb;
@@ -116,17 +116,15 @@ out:
static int external_connection_register_changed_event(
ConnectionUpdated updated_cb, void *data)
{
- int ret;
-
if (sdata.updated_cb) {
_E("update callback is already registered");
return -EEXIST;
}
- ret = register_dbus_signal(EXTCON_OBJECT,
+ signal_id = subscribe_dbus_signal(NULL, EXTCON_OBJECT,
EXTCON_IFACE, EXTCON_SIGNAL,
- signal_delivered, &sdata, &id);
- if (ret < 0) {
+ signal_delivered, &sdata, NULL);
+ if (signal_id < 0) {
_E("Failed to register signal");
return -ENOMEM;
}
@@ -140,7 +138,8 @@ static int external_connection_register_changed_event(
static void external_connection_unregister_changed_event(
ConnectionUpdated updated_cb)
{
- unregister_dbus_signal(&id);
+ unsubscribe_dbus_signal(NULL, signal_id);
+ signal_id = 0;
sdata.updated_cb = NULL;
sdata.data = NULL;
}