Use only hal-rootstrap package to build 86/314086/1 accepted/tizen/unified/20240711.011431 accepted/tizen/unified/dev/20240711.085706
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 5 Jul 2024 04:41:03 +0000 (13:41 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 5 Jul 2024 04:41:03 +0000 (13:41 +0900)
As support hal-abi-versioning, the hal-backend package should be built
using only the hal-rootstrap.
Other packages not included in the hal-roostrap have been deleted to remove dependencies.
util is added to replace functions of dlog and libsyscommon package.

Change-Id: I5ba534c5b52a201b0cc4fba999a04b25970636c3
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
14 files changed:
CMakeLists.txt
hw/battery/CMakeLists.txt
hw/battery/battery.c
hw/display/CMakeLists.txt
hw/display/display.c
hw/external_connection/CMakeLists.txt
hw/external_connection/external_connection.c
hw/haptic/CMakeLists.txt
hw/haptic/emulator.c
hw/memory/CMakeLists.txt
hw/memory/memory.c
include/util.h [new file with mode: 0644]
packaging/hal-backend-device-emulator.spec
src/util.c [new file with mode: 0644]

index 4a9f6f67b57557fff223a52783f07cc051e435ab..70275fc62b01c2abb1329d8d8b7b9d8de59a9179 100644 (file)
@@ -14,7 +14,7 @@ IF(ENABLE_DLOG STREQUAL on)
 ENDIF()
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED hal-backend-device-common)
+pkg_check_modules(pkgs REQUIRED hal-rootstrap)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -24,6 +24,8 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror")
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION ${HAL_LICENSE_DIR}/${PROJECT_NAME})
 
 ADD_SUBDIRECTORY(hw/battery)
index e17fce4cf3813c04f23822eef484145c03a3020e..15ca4108412aa7baeb92f737cc43568b2810211b 100644 (file)
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-battery C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
 INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-battery_pkgs REQUIRED hal-backend-device-common glib-2.0 gio-2.0 libsyscommon)
+pkg_check_modules(hal-backend-device-battery_pkgs REQUIRED hal-rootstrap)
 
 FOREACH(flag ${hal-backend-device-battery_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,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)
+ADD_LIBRARY(${PROJECT_NAME} MODULE battery.c ${CMAKE_SOURCE_DIR}/src/util.c)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-battery_pkgs_LDFLAGS})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
index 5d21d940a72208595a77f374a165f9a83533f0fb..74876295573704df78f91486a6e8da0e6b491e8b 100644 (file)
 
 #include <hal/hal-device-battery-interface.h>
 #include <hal/hal-common-interface.h>
-#include <libsyscommon/file.h>
 
-#include <libsyscommon/libgdbus.h>
-
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
 
 #define BATTERY_BUS      "org.tizen.system.deviced"
 #define BATTERY_OBJECT   "/Org/Tizen/System/DeviceD/SysNoti"
@@ -50,6 +47,7 @@ static struct signal_data {
 } sdata = { 0, };
 
 static guint signal_id; /* signal handler id */
