diff options
author | lokilee73 <changjoo.lee@samsung.com> | 2021-01-13 21:25:08 +0900 |
---|---|---|
committer | lokilee73 <changjoo.lee@samsung.com> | 2021-01-13 21:27:37 +0900 |
commit | 85951388de2596cdbe050b7e7f49ce0fa3d5b684 (patch) | |
tree | 7990622ce1c4fbffc96022452dc3445f1b2f0358 | |
parent | da849456eadeaac1533360fad6ee57e90c8be3c0 (diff) | |
download | device-emulator-85951388de2596cdbe050b7e7f49ce0fa3d5b684.tar.gz device-emulator-85951388de2596cdbe050b7e7f49ce0fa3d5b684.tar.bz2 device-emulator-85951388de2596cdbe050b7e7f49ce0fa3d5b684.zip |
Apply next HAL architecture (hal api + backend)
Change-Id: I4a873fecc39384911c0b7c267c63b1b89821b496
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
-rw-r--r-- | hw/battery/CMakeLists.txt | 13 | ||||
-rw-r--r-- | hw/battery/battery.c | 51 | ||||
-rw-r--r-- | hw/common/common.h | 146 | ||||
-rw-r--r-- | hw/display/CMakeLists.txt | 11 | ||||
-rw-r--r-- | hw/display/display.c | 50 | ||||
-rw-r--r-- | hw/external_connection/CMakeLists.txt | 13 | ||||
-rw-r--r-- | hw/external_connection/external_connection.c | 53 | ||||
-rw-r--r-- | packaging/device-manager-plugin-emul.spec | 5 |
8 files changed, 238 insertions, 104 deletions
diff --git a/hw/battery/CMakeLists.txt b/hw/battery/CMakeLists.txt index 5d68e4b..fa59860 100644 --- a/hw/battery/CMakeLists.txt +++ b/hw/battery/CMakeLists.txt @@ -1,12 +1,14 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(battery C) +PROJECT(hal-backend-device-battery C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +INCLUDE_DIRECTORIES(../common) + INCLUDE(FindPkgConfig) -pkg_check_modules(battery_pkgs REQUIRED hwcommon dlog glib-2.0 gio-2.0) +pkg_check_modules(hal-backend-device-battery_pkgs REQUIRED dlog glib-2.0 gio-2.0) -FOREACH(flag ${battery_pkgs_CFLAGS}) +FOREACH(flag ${hal-backend-device-battery_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -14,6 +16,5 @@ 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) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${battery_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-battery_pkgs_LDFLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /hal/lib COMPONENT RuntimeLibraries) diff --git a/hw/battery/battery.c b/hw/battery/battery.c index f4ef137..dca5f1f 100644 --- a/hw/battery/battery.c +++ b/hw/battery/battery.c @@ -24,9 +24,11 @@ #include <linux/limits.h> #include <dirent.h> -#include <hw/battery.h> -#include <hw/shared.h> +#include <hal/device/hal-battery-interface.h> +#include <hal/hal-common-interface.h> + #include "../dbus.h" +#include "common.h" #define BATTERY_BUS "org.tizen.system.deviced" #define BATTERY_OBJECT "/Org/Tizen/System/DeviceD/SysNoti" @@ -250,45 +252,36 @@ static int battery_get_current_state( return 0; } -static int battery_open(struct hw_info *info, - const char *id, struct hw_common **common) +static int battery_init(void **data) { - struct battery_device *battery_dev; - - if (!info || !common) - return -EINVAL; + hal_backend_battery_funcs *battery_funcs; - battery_dev = calloc(1, sizeof(struct battery_device)); - if (!battery_dev) + battery_funcs = calloc(1, sizeof(hal_backend_battery_funcs)); + if (!battery_funcs) return -ENOMEM; - battery_dev->common.info = info; - battery_dev->register_changed_event - = battery_register_changed_event; - battery_dev->unregister_changed_event - = battery_unregister_changed_event; - battery_dev->get_current_state - = battery_get_current_state; + battery_funcs->register_changed_event = battery_register_changed_event; + battery_funcs->unregister_changed_event = battery_unregister_changed_event; + battery_funcs->get_current_state = battery_get_current_state; + + *data = (void *)battery_funcs; - *common = (struct hw_common *)battery_dev; return 0; } -static int battery_close(struct hw_common *common) +static int battery_exit(void *data) { - if (!common) - return -EINVAL; + if (!data) + return 0; - free(common); + free(data); return 0; } -HARDWARE_MODULE_STRUCTURE = { - .magic = HARDWARE_INFO_TAG, - .hal_version = HARDWARE_INFO_VERSION, - .device_version = BATTERY_HARDWARE_DEVICE_VERSION, - .id = BATTERY_HARDWARE_DEVICE_ID, +hal_backend EXPORT hal_backend_device_battery_data = { .name = "battery", - .open = battery_open, - .close = battery_close, + .vendor = "EMUL", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = battery_init, + .exit = battery_exit, }; diff --git a/hw/common/common.h b/hw/common/common.h new file mode 100644 index 0000000..91767ee --- /dev/null +++ b/hw/common/common.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2021 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 __HAL_BACKEND_COMMON_H__ +#define __HAL_BACKEND_COMMON_H__ + +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#ifdef FEATURE_DLOG + #define LOG_TAG "HALBACKEND_DEVICE" + #include <dlog.h> + #define _D(fmt, args...) SLOGD(fmt, ##args) + #define _I(fmt, args...) SLOGI(fmt, ##args) + #define _W(fmt, args...) SLOGW(fmt, ##args) + #define _E(fmt, args...) SLOGE(fmt, ##args) +#else + #define _D(x, ...) + #define _I(x, ...) + #define _W(x, ...) + #define _E(x, ...) +#endif + + +#define EXPORT __attribute__ ((visibility("default"))) + +#define SHARED_H_BUF_MAX 255 + +static inline int sys_read_buf(char *file, char *buf, int len) +{ + int fd, r; + + if (!file || !buf || len < 0) + return -EINVAL; + + fd = open(file, O_RDONLY); + if (fd == -1) + return -ENOENT; + + r = read(fd, buf, len); + close(fd); + if ((r >= 0) && (r < len)) + buf[r] = '\0'; + else + return -EIO; + + return 0; +} + +static inline int sys_write_buf(char *file, char *buf) +{ + int fd, r; + + if (!file || !buf) + return -EINVAL; + + fd = open(file, O_WRONLY); + if (fd == -1) + return -EPERM; + + r = write(fd, buf, strlen(buf)); + close(fd); + if (r < 0) + return -EIO; + + return 0; +} + +static inline int sys_get_int(char *fname, int *val) +{ + char buf[SHARED_H_BUF_MAX]; + int r; + + if (!fname || !val) + return -EINVAL; + + r = sys_read_buf(fname, buf, sizeof(buf)); + if (r < 0) + return r; + + *val = atoi(buf); + return 0; +} + +static inline int sys_get_str(char *fname, char *str, int len) +{ + int r; + + if (!fname || !str || len < 0) + return -EINVAL; + + r = sys_read_buf(fname, str, len); + if (r < 0) + return r; + + return 0; +} + +static inline int sys_set_int(char *fname, int val) +{ + char buf[SHARED_H_BUF_MAX]; + int r; + + if (!fname) + return -EINVAL; + + snprintf(buf, sizeof(buf), "%d", val); + r = sys_write_buf(fname, buf); + if (r < 0) + return r; + + return 0; +} + +static inline int sys_set_str(char *fname, char *val) +{ + int r; + + if (!fname || !val) + return -EINVAL; + + r = sys_write_buf(fname, val); + if (r < 0) + return r; + + return 0; +} + +#endif /* __HAL_BACKEND_COMMON_H__ */ diff --git a/hw/display/CMakeLists.txt b/hw/display/CMakeLists.txt index 08c293d..d5a5a3a 100644 --- a/hw/display/CMakeLists.txt +++ b/hw/display/CMakeLists.txt @@ -1,10 +1,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(display C) +PROJECT(hal-backend-device-display C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +INCLUDE_DIRECTORIES(../common) + INCLUDE(FindPkgConfig) -pkg_check_modules(display_pkgs REQUIRED hwcommon dlog) +pkg_check_modules(hal-backend-device-display_pkgs REQUIRED dlog) FOREACH(flag ${display_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -14,6 +16,5 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} MODULE display.c) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${display_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-display_pkgs_LDFLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /hal/lib COMPONENT RuntimeLibraries) diff --git a/hw/display/display.c b/hw/display/display.c index 71e7260..f4bf894 100644 --- a/hw/display/display.c +++ b/hw/display/display.c @@ -23,8 +23,10 @@ #include <errno.h> #include <linux/limits.h> -#include <hw/display.h> -#include <hw/shared.h> +#include <hal/device/hal-display-interface.h> +#include <hal/hal-common-interface.h> + +#include "common.h" #ifndef BACKLIGHT_PATH #define BACKLIGHT_PATH "/sys/class/backlight/emulator" @@ -91,42 +93,36 @@ static int display_set_brightness(int brightness) return 0; } -static int display_open(struct hw_info *info, - const char *id, struct hw_common **common) +static int display_init(void **data) { - struct display_device *display_dev; - - if (!info || !common) - return -EINVAL; + hal_backend_display_funcs *display_funcs; - display_dev = calloc(1, sizeof(struct display_device)); - if (!display_dev) + display_funcs = calloc(1, sizeof(hal_backend_display_funcs)); + if (!display_funcs) return -ENOMEM; - display_dev->common.info = info; - display_dev->get_max_brightness = display_get_max_brightness; - display_dev->get_brightness = display_get_brightness; - display_dev->set_brightness = display_set_brightness; + display_funcs->get_max_brightness = display_get_max_brightness; + display_funcs->get_brightness = display_get_brightness; + display_funcs->set_brightness = display_set_brightness; + + *data = (void *)display_funcs; - *common = (struct hw_common *)display_dev; return 0; } -static int display_close(struct hw_common *common) +static int display_exit(void *data) { - if (!common) - return -EINVAL; + if (!data) + return 0; - free(common); + free(data); return 0; } -HARDWARE_MODULE_STRUCTURE = { - .magic = HARDWARE_INFO_TAG, - .hal_version = HARDWARE_INFO_VERSION, - .device_version = DISPLAY_HARDWARE_DEVICE_VERSION, - .id = DISPLAY_HARDWARE_DEVICE_ID, - .name = "Display", - .open = display_open, - .close = display_close, +hal_backend EXPORT hal_backend_device_display_data = { + .name = "display", + .vendor = "EMUL", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = display_init, + .exit = display_exit, }; diff --git a/hw/external_connection/CMakeLists.txt b/hw/external_connection/CMakeLists.txt index 8c03f5b..c80f6fb 100644 --- a/hw/external_connection/CMakeLists.txt +++ b/hw/external_connection/CMakeLists.txt @@ -1,12 +1,14 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(external_connection C) +PROJECT(hal-backend-device-external-connection C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +INCLUDE_DIRECTORIES(../common) + INCLUDE(FindPkgConfig) -pkg_check_modules(external_connection_pkgs REQUIRED hwcommon dlog glib-2.0 gio-2.0) +pkg_check_modules(hal-backend-device-external-connection_pkgs REQUIRED dlog glib-2.0 gio-2.0) -FOREACH(flag ${external_connection_pkgs_CFLAGS}) +FOREACH(flag ${hal-backend-device-external-connection_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -14,6 +16,5 @@ 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) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${external_connection_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-external-connection_pkgs_LDFLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /hal/lib COMPONENT RuntimeLibraries) diff --git a/hw/external_connection/external_connection.c b/hw/external_connection/external_connection.c index f317b52..c61a716 100644 --- a/hw/external_connection/external_connection.c +++ b/hw/external_connection/external_connection.c @@ -25,9 +25,11 @@ #include <linux/limits.h> #include <dirent.h> -#include <hw/external_connection.h> -#include <hw/shared.h> +#include <hal/device/hal-external_connection-interface.h> +#include <hal/hal-common-interface.h> + #include "../dbus.h" +#include "common.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) @@ -169,45 +171,36 @@ static int external_connection_get_current_state( return 0; } -static int external_connection_open(struct hw_info *info, - const char *id, struct hw_common **common) +static int external_connection_init(void **data) { - struct external_connection_device *external_connection_dev; - - if (!info || !common) - return -EINVAL; + hal_backend_external_connection_funcs *external_connection_funcs; - external_connection_dev = calloc(1, sizeof(struct external_connection_device)); - if (!external_connection_dev) + external_connection_funcs = calloc(1, sizeof(hal_backend_external_connection_funcs)); + if (!external_connection_funcs) return -ENOMEM; - external_connection_dev->common.info = info; - external_connection_dev->register_changed_event - = external_connection_register_changed_event; - external_connection_dev->unregister_changed_event - = external_connection_unregister_changed_event; - external_connection_dev->get_current_state - = external_connection_get_current_state; + external_connection_funcs->register_changed_event = external_connection_register_changed_event; + external_connection_funcs->unregister_changed_event = external_connection_unregister_changed_event; + external_connection_funcs->get_current_state = external_connection_get_current_state; + + *data = (void *)external_connection_funcs; - *common = (struct hw_common *)external_connection_dev; return 0; } -static int external_connection_close(struct hw_common *common) +static int external_connection_exit(void *data) { - if (!common) - return -EINVAL; + if (!data) + return 0; - free(common); + free(data); return 0; } -HARDWARE_MODULE_STRUCTURE = { - .magic = HARDWARE_INFO_TAG, - .hal_version = HARDWARE_INFO_VERSION, - .device_version = EXTERNAL_CONNECTION_HARDWARE_DEVICE_VERSION, - .id = EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID, - .name = "external_connection", - .open = external_connection_open, - .close = external_connection_close, +hal_backend EXPORT hal_backend_device_external_connection_data = { + .name = "external-connection", + .vendor = "EMUL", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = external_connection_init, + .exit = external_connection_exit, }; diff --git a/packaging/device-manager-plugin-emul.spec b/packaging/device-manager-plugin-emul.spec index 7dbff80..5db9ac3 100644 --- a/packaging/device-manager-plugin-emul.spec +++ b/packaging/device-manager-plugin-emul.spec @@ -13,6 +13,9 @@ BuildRequires: pkgconfig(devman_plugin) BuildRequires: pkgconfig(hwcommon) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(hal-api-device) +BuildRequires: pkgconfig(libsyscommon) %description Emulator plugin for libdevice-node. @@ -41,4 +44,4 @@ make %manifest device-manager-plugin-emul.manifest %{_libdir}/libslp_devman_plugin.so %{_libdir}/hw/*.so - +/hal/lib/*.so*
\ No newline at end of file |