From: Yunhee Seo Date: Thu, 13 Feb 2025 05:22:35 +0000 (+0900) Subject: device-display: Add hal-api IPC module using generated IPC module by TIDL X-Git-Tag: accepted/tizen/unified/20250311.134552~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f80d138e2cf43f4401e270d96928b6a009050bd2;p=platform%2Fhal%2Fapi%2Fdevice.git device-display: Add hal-api IPC module using generated IPC module by TIDL To support IPC communication with hal-backend-service, hal-api IPC module is newly added. With generated codes from TIDL, below descriptions are added. - proxy initialization for IPC communication - handling IPC communication - using generated proxy function call Change-Id: I638d1b3881bb3929d65b5c09f777c255d0911e81 Signed-off-by: Yunhee Seo --- diff --git a/packaging/hal-api-device.spec b/packaging/hal-api-device.spec index 2a7a6e0..2099fba 100644 --- a/packaging/hal-api-device.spec +++ b/packaging/hal-api-device.spec @@ -41,8 +41,8 @@ Device HAL(Hardware Abstraction Layer) Test Cases %prep %setup -q mkdir -p ./src/generated -tidlc -p -l C -i ./include/hal_device_display_ipc_1.tidl -o ../src/generated/hal_device_display_proxy_1 -n -tidlc -s -l C -i ./include/hal_device_display_ipc_1.tidl -o ../src/generated/hal_device_display_stub_1 -n +tidlc -p -l C -i ./include/hal_device_display_ipc_1.tidl -o ./src/generated/hal_device_display_proxy_1 -n +tidlc -s -l C -i ./include/hal_device_display_ipc_1.tidl -o ./src/generated/hal_device_display_stub_1 -n %build cp %{SOURCE1} . diff --git a/src/hal-api-device-display-ipc.c b/src/hal-api-device-display-ipc.c new file mode 100644 index 0000000..c3ec6ac --- /dev/null +++ b/src/hal-api-device-display-ipc.c @@ -0,0 +1,468 @@ +/* + * Copyright (c) 2025 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 + +#include + +#include "hal-device-display-interface.h" +#include "hal-api-device-display-ipc.h" +#include "src/generated/hal_device_display_proxy_1.h" + +#include "common.h" + +extern char *program_invocation_name; + +static bool g_hal_backend_service_connected = false; +rpc_port_proxy_hal_device_display_proxy_1_device_display_h g_hal_device_display_ipc_h = NULL; + +static void hal_device_display_ipc_connected_cb(rpc_port_proxy_hal_device_display_proxy_1_device_display_h h, + void *user_data) +{ + g_hal_backend_service_connected = true; +} + +static void hal_device_display_ipc_disconnected_cb(rpc_port_proxy_hal_device_display_proxy_1_device_display_h h, + void *user_data) +{ + int ret = 0; + + g_hal_backend_service_connected = false; + ret = hal_device_display_ipc_put_backend(); + if (ret != 0) + _W("Cannot put device-display ipc backend"); +} + +static void hal_device_display_ipc_rejected_cb(rpc_port_proxy_hal_device_display_proxy_1_device_display_h h, + void *user_data) +{ + int ret = 0; + + g_hal_backend_service_connected = false; + ret = hal_device_display_ipc_put_backend(); + if (ret != 0) + _W("Cannot put device-display ipc backend"); +} + +int hal_device_display_ipc_get_backend(void) +{ + int ret = 0; + + if (g_hal_device_display_ipc_h) + return 0; + + rpc_port_proxy_hal_device_display_proxy_1_device_display_callback_s callback = { + .connected = hal_device_display_ipc_connected_cb, + .disconnected = hal_device_display_ipc_disconnected_cb, + .rejected = hal_device_display_ipc_rejected_cb + }; + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_create(HAL_BACKEND_SERVICE_APPID, + &callback, NULL, &g_hal_device_display_ipc_h); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create display ipc handle(%d)", ret); + goto ipc_init_fail; + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_connect_sync(g_hal_device_display_ipc_h); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to connect display ipc handle(%d)", ret); + goto ipc_init_fail; + } + + return 0; + +ipc_init_fail: + g_hal_backend_service_connected = false; + if (g_hal_device_display_ipc_h) + rpc_port_proxy_hal_device_display_proxy_1_device_display_destroy(g_hal_device_display_ipc_h); + g_hal_device_display_ipc_h = NULL; + return ret; +} + +int hal_device_display_ipc_put_backend(void) +{ + int ret = 0; + + if (!g_hal_device_display_ipc_h) + return 0; + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_disconnect(g_hal_device_display_ipc_h); + if (ret != RPC_PORT_ERROR_NONE) + _W("Cannot disconnect display ipc proxy handle(%d)", ret); + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_destroy(g_hal_device_display_ipc_h); + if (ret != RPC_PORT_ERROR_NONE) + _W("Cannot destroy display ipc proxy handle(%d)", ret); + + g_hal_device_display_ipc_h = NULL; + return ret; +} + +int hal_device_display_ipc_get_max_brightness(int *brightness) +{ + int ret = 0; + + if (!brightness) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_max_brightness(g_hal_device_display_ipc_h, + brightness); +} + +int hal_device_display_ipc_get_brightness(int *brightness) +{ + int ret = 0; + + _D("Starting by %s\n", program_invocation_name); + + if (!brightness) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_brightness(g_hal_device_display_ipc_h, + brightness); + + _D("Started by %s\n", program_invocation_name); + + return ret; +} + +int hal_device_display_ipc_set_brightness(int brightness) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_brightness(g_hal_device_display_ipc_h, + brightness); +} + +int hal_device_display_ipc_set_multi_brightness(int brightness, int step, int delay) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_multi_brightness(g_hal_device_display_ipc_h, + brightness, step, delay); +} + +int hal_device_display_ipc_get_auto_brightness(float lmax, float lmin, float light, int *brightness) +{ + int ret = 0; + + if (!brightness) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_auto_brightness(g_hal_device_display_ipc_h, + lmax, lmin, light, brightness); +} + +int hal_device_display_ipc_get_state(hal_device_display_state_e *state) +{ + int ret = 0; + rpc_port_proxy_hal_device_display_proxy_1_enums_state_e state_e; + + if (!state) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_state(g_hal_device_display_ipc_h, + &state_e); + *state = (hal_device_display_state_e)state_e; + return ret; +} + +int hal_device_display_ipc_set_state(hal_device_display_state_e state) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_state(g_hal_device_display_ipc_h, + state); +} + +int hal_device_display_ipc_get_image_effect(hal_device_display_image_effect_e *effect) +{ + int ret = 0; + rpc_port_proxy_hal_device_display_proxy_1_enums_image_effect_e image_effect_e; + + if (!effect) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_image_effect(g_hal_device_display_ipc_h, + &image_effect_e); + *effect = (hal_device_display_image_effect_e)image_effect_e; + return ret; +} + +int hal_device_display_ipc_set_image_effect(hal_device_display_image_effect_e effect) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_image_effect(g_hal_device_display_ipc_h, + effect); +} + +int hal_device_display_ipc_get_panel_mode(hal_device_display_panel_mode_e *mode) +{ + int ret = 0; + rpc_port_proxy_hal_device_display_proxy_1_enums_panel_mode_e panel_mode_e; + + if (!mode) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_panel_mode(g_hal_device_display_ipc_h, + &panel_mode_e); + *mode = (hal_device_display_panel_mode_e)panel_mode_e; + return ret; +} + +int hal_device_display_ipc_set_panel_mode(hal_device_display_panel_mode_e mode) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_panel_mode(g_hal_device_display_ipc_h, + mode); +} + +int hal_device_display_ipc_get_aod_mode(hal_device_display_aod_mode_e *mode) +{ + int ret = 0; + rpc_port_proxy_hal_device_display_proxy_1_enums_aod_mode_e aod_mode_e; + + if (!mode) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_aod_mode(g_hal_device_display_ipc_h, + &aod_mode_e); + *mode = (hal_device_display_aod_mode_e)aod_mode_e; + return ret; +} + +int hal_device_display_ipc_get_aod_brightness(int *max, int *normal, int *min, int *charging) +{ + int ret = 0; + + if (!max ||!normal ||!min ||!charging) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_aod_brightness(g_hal_device_display_ipc_h, + max, normal, min, charging); +} + +int hal_device_display_ipc_get_max_frame_rate(int *rate) +{ + int ret = 0; + + if (!rate) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_max_frame_rate(g_hal_device_display_ipc_h, + rate); +} + +int hal_device_display_ipc_get_min_frame_rate(int *rate) +{ + int ret = 0; + + if (!rate) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_min_frame_rate(g_hal_device_display_ipc_h, + rate); +} + +int hal_device_display_ipc_get_frame_rate(int *rate) +{ + int ret = 0; + + if (!rate) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_frame_rate(g_hal_device_display_ipc_h, + rate); +} + +int hal_device_display_ipc_set_frame_rate(int rate) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_frame_rate(g_hal_device_display_ipc_h, + rate); +} + +int hal_device_display_ipc_set_white_balance(hal_device_display_white_balance_e white_balance_type, int value) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_white_balance(g_hal_device_display_ipc_h, + white_balance_type, value); +} + +int hal_device_display_ipc_get_white_balance(hal_device_display_white_balance_e white_balance_type, int* value) +{ + int ret = 0; + + if (!value) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_white_balance(g_hal_device_display_ipc_h, + white_balance_type, value); +} + +int hal_device_display_ipc_get_rotation_angle(int display_index, hal_device_display_rotation_angle_e *angle) +{ + int ret = 0; + rpc_port_proxy_hal_device_display_proxy_1_enums_rotation_angle_e rotation_angle_e; + + if (!angle) + return -EINVAL; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + ret = rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_get_rotation_angle(g_hal_device_display_ipc_h, + display_index, &rotation_angle_e); + *angle = (hal_device_display_rotation_angle_e)rotation_angle_e; + return ret; +} + +int hal_device_display_ipc_set_rotation_angle(int display_index, + hal_device_display_rotation_angle_e angle, + hal_device_display_rotation_direction_e direction) +{ + int ret = 0; + + if (!g_hal_backend_service_connected) { + if ((ret = hal_device_display_ipc_get_backend() != RPC_PORT_ERROR_NONE)) { + return -ENOTSUP; + } + } + + return rpc_port_proxy_hal_device_display_proxy_1_device_display_invoke_set_rotation_angle(g_hal_device_display_ipc_h, + display_index, angle, direction); +} diff --git a/src/hal-api-device-display-ipc.h b/src/hal-api-device-display-ipc.h new file mode 100644 index 0000000..01a0548 --- /dev/null +++ b/src/hal-api-device-display-ipc.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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_DEVICE_DISPLAY_IPC_H__ +#define __HAL_DEVICE_DISPLAY_IPC_H__ + +#include "hal-device-display-interface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define HAL_BACKEND_SERVICE_APPID "d::HalBackendService" + +int hal_device_display_ipc_get_backend(void); +int hal_device_display_ipc_put_backend(void); +int hal_device_display_ipc_get_max_brightness(int *brightness); +int hal_device_display_ipc_get_brightness(int *brightness); +int hal_device_display_ipc_set_brightness(int brightness); +int hal_device_display_ipc_set_multi_brightness(int brightness, int step, int delay); +int hal_device_display_ipc_get_auto_brightness(float lmax, float lmin, float light, int *brightness); +int hal_device_display_ipc_get_state(hal_device_display_state_e *state); +int hal_device_display_ipc_set_state(hal_device_display_state_e state); +int hal_device_display_ipc_get_image_effect(hal_device_display_image_effect_e *effect); +int hal_device_display_ipc_set_image_effect(hal_device_display_image_effect_e effect); +int hal_device_display_ipc_get_panel_mode(hal_device_display_panel_mode_e *mode); +int hal_device_display_ipc_set_panel_mode(hal_device_display_panel_mode_e mode); +int hal_device_display_ipc_get_aod_mode(hal_device_display_aod_mode_e *mode); +int hal_device_display_ipc_get_aod_brightness(int *max, int *normal, int *min, int *charging); +int hal_device_display_ipc_get_max_frame_rate(int *rate); +int hal_device_display_ipc_get_min_frame_rate(int *rate); +int hal_device_display_ipc_get_frame_rate(int *rate); +int hal_device_display_ipc_set_frame_rate(int rate); +int hal_device_display_ipc_set_white_balance(hal_device_display_white_balance_e white_balance_type, int value); +int hal_device_display_ipc_get_white_balance(hal_device_display_white_balance_e white_balance_type, int* value); +int hal_device_display_ipc_get_rotation_angle(int display_index, hal_device_display_rotation_angle_e *angle); +int hal_device_display_ipc_set_rotation_angle(int display_index, hal_device_display_rotation_angle_e angle, + hal_device_display_rotation_direction_e direction); + +#ifdef __cplusplus +} +#endif + +#endif // __HAL_DEVICE_DISPLAY_IPC_H__ \ No newline at end of file