device-display: Apply HAL ABI versioning rule 08/308908/3
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 2 Apr 2024 11:23:52 +0000 (20:23 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 4 Apr 2024 01:29:46 +0000 (10:29 +0900)
In HAL-API-[module], source file name should follow hal-api-[module].c format
for applying HAL ABI versioning.

hal-api-device-display.c
 -> HAL-INTERFACE Wrapper call according to major version and implemenation of
functions declared in hal-device-display.h

To apply HAL ABI versioning, the backend function structure memory allocation part
was moved to hal-api-device-display.

Change-Id: I6c203c078a512e474a8568b1303bcfbf20afe31e
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/display.c [deleted file]
src/hal-api-device-display.c [new file with mode: 0644]

diff --git a/src/display.c b/src/display.c
deleted file mode 100644 (file)
index 18881f2..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * 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.
- */
-
-#include <hal/hal-common.h>
-
-#include "hal-device-display-interface.h"
-#include "common.h"
-
-static hal_backend_device_display_funcs *hal_device_display_funcs = NULL;
-/*
--1 : failed to initialize
-0  : not initialized
-1  : succeeded to initialize
-*/
-static int hal_initialized = 0;
-
-int hal_device_display_get_backend(void)
-{
-       int ret;
-
-       if (hal_device_display_funcs)
-               return 0;
-
-       ret = hal_common_get_backend(HAL_MODULE_DEVICE_DISPLAY, (void **)&hal_device_display_funcs);
-       if (ret < 0) {
-                _E("Failed to get display backend");
-               hal_initialized = -1;
-               return -EINVAL;
-       }
-
-       hal_initialized = 1;
-       return 0;
-}
-
-int hal_device_display_put_backend(void)
-{
-       if (!hal_device_display_funcs)
-               return 0;
-
-       hal_common_put_backend(HAL_MODULE_DEVICE_DISPLAY, (void *)hal_device_display_funcs);
-       hal_device_display_funcs = NULL;
-       hal_initialized = 0;
-
-       return 0;
-}
-
-int hal_device_display_get_max_brightness(int *brightness)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_max_brightness)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_max_brightness(brightness);
-}
-
-int hal_device_display_get_brightness(int *brightness)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_brightness)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_brightness(brightness);
-}
-
-int hal_device_display_set_brightness(int brightness)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_brightness)
-               return -ENODEV;
-
-       return hal_device_display_funcs->set_brightness(brightness);
-}
-
-int hal_device_display_set_multi_brightness(int brightness, int step, int delay)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_multi_brightness)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_auto_brightness)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_state)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_state(state);
-}
-
-int hal_device_display_set_state(hal_device_display_state_e state)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_state)
-               return -ENODEV;
-
-       return hal_device_display_funcs->set_state(state);
-}
-
-int hal_device_display_get_image_effect(hal_device_display_image_effect_e *effect)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_image_effect)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_image_effect)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_panel_mode)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_panel_mode)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_aod_mode)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_aod_brightness)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_aod_brightness(max, normal, min, charging);
-}
-
-int hal_device_display_get_max_frame_rate(int *rate)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_max_frame_rate)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_max_frame_rate(rate);
-}
-
-int hal_device_display_get_min_frame_rate(int *rate)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_min_frame_rate)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_min_frame_rate(rate);
-}
-
-int hal_device_display_get_frame_rate(int *rate)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_frame_rate)
-               return -ENODEV;
-
-       return hal_device_display_funcs->get_frame_rate(rate);
-}
-
-int hal_device_display_set_frame_rate(int rate)
-{
-       int ret;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_frame_rate)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->set_white_balance)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-               !hal_device_display_funcs->get_white_balance)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->get_rotation_angle)
-               return -ENODEV;
-
-       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;
-
-       if (!hal_device_display_funcs && !hal_initialized) {
-               if ((ret = hal_device_display_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_display_funcs ||
-           !hal_device_display_funcs->set_rotation_angle)
-               return -ENODEV;
-
-       return hal_device_display_funcs->set_rotation_angle(display_index, angle, direction);
-}
diff --git a/src/hal-api-device-display.c b/src/hal-api-device-display.c
new file mode 100644 (file)
index 0000000..a8969ef
--- /dev/null
@@ -0,0 +1,288 @@
+/*
+ * 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.
+ */
+
+#include <hal/hal-common.h>
+
+#include "hal-device-display-interface.h"
+#include "common.h"
+
+static hal_backend_device_display_funcs *hal_device_display_funcs = NULL;
+
+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);
+               return -ENOTSUP;
+       }
+
+       return 0;
+}
+
+int hal_device_display_put_backend(void)
+{
+       int ret = 0;
+
+       if (!hal_device_display_funcs)
+               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)
+{
+       if (!brightness)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_max_brightness)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_max_brightness(brightness);
+}
+
+int hal_device_display_get_brightness(int *brightness)
+{
+       if (!brightness)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_brightness)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_brightness(brightness);
+}
+
+int hal_device_display_set_brightness(int brightness)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_brightness)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->set_brightness(brightness);
+}
+
+int hal_device_display_set_multi_brightness(int brightness, int step, int delay)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_multi_brightness)
+               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)
+{
+       if (!brightness)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_auto_brightness)
+               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)
+{
+       if (!state)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_state)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_state(state);
+}
+
+int hal_device_display_set_state(hal_device_display_state_e state)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_state)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->set_state(state);
+}
+
+int hal_device_display_get_image_effect(hal_device_display_image_effect_e *effect)
+{
+       if (!effect)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_image_effect)
+               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)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_image_effect)
+               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)
+{
+       if (!mode)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_panel_mode)
+               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)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_panel_mode)
+               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)
+{
+       if (!mode)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_aod_mode)
+               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)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_aod_brightness)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_aod_brightness(max, normal, min, charging);
+}
+
+int hal_device_display_get_max_frame_rate(int *rate)
+{
+       if (!rate)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_max_frame_rate)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_max_frame_rate(rate);
+}
+
+int hal_device_display_get_min_frame_rate(int *rate)
+{
+       if (!rate)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_min_frame_rate)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_min_frame_rate(rate);
+}
+
+int hal_device_display_get_frame_rate(int *rate)
+{
+       if (!rate)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_frame_rate)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->get_frame_rate(rate);
+}
+
+int hal_device_display_set_frame_rate(int rate)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_frame_rate)
+               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)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_white_balance)
+               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)
+{
+       if (!value)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_white_balance)
+               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)
+{
+       if (!angle)
+               return -EINVAL;
+
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->get_rotation_angle)
+               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)
+{
+       if (!hal_device_display_funcs ||
+               !hal_device_display_funcs->set_rotation_angle)
+               return -ENOTSUP;
+
+       return hal_device_display_funcs->set_rotation_angle(display_index, angle, direction);
+}