+static dbus_handle_s *dh;
 
 static int get_power_source(int online, hal_device_battery_power_source_type_e *src)
 {
@@ -141,9 +139,22 @@ static int battery_register_changed_event(
                return -EEXIST;
        }
 
-       signal_id = gdbus_signal_subscribe(NULL, BATTERY_OBJECT,
-                       BATTERY_IFACE, BATTERY_SIGNAL,
-                       signal_delivered, &sdata, NULL);
+       if (!dh) {
+               dh = (dbus_handle_s*)dbus_get_default_connection();
+               if (!dh) {
+                       _E("failed to get default connection, bustype:%d", (int)dbus_get_default_bus_type());
+                       return -EPERM;
+               }
+       }
+
+       if (!dh->conn) {
+               _E("connection is null. check bus status");
+               return -EPERM;
+       }
+
+       signal_id = g_dbus_connection_signal_subscribe(dh->conn, NULL, BATTERY_IFACE, BATTERY_SIGNAL, BATTERY_OBJECT, NULL,
+                               G_DBUS_SIGNAL_FLAGS_NONE, signal_delivered, &sdata, NULL);
+
        if (signal_id <= 0) {
                _E("Failed to register signal");
                return -ENOMEM;
@@ -159,7 +170,20 @@ static void battery_unregister_changed_event(
                hal_device_battery_updated_cb updated_cb)
 {
        if (signal_id > 0) {
-               gdbus_signal_unsubscribe(NULL, signal_id);
+               if (!dh) {
+                       dh = (dbus_handle_s*)dbus_get_default_connection();
+                       if (!dh) {
+                               _E("failed to get default connection, bustype:%d", (int)dbus_get_default_bus_type());
+                               return;
+                       }
+               }
+
+               if (!dh->conn) {
+                       _E("connection is null. check bus status");
+                       return;
+               }
+
+               g_dbus_connection_signal_unsubscribe(dh->conn, signal_id);
                signal_id = 0;
        }
        sdata.updated_cb = NULL;
@@ -184,7 +208,7 @@ static int battery_get_current_state(
 
        info.name = BATTERY_HARDWARE_DEVICE_ID;
 
-       ret = sys_get_str(FILE_BATTERY_CAPACITY, capacity_str, sizeof(capacity_str));
+       ret = sysfs_read_str(FILE_BATTERY_CAPACITY, capacity_str, sizeof(capacity_str));
        if (ret < 0) {
                _E("Failed to get value of (%s, %d)", FILE_BATTERY_CAPACITY, ret);
                return ret;
@@ -194,24 +218,24 @@ static int battery_get_current_state(
           it sometimes returns an empty string. */
        if (capacity_str[0] == 0) {
                _E("/sys/class/power_supply/battery/capacity returns null string, retry read it again");
-               ret = sys_get_str(FILE_BATTERY_CAPACITY, capacity_str, sizeof(capacity_str));
+               ret = sysfs_read_str(FILE_BATTERY_CAPACITY, capacity_str, sizeof(capacity_str));
                if (ret < 0) {
                        _E("Failed to get value of (%s, %d)", FILE_BATTERY_CAPACITY, ret);
                        return ret;
                }
        }
 
-       ret = sys_get_str(FILE_BATTERY_CHARGER_ONLINE, charger_str, sizeof(charger_str));
+       ret = sysfs_read_str(FILE_BATTERY_CHARGER_ONLINE, charger_str, sizeof(charger_str));
        if (ret < 0) {
                _E("Failed to get value of (%s, %d)", FILE_BATTERY_CHARGER_ONLINE, ret);
                return ret;
        }
-       ret = sys_get_str(FILE_BATTERY_CHARGE_FULL, charge_full_str, sizeof(charge_full_str));
+       ret = sysfs_read_str(FILE_BATTERY_CHARGE_FULL, charge_full_str, sizeof(charge_full_str));
        if (ret < 0) {
                _E("Failed to get value of (%s, %d)", FILE_BATTERY_CHARGE_FULL, ret);
                return ret;
        }
-       ret = sys_get_str(FILE_BATTERY_CHARGE_NOW, charge_now_str, sizeof(charge_now_str));
+       ret = sysfs_read_str(FILE_BATTERY_CHARGE_NOW, charge_now_str, sizeof(charge_now_str));
        if (ret < 0) {
                _E("Failed to get value of (%s, %d)", FILE_BATTERY_CHARGE_NOW, ret);
                return ret;
index 1db4a9e955fa9ead52823248c2f0ad10c264a706..7bf1a4bfb8f0808cd5a92f241ea862073c412c5c 100644 (file)
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-display C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
 INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-display_pkgs REQUIRED hal-backend-device-common libsyscommon)
+pkg_check_modules(hal-backend-device-display_pkgs REQUIRED hal-rootstrap)
 
 FOREACH(flag ${display_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,6 @@ ENDFOREACH(flag)
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
-ADD_LIBRARY(${PROJECT_NAME} MODULE display.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE display.c ${CMAKE_SOURCE_DIR}/src/util.c)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-display_pkgs_LDFLAGS})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
index d010f6078215fc081fbd1e543921adfc35e1805f..63ab311489464966ed67e2422c9544d96f60917f 100644 (file)
@@ -25,9 +25,8 @@
 
 #include <hal/hal-device-display-interface.h>
 #include <hal/hal-common-interface.h>
-#include <libsyscommon/file.h>
 
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
 
 #ifndef BACKLIGHT_PATH
 #define BACKLIGHT_PATH  "/sys/class/backlight/emulator"
@@ -42,7 +41,7 @@ static int display_get_max_brightness(int *val)
                return -EINVAL;
 
        if (max < 0) {
-               r = sys_get_int(BACKLIGHT_PATH"/max_brightness", &max);
+               r = sysfs_read_int(BACKLIGHT_PATH"/max_brightness", &max);
                if (r < 0)
                        return r;
        }
@@ -60,7 +59,7 @@ static int display_get_brightness(int *brightness)
                return -EINVAL;
        }
 
-       r = sys_get_int(BACKLIGHT_PATH"/brightness", &v);
+       r = sysfs_read_int(BACKLIGHT_PATH"/brightness", &v);
        if (r < 0) {
                _E("fail to get brightness (errno:%d)", r);
                return r;
@@ -85,7 +84,7 @@ static int display_set_brightness(int brightness)
                return -EINVAL;
        }
 
-       r = sys_set_int(BACKLIGHT_PATH"/brightness", brightness);
+       r = sysfs_write_int(BACKLIGHT_PATH"/brightness", brightness);
        if (r < 0) {
                _E("fail to set brightness (errno:%d)", r);
                return r;
index 70b2fed13b118c1966b5e0435545a74bf014afcd..7b9c6ed9ca05712ee7c93a9aae15795752973321 100644 (file)
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-external-connection C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
 INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-external-connection_pkgs REQUIRED hal-backend-device-common glib-2.0 gio-2.0 libsyscommon)
+pkg_check_modules(hal-backend-device-external-connection_pkgs REQUIRED hal-rootstrap)
 
 FOREACH(flag ${hal-backend-device-external-connection_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,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)
+ADD_LIBRARY(${PROJECT_NAME} MODULE external_connection.c ${CMAKE_SOURCE_DIR}/src/util.c)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-external-connection_pkgs_LDFLAGS})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
index 09bfd1128c1c5d69d972a546dade98278ea3a84e..08d6db2108f7fde8d4e4d909f2148a42d19711e8 100644 (file)
 
 #include <hal/hal-device-external_connection-interface.h>
 #include <hal/hal-common-interface.h>
-#include <libsyscommon/file.h>
 
-#include <libsyscommon/libgdbus.h>
-
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
 
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
@@ -64,6 +61,8 @@ static struct signal_data {
        void *data;
 } sdata = { 0, };
 
+static dbus_handle_s *dh;
+
 static void signal_delivered(GDBusConnection *conn,
                const gchar *sender,
                const gchar *object,
@@ -121,9 +120,22 @@ static int external_connection_register_changed_event(
                return -EEXIST;
        }
 
-       signal_id = gdbus_signal_subscribe(NULL, EXTCON_OBJECT,
-                       EXTCON_IFACE, EXTCON_SIGNAL,
-                       signal_delivered, &sdata, NULL);
+       if (!dh) {
+               dh = (dbus_handle_s*)dbus_get_default_connection();
+               if (!dh) {
+                       _E("failed to get default connection, bustype:%d", (int)dbus_get_default_bus_type());
+                       return -EPERM;
+               }
+       }
+
+       if (!dh->conn) {
+               _E("connection is null. check bus status");
+               return -EPERM;
+       }
+
+       signal_id = g_dbus_connection_signal_subscribe(dh->conn, NULL, EXTCON_IFACE, EXTCON_SIGNAL, EXTCON_OBJECT, NULL,
+                               G_DBUS_SIGNAL_FLAGS_NONE, signal_delivered, &sdata, NULL);
+
        if (signal_id <= 0) {
                _E("Failed to register signal");
                return -ENOMEM;
@@ -139,7 +151,20 @@ static void external_connection_unregister_changed_event(
                hal_device_external_connection_updated_cb updated_cb)
 {
        if (signal_id > 0) {
-               gdbus_signal_unsubscribe(NULL, signal_id);
+               if (!dh) {
+                       dh = (dbus_handle_s*)dbus_get_default_connection();
+                       if (!dh) {
+                               _E("failed to get default connection, bustype:%d", (int)dbus_get_default_bus_type());
+                               return;
+                       }
+               }
+
+               if (!dh->conn) {
+                       _E("connection is null. check bus status");
+                       return;
+               }
+
+               g_dbus_connection_signal_unsubscribe(dh->conn, signal_id);
                signal_id = 0;
        }
        sdata.updated_cb = NULL;
@@ -157,7 +182,7 @@ static int external_connection_get_current_state(
                return -EINVAL;
 
        for (i = 0 ; i < ARRAY_SIZE(extcon_devices) ; i++) {
-               ret = sys_get_int(extcon_devices[i].path, &val);
+               ret = sysfs_read_int(extcon_devices[i].path, &val);
                if (ret < 0) {
                        _E("Failed to get value of (%s, ret:%d)",
                                        extcon_devices[i].path, ret);
index 0c53a66a6164cddf8f633a7c3940c4f6d6b34d36..1386c433445ae1581257782d6517ad5967ccf20e 100644 (file)
@@ -3,12 +3,10 @@ PROJECT(hal-backend-device-haptic C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
 INCLUDE(FindPkgConfig)
-pkg_check_modules(haptic_pkgs REQUIRED
-               hal-backend-device-common
-               glib-2.0
-               libsyscommon
-               capi-system-info)
+pkg_check_modules(haptic_pkgs REQUIRED hal-rootstrap)
 
 FOREACH(flag ${haptic_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -17,7 +15,7 @@ ENDFOREACH(flag)
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
-ADD_LIBRARY(${PROJECT_NAME} MODULE emulator.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE emulator.c ${CMAKE_SOURCE_DIR}/src/util.c)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${haptic_pkgs_LDFLAGS})
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
index 48da52519dd6383f04d765d805791cfd105b60d0..eb8044297da6d324c3efb805052f8493316f1f3b 100644 (file)
 #include <errno.h>
 #include <stdbool.h>
 #include <system_info.h>
-#include <libsyscommon/list.h>
 #include <hal/hal-device-haptic-interface.h>
 
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
 
 static GList *handle_list;
 static int unique_number = 0;
@@ -46,12 +45,12 @@ static int open_device(int *device_handle)
 
        while (found != true) {
                ++unique_number;
-               elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)unique_number);
+               elem = g_list_find(handle_list, (gpointer)(long)unique_number);
                if (!elem)
                        found = true;
        }
        handle = unique_number;
-       SYS_G_LIST_APPEND(handle_list, (gpointer)(long)handle);
+       handle_list = g_list_append(handle_list, (gpointer)(long)handle);
 
        if (device_handle)
                *device_handle = handle;
@@ -61,7 +60,7 @@ static int open_device(int *device_handle)
 
 static int close_device(int device_handle)
 {
-       SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)device_handle);
+       handle_list = g_list_remove(handle_list, (gpointer)(long)device_handle);
 
        return 0;
 }
@@ -70,7 +69,7 @@ static int vibrate_monotone(int device_handle, int duration, int frequency, int
 {
        GList *elem;
 
-       elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)device_handle);
+       elem = g_list_find(handle_list, (gpointer)(long)device_handle);
        if (!elem)
                return -EINVAL;
 
@@ -81,7 +80,7 @@ static int stop_device(int device_handle)
 {
        GList *elem;
 
-       elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)device_handle);
+       elem = g_list_find(handle_list, (gpointer)(long)device_handle);
        if (!elem)
                return -EINVAL;
 
index a35248a5828afb5efd9c345ad3a99a4e8b04f34f..77b4f9c6a3a9b8bfa08e965e95533b1e037afb71 100644 (file)
@@ -3,8 +3,10 @@ PROJECT(hal-backend-device-memory C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
 INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED dlog)
+pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED hal-rootstrap)
 
 FOREACH(flag ${hal-backend-device-memory_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -13,6 +15,6 @@ ENDFOREACH(flag)
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
-ADD_LIBRARY(${PROJECT_NAME} MODULE memory.c)
+ADD_LIBRARY(${PROJECT_NAME} MODULE memory.c ${CMAKE_SOURCE_DIR}/src/util.c)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-memory_pkgs_LDFLAGS})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
index 66ed8a7f09cc1676c279d77fe42d3dc0f2544a41..2afd2de1b00f08b649a916fdfbbcd7671bab7e57 100644 (file)
@@ -21,7 +21,7 @@
 #include <hal/hal-device-memory-interface.h>
 #include <hal/hal-common-interface.h>
 
-#include </hal/include/device/hal-backend-common.h>
+#include "util.h"
 
 static int memory_get_gpu_info(const int pid, hal_device_memory_gpu_info_s *info)
 {
diff --git a/include/util.h b/include/util.h
new file mode 100644 (file)
index 0000000..4bd3bcc
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2024 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.
+ */
+#include <assert.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib-unix.h>
+#include <gio/gunixfdlist.h>
+#include <stdarg.h>
+
+#ifdef FEATURE_DLOG
+       #define LOG_TAG "HAL_BACKEND_DEVICE_EMULATOR"
+       #include <dlog.h>
+       #define _D(fmt, args...)        dlog_print(DLOG_DEBUG, LOG_TAG, fmt, ##args)
+       #define _I(fmt, args...)        dlog_print(DLOG_INFO, LOG_TAG, fmt, ##args)
+       #define _W(fmt, args...)        dlog_print(DLOG_WARN, LOG_TAG, fmt, ##args)
+       #define _E(fmt, args...)        dlog_print(DLOG_ERROR, LOG_TAG, fmt, ##args)
+#else
+       #define _D(x, ...)
+       #define _I(x, ...)
+       #define _W(x, ...)
+       #define _E(x, ...)
+#endif
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+#define MAX_BUF_SIZE   255
+
+typedef struct {
+       GDBusConnection *conn;
+       GBusType bus_type;
+       gboolean priv;
+       GList *list_names;      /* dbus_name */
+       GList *list_object;     /* dbus_object_handle_s */
+       pthread_mutex_t mutex;
+} dbus_handle_s;
+
+int sysfs_read_int(char *path, int *val);
+int sysfs_read_str(char *path, char *str, int len);
+int sysfs_write_int(char *path, int val);
+int sysfs_write_str(char *path, char *str);
+dbus_handle_s * dbus_get_default_connection(void);
+GBusType dbus_get_default_bus_type(void);
index 1587989a8e60eab795e79ffb7b949f89efed0bef..4cdd1391737a6c07d805898c29d02c1112e67e70 100644 (file)
@@ -10,13 +10,7 @@ ExclusiveArch:      %{ix86} x86_64 aarch64 %{arm}
 Requires(post):     /sbin/ldconfig
 Requires(postun):   /sbin/ldconfig
 BuildRequires:      cmake
-BuildRequires:      pkgconfig(glib-2.0)
-BuildRequires:      pkgconfig(gio-2.0)
-BuildRequires:      pkgconfig(hal-api-common)
-BuildRequires:      pkgconfig(hal-api-device)
-BuildRequires:      pkgconfig(libsyscommon)
-BuildRequires:      pkgconfig(capi-system-info)
-BuildRequires:      pkgconfig(hal-backend-device-common)
+BuildRequires:      pkgconfig(hal-rootstrap)
 
 %description
 Device HAL backend drivers for emulator targets
diff --git a/src/util.c b/src/util.c
new file mode 100644 (file)
index 0000000..4fb5d1e
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2024 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 <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "util.h"
+
+static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM;
+pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
+/* global shared bus : system, session */
+static dbus_handle_s g_dh[2];
+
+#define dbus_lock(handle) do {\
+       assert(handle);\
+       pthread_mutex_lock(&((handle)->mutex));\
+} while (0);
+
+#define dbus_unlock(handle) do {\
+       assert(handle);\
+       pthread_mutex_unlock(&(handle)->mutex);\
+} while (0);
+
+static int sysfs_read_buf(char *path, char *buf, int len)
+{
+       int r, fd;
+
+       if ((!path) || (!buf) || (len < 0))
+               return -EINVAL;
+
+       fd = open(path, O_RDONLY);
+       if (fd == -1)
+               return -ENOENT;
+
+       r = read(fd, buf, len);
+       close(fd);
+
+       if ((r < 0) || (r > len))
+               return -EIO;
+
+       /* Replace '\n' with space (ascii code is 32) */
+       buf[strcspn(buf, "\n")] = (char)32;
+       buf[r] = '\0';
+
+       return 0;
+}
+
+static int sysfs_write_buf(char *path, char *buf)
+{
+       int w, fd;
+
+       if ((!path) || (!buf))
+               return -EINVAL;
+
+       fd = open(path, O_WRONLY);
+       if (fd == -1)
+               return -ENOENT;
+
+       w = write(fd, buf, strlen(buf));
+       close(fd);
+
+       if (w < 0)
+               return -EIO;
+
+       return 0;
+}
+
+int sysfs_read_int(char *path, int *val)
+{
+       char buf[MAX_BUF_SIZE + 1];
+       int r;
+
+       if ((!path) || (!val))
+               return -EINVAL;
+
+       r = sysfs_read_buf(path, buf, MAX_BUF_SIZE);
+       if (r < 0)
+               return r;
+
+       *val = atoi(buf);
+       return 0;
+}
+
+int sysfs_read_str(char *path, char *str, int len)
+{
+       int r;
+
+       if ((!path) || (!str) || (len <= 0))
+               return -EINVAL;
+
+       r = sysfs_read_buf(path, str, len);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
+
+int sysfs_write_int(char *path, int val)
+{
+       char buf[MAX_BUF_SIZE + 1];
+       int w;
+
+       if (!path)
+               return -EINVAL;
+
+       snprintf(buf, MAX_BUF_SIZE, "%d", val);
+       w = sysfs_write_buf(path, buf);
+       if (w < 0)
+               return w;
+
+       return 0;
+}
+
+int sysfs_write_str(char *path, char *str)
+{
+       int w;
+
+       if ((!path) || (!str))
+               return -EINVAL;
+
+       w = sysfs_write_buf(path, str);
+       if (w < 0)
+               return w;
+
+       return 0;
+}
+
+static GDBusConnection * _get_bus(GBusType bus_type)
+{
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+
+       if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) {
+               _E("Wrong bus_type %d", bus_type);
+               return NULL;
+       }
+
+       conn = g_bus_get_sync(bus_type, NULL, &err);
+       if (!conn || err) {
+               _E("failed to get bus:type:%d, %s\n", bus_type, err->message);
+               g_error_free(err);
+               return NULL;
+       }
+
+       return conn;
+}
+
+/* ref cout is 1 */
+static dbus_handle_s *_dbus_get_connection(GBusType bus_type)
+{
+       int ibus = bus_type - 1;
+       dbus_handle_s *dh = NULL;
+
+       if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) {
+               _E("Unknown bus type %d", bus_type);
+               return NULL;
+       }
+       dh = &g_dh[ibus];
+
+       dbus_lock(dh);
+
+       if (!dh->conn) {
+               dh->conn = _get_bus(bus_type);
+               if (!dh->conn) {
+                       dbus_unlock(dh);
+                       return NULL;
+               }
+               dh->priv = FALSE;
+               dh->bus_type = bus_type;
+       }
+
+       dbus_unlock(dh);
+
+       return dh;
+}
+
+GBusType dbus_get_default_bus_type(void)
+{
+       GBusType type;
+
+       pthread_mutex_lock(&g_mutex);
+       type = g_default_bus_type;
+       pthread_mutex_unlock(&g_mutex);
+
+       return type;
+}
+
+dbus_handle_s* dbus_get_default_connection(void)
+{
+       return _dbus_get_connection(dbus_get_default_bus_type());
+}
\ No newline at end of file