From: Yunhee Seo Date: Thu, 27 Feb 2025 02:45:57 +0000 (+0900) Subject: device-led: Add hal-backend-service-device-led plugin X-Git-Tag: accepted/tizen/unified/20250311.134552~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c043e9e36fc41251e2214f4fbaa41bea30b87c29;p=platform%2Fhal%2Fapi%2Fdevice.git device-led: Add hal-backend-service-device-led plugin Add hal-backend-service-device-led plugin which is HAL IPC stub(server) for HAL_MODULE_DEVICE_LED. Change-Id: I35d7040cf5dd08fa1616e02f7b8ae32604047644 Signed-off-by: Yunhee Seo --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a8fd6..e675807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,3 +108,4 @@ ADD_CUSTOM_COMMAND( ENDIF(UNIX) ADD_SUBDIRECTORY(hal-backend-service-plugin/display) +ADD_SUBDIRECTORY(hal-backend-service-plugin/led) diff --git a/hal-backend-service-plugin/led/CMakeLists.txt b/hal-backend-service-plugin/led/CMakeLists.txt new file mode 100644 index 0000000..86713dd --- /dev/null +++ b/hal-backend-service-plugin/led/CMakeLists.txt @@ -0,0 +1,42 @@ +PROJECT(hal-backend-service-device-led C) + +SET(LIBRARY_NAME "${PROJECT_NAME}") +SET(CMAKE_VERBOSE_MAKEFILE ON) +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +IF(ENABLE_DLOG STREQUAL on) + ADD_DEFINITIONS("-DFEATURE_DLOG") + ADD_DEFINITIONS("-DLOG_TAG=\"HAL_BACKEND_SERVICE_DEVICE_LED\"") +ENDIF() + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + dlog + hal-api-common + glib-2.0 + capi-appfw-app-common + capi-appfw-app-manager + capi-appfw-package-manager + rpc-port +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(CMAKE_C_FLAGS "${CMAKE_CFLAGS} ${EXTRA_CFLAGS}") + +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/generated) + +SET(SRCS + ${PROJECT_SOURCE_DIR}/${LIBRARY_NAME}.c + ${CMAKE_SOURCE_DIR}/src/hal-api-device-led.c + ${CMAKE_SOURCE_DIR}/src/hal-api-device-led-passthrough.c + ${CMAKE_SOURCE_DIR}/src/generated/hal_device_led_stub_1.c) + +ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${pkgs_LDFLAGS} -ldl) + +INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${LIB_INSTALL_DIR}/hal COMPONENT RuntimeLibraries) diff --git a/hal-backend-service-plugin/led/hal-backend-service-device-led.c b/hal-backend-service-plugin/led/hal-backend-service-device-led.c new file mode 100644 index 0000000..6b71c78 --- /dev/null +++ b/hal-backend-service-plugin/led/hal-backend-service-device-led.c @@ -0,0 +1,209 @@ +/* + * HAL Backend Service Plugin for HAL_MODULE_DEVICE_LED + * + * Copyright (c) 2025 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 +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "common.h" + +static int device_led_early_init (void *data) +{ + return 0; +} + +static void device_led_ipc_create(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + void *user_data) +{ + char *sender = NULL; + rpc_port_stub_hal_device_led_stub_1_device_led_context_get_sender(context, &sender); + if (!sender) + return; + + free(sender); +} + +static void device_led_ipc_terminate(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + void *user_data) +{ + char *sender = NULL; + + rpc_port_stub_hal_device_led_stub_1_device_led_context_get_sender(context, &sender); + if (!sender) + return; + + free(sender); +} + +int hal_device_led_funcs_camera_front_set_state(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + rpc_port_stub_hal_device_led_stub_1_enums_type_e type, + rpc_port_stub_hal_device_led_stub_1_state_h state, + void *user_data) +{ + hal_device_led_state_s led_state; + + rpc_port_stub_hal_device_led_stub_1_state_get_type(state, (rpc_port_stub_hal_device_led_stub_1_enums_type_e*)&led_state.type); + rpc_port_stub_hal_device_led_stub_1_state_get_color(state, &led_state.color); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_on(state, &led_state.duty_on); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_off(state, &led_state.duty_off); + return hal_device_led_passthrough_set_state(type, &led_state); +} + +int hal_device_led_funcs_camera_back_set_state(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + rpc_port_stub_hal_device_led_stub_1_enums_type_e type, + rpc_port_stub_hal_device_led_stub_1_state_h state, + void *user_data) +{ + hal_device_led_state_s led_state; + + rpc_port_stub_hal_device_led_stub_1_state_get_type(state, (rpc_port_stub_hal_device_led_stub_1_enums_type_e*)&led_state.type); + rpc_port_stub_hal_device_led_stub_1_state_get_color(state, &led_state.color); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_on(state, &led_state.duty_on); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_off(state, &led_state.duty_off); + return hal_device_led_passthrough_set_state(type, &led_state); +} + +int hal_device_led_funcs_notification_set_state(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + rpc_port_stub_hal_device_led_stub_1_enums_type_e type, + rpc_port_stub_hal_device_led_stub_1_state_h state, + void *user_data) +{ + hal_device_led_state_s led_state; + + rpc_port_stub_hal_device_led_stub_1_state_get_type(state, (rpc_port_stub_hal_device_led_stub_1_enums_type_e*)&led_state.type); + rpc_port_stub_hal_device_led_stub_1_state_get_color(state, &led_state.color); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_on(state, &led_state.duty_on); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_off(state, &led_state.duty_off); + return hal_device_led_passthrough_set_state(type, &led_state); +} + +int hal_device_led_funcs_touch_key_set_state(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + rpc_port_stub_hal_device_led_stub_1_enums_type_e type, + rpc_port_stub_hal_device_led_stub_1_state_h state, + void *user_data) +{ + hal_device_led_state_s led_state; + + rpc_port_stub_hal_device_led_stub_1_state_get_type(state, (rpc_port_stub_hal_device_led_stub_1_enums_type_e*)&led_state.type); + rpc_port_stub_hal_device_led_stub_1_state_get_color(state, &led_state.color); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_on(state, &led_state.duty_on); + rpc_port_stub_hal_device_led_stub_1_state_get_duty_off(state, &led_state.duty_off); + return hal_device_led_passthrough_set_state(type, &led_state); +} + +int hal_device_led_funcs_notification_get_number(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, void *user_data) +{ + return hal_device_led_passthrough_get_number(); +} + +int hal_device_led_funcs_notification_set_num(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, int number, void *user_data) +{ + return hal_device_led_passthrough_set_number(number); +} + +int hal_device_led_funcs_notification_get_max_num(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, void *user_data) +{ + return hal_device_led_passthrough_get_max_num(); +} + +int hal_device_led_funcs_touch_key_keyled_set_state(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + rpc_port_stub_hal_device_led_stub_1_keyled_state_h state, + void *user_data) +{ + hal_device_led_keyled_state_s keyled_state; + + rpc_port_stub_hal_device_led_stub_1_keyled_state_get_keycode(state, &keyled_state.keycode); + rpc_port_stub_hal_device_led_stub_1_keyled_state_get_brightness(state, &keyled_state.brightness); + return hal_device_keyled_passthrough_set_state(&keyled_state); +} + +int hal_device_led_funcs_touch_key_keyled_get_state(rpc_port_stub_hal_device_led_stub_1_device_led_context_h context, + int *keycode, + int *brightness, + void *user_data) +{ + if (!keycode || !brightness) + return -EINVAL; + + return hal_device_keyled_passthrough_get_state(keycode, brightness); +} + +static int device_led_init (void *data) +{ + int ret = 0; + + ret = hal_device_led_passthrough_get_backend(); + if (ret != 0) { + _E("Failed to get passthrough led backend: %d", ret); + return ret; + } + + rpc_port_stub_hal_device_led_stub_1_device_led_callback_s callback = { + .create = device_led_ipc_create, + .terminate = device_led_ipc_terminate, + .led_funcs_camera_front_set_state = hal_device_led_funcs_camera_front_set_state, + .led_funcs_camera_back_set_state = hal_device_led_funcs_camera_back_set_state, + .led_funcs_notification_set_state = hal_device_led_funcs_notification_set_state, + .led_funcs_touch_key_set_state = hal_device_led_funcs_touch_key_set_state, + .led_funcs_notification_get_number = hal_device_led_funcs_notification_get_number, + .led_funcs_notification_set_num = hal_device_led_funcs_notification_set_num, + .led_funcs_notification_get_max_num = hal_device_led_funcs_notification_get_max_num, + .led_funcs_touch_key_keyled_set_state = hal_device_led_funcs_touch_key_keyled_set_state, + .led_funcs_touch_key_keyled_get_state = hal_device_led_funcs_touch_key_keyled_get_state, + }; + + ret = rpc_port_stub_hal_device_led_stub_1_device_led_register(&callback, NULL); + if (ret != RPC_PORT_ERROR_NONE) + _E("Failed to register rpc_port_stub_hal_device_led_stub_1_device_led_callback_s ret(%d)", ret); + + return 0; +} + +static int device_led_exit (void *data) +{ + int ret = 0; + + rpc_port_stub_hal_device_led_stub_1_device_led_unregister(); + + ret = hal_device_led_passthrough_put_backend(); + if (ret != 0) + _E("Failed to hal_device_led_put_backend_passthrough ret(%d)", ret); + + return 0; +} + +static int device_led_late_exit (void *data) +{ + return 0; +} + +hal_backend_service hal_backend_service_device_led_data = { + .module = HAL_MODULE_DEVICE_LED, + .name = "hal-backend-service-device-led", + .early_init = device_led_early_init, + .init = device_led_init, + .exit = device_led_exit, + .late_exit = device_led_late_exit, +}; diff --git a/packaging/hal-api-device.spec b/packaging/hal-api-device.spec index 1a65c3e..dfe105d 100644 --- a/packaging/hal-api-device.spec +++ b/packaging/hal-api-device.spec @@ -75,6 +75,7 @@ cp %{SOURCE2} %{buildroot}%{_sysconfdir}/hal/ %license LICENSE.Apache-2.0 %{_libdir}/hal/libhal-api-device.so* %{_libdir}/hal/libhal-backend-service-device-display.so +%{_libdir}/hal/libhal-backend-service-device-led.so %{_sysconfdir}/hal/hal-api-device-manifest.xml %files devel