Use libsyscommon for dbus
authorlokilee73 <changjoo.lee@samsung.com>
Tue, 16 Feb 2021 07:53:55 +0000 (16:53 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Wed, 17 Feb 2021 04:33:53 +0000 (13:33 +0900)
Change-Id: Ic17d0180d14107f631d5c77d4f69fa3e9394a53b
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
hw/battery/CMakeLists.txt
hw/battery/battery.c
hw/dbus.c [deleted file]
hw/dbus.h [deleted file]
hw/external_connection/CMakeLists.txt
hw/external_connection/external_connection.c

index cbea2579580686aec6e8339e119324f8a855ceca..e17fce4cf3813c04f23822eef484145c03a3020e 100644 (file)
@@ -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)
index 0fd3b4c0097f4ef6abfb1bd37ca5d1029ce46544..fa45c73559bc893324327b1516268f411a26089d 100644 (file)
@@ -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 (file)
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 (file)
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
index ca1da2ffe487752a28f231f9584243da12c23a22..70b2fed13b118c1966b5e0435545a74bf014afcd 100644 (file)
@@ -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)
index 7fe0127e8be378f373b2d9513ae82a7ad8d1f364..e1a09e08d6d1e85385d8d449e5564bd794c3970b 100644 (file)
@@ -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;
 }