device-display: Support hal-api passthrough and IPC selectively by configuration
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 13 Feb 2025 06:08:11 +0000 (15:08 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 20 Feb 2025 10:01:38 +0000 (19:01 +0900)
To support two-way communication method from HAL,
hal_transport definition and implementation is added.
Please refer changed communication method.

Before
- Passthrough
  - hal-api(display) --(dlopen)--> hal-backend

After
- Passthrough and IPC
  - hal-api(display) --(dlopen)--> hal-backend
           |
           |(proxy)
           |
           |-----------(IPC)-----> hal-backend-serivce(stub) --> hal-backend

With hal_transport configuration, transport method can be selected.
It defines IPC or passthrough communication way.
Therefore, the existing hal-api code should call either IPC or passthrough.

Change-Id: I01f26ecfd79406d5d782f167f5ac1cef549a9c80
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
CMakeLists.txt
packaging/hal-api-device.spec
src/hal-api-device-display.c

index 41056c0cb093a628f493284b8ed67713f49c994b..1ce340cfe0cfe05d16fd78c514c5c97846a7d170 100644 (file)
@@ -36,6 +36,7 @@ ENDIF("${ARCH}" STREQUAL "arm")
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DFEATURE_DEVICE_DLOG")
 ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}/hal\"")
+ADD_DEFINITIONS(-DHAL_TRANSPORT=${HAL_TRANSPORT})
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}/hal")
 
index 2a7a6e0928aa049b5c75432f076ffc7c19e82b9b..e44902da9ee6261a5a9361edcac452c195df3981 100644 (file)
@@ -1,3 +1,4 @@
+%define hal_transport 2
 Name:       hal-api-device
 Summary:    API library for HAL device modules
 Version:    1.0.0
@@ -49,7 +50,8 @@ cp %{SOURCE1} .
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . -DFULLVER=%{version} \
                 -DMAJORVER=${MAJORVER} \
-                -DHALTEST=on
+                -DHALTEST=on \
+                -DHAL_TRANSPORT=%{hal_transport}
 
 %__make %{?jobs:-j%jobs}
 
index 49ebfb030f7ac621190d441b429c8d7e806de8b9..33cf37499cbaa9e4a953d9fccb86ce5375d0e743 100644 (file)
 #include <hal/hal-common.h>
 
 #include "hal-device-display-interface.h"
+#include "hal-device-display-ipc.h"
+#include "hal-device-display-passthrough.h"
+
 #include "common.h"
 
-static hal_backend_device_display_funcs *hal_device_display_funcs = NULL;
+static enum hal_common_transport g_hal_transport = HAL_TRANSPORT;
 
 int hal_device_display_get_backend(void)
 {
-       int ret;
-
-       if (hal_device_display_funcs)
-               return 0;
-
-       hal_device_display_funcs = calloc(1, sizeof(hal_backend_device_display_funcs));
-       if (!hal_device_display_funcs)
-               return -ENOMEM;
-
-       ret = hal_common_get_backend(HAL_MODULE_DEVICE_DISPLAY, (void **)&hal_device_display_funcs);
-       if (ret < 0) {
-               _E("Failed to get device-display backend");
-               free(hal_device_display_funcs);
-               hal_device_display_funcs = NULL;
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_backend();
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_backend();
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
        }
-
-       return 0;
 }
 
 int hal_device_display_put_backend(void)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_put_backend();
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_put_backend();
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       ret = hal_common_put_backend(HAL_MODULE_DEVICE_DISPLAY, (void *)hal_device_display_funcs);
-       if (ret < 0) {
-               _E("Failed to put device-display backend");
-               return ret;
        }
-
-       free(hal_device_display_funcs);
-       hal_device_display_funcs = NULL;
-
-       return 0;
 }
 
 int hal_device_display_get_max_brightness(int *brightness)
 {
-       int ret = 0;
-
        if (!brightness)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_max_brightness)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_max_brightness(brightness);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_max_brightness(brightness);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_max_brightness(brightness);
+       }
 }
 
 int hal_device_display_get_brightness(int *brightness)
 {
-       int ret = 0;
-
        if (!brightness)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_brightness)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_brightness(brightness);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_brightness(brightness);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_brightness(brightness);
+       }
 }
 
 int hal_device_display_set_brightness(int brightness)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_brightness)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_brightness(brightness);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_brightness(brightness);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_brightness(brightness);
+       }
 }
 
 int hal_device_display_set_multi_brightness(int brightness, int step, int delay)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_multi_brightness)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_passthrough_set_multi_brightness(brightness, step, delay);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_multi_brightness(brightness, step, delay);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_multi_brightness(brightness, step, delay);
+       }
 }
 
 int hal_device_display_get_auto_brightness(float lmax, float lmin, float light, int *brightness)
 {
-       int ret = 0;
-
-       if (!brightness)
-               return -EINVAL;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_auto_brightness)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_auto_brightness(lmax, lmin, light, brightness);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_auto_brightness(lmax, lmin, light, brightness);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_auto_brightness(lmax, lmin, light, brightness);
+       }
 }
 
 int hal_device_display_get_state(hal_device_display_state_e *state)
 {
-       int ret = 0;
-
        if (!state)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_state)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_state(state);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_state(state);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_state(state);
+       }
 }
 
 int hal_device_display_set_state(hal_device_display_state_e state)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_state)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_state(state);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_state(state);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_state(state);
+       }
 }
 
 int hal_device_display_get_image_effect(hal_device_display_image_effect_e *effect)
 {
-       int ret = 0;
-
        if (!effect)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_image_effect)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_image_effect(effect);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_image_effect(effect);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_image_effect(effect);
+       }
 }
 
 int hal_device_display_set_image_effect(hal_device_display_image_effect_e effect)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_image_effect)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_image_effect(effect);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_image_effect(effect);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_image_effect(effect);
+       }
 }
 
 int hal_device_display_get_panel_mode(hal_device_display_panel_mode_e *mode)
 {
-       int ret = 0;
-
        if (!mode)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_panel_mode)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_panel_mode(mode);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_panel_mode(mode);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_panel_mode(mode);
+       }
 }
 
 int hal_device_display_set_panel_mode(hal_device_display_panel_mode_e mode)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_panel_mode)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_panel_mode(mode);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_panel_mode(mode);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_panel_mode(mode);
+       }
 }
 
 int hal_device_display_get_aod_mode(hal_device_display_aod_mode_e *mode)
 {
-       int ret = 0;
-
        if (!mode)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_aod_mode)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_aod_mode(mode);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_aod_mode(mode);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_aod_mode(mode);
+       }
 }
 
 int hal_device_display_get_aod_brightness(int *max, int *normal, int *min, int *charging)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
+       if (!max ||!normal ||!min ||!charging)
+               return -EINVAL;
 
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_aod_brightness)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_aod_brightness(max, normal, min, charging);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_aod_brightness(max, normal, min, charging);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_aod_brightness(max, normal, min, charging);
+       }
 }
 
 int hal_device_display_get_max_frame_rate(int *rate)
 {
-       int ret = 0;
-
        if (!rate)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_max_frame_rate)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_max_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_max_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_max_frame_rate(rate);
+       }
 }
 
 int hal_device_display_get_min_frame_rate(int *rate)
 {
-       int ret = 0;
-
        if (!rate)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_min_frame_rate)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_min_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_min_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_min_frame_rate(rate);
+       }
 }
 
 int hal_device_display_get_frame_rate(int *rate)
 {
-       int ret = 0;
-
        if (!rate)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_frame_rate)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_frame_rate(rate);
+       }
 }
 
 int hal_device_display_set_frame_rate(int rate)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_frame_rate)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_frame_rate(rate);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_frame_rate(rate);
+       }
 }
 
 int hal_device_display_set_white_balance(hal_device_display_white_balance_e white_balance_type, int value)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_white_balance)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_white_balance(white_balance_type, value);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_white_balance(white_balance_type, value);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_white_balance(white_balance_type, value);
+       }
 }
 
 int hal_device_display_get_white_balance(hal_device_display_white_balance_e white_balance_type, int* value)
 {
-       int ret = 0;
-
        if (!value)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_white_balance)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_white_balance(white_balance_type, value);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_white_balance(white_balance_type, value);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_white_balance(white_balance_type, value);
+       }
 }
 
 int hal_device_display_get_rotation_angle(int display_index, hal_device_display_rotation_angle_e *angle)
 {
-       int ret = 0;
-
        if (!angle)
                return -EINVAL;
 
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_rotation_angle)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_get_rotation_angle(display_index, angle);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_get_rotation_angle(display_index, angle);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->get_rotation_angle(display_index, angle);
+       }
 }
 
 int hal_device_display_set_rotation_angle(int display_index,
                                        hal_device_display_rotation_angle_e angle,
                                        hal_device_display_rotation_direction_e direction)
 {
-       int ret = 0;
-
-       if (!hal_device_display_funcs) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_rotation_angle)
+       switch (g_hal_transport) {
+       case HAL_COMMON_TRANSPORT_IPC:
+               return hal_device_display_ipc_set_rotation_angle(display_index, angle, direction);
+       case HAL_COMMON_TRANSPORT_PASSTHROUGH:
+               return hal_device_display_passthrough_set_rotation_angle(display_index, angle, direction);
+       case HAL_COMMON_TRANSPORT_UNKNOWN:
+       default:
                return -ENOTSUP;
-
-       return hal_device_display_funcs->set_rotation_angle(display_index, angle, direction);
-}
+       }
+}
\ No newline at end of file