device-board: Apply HAL ABI versioning rule 32/309332/4
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 8 Apr 2024 12:20:49 +0000 (21:20 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 15 Apr 2024 07:27:53 +0000 (07:27 +0000)
In HAL-API-[module], source file name should follow hal-api-[module].c format
for applying HAL ABI versioning.

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

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

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

diff --git a/src/board.c b/src/board.c
deleted file mode 100644 (file)
index 762372f..0000000
+++ /dev/null
@@ -1,300 +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 <stdio.h>
-#include <hal/hal-common.h>
-
-#include "hal-device-board-interface.h"
-#include "common.h"
-
-static hal_backend_device_board_funcs *hal_device_board_funcs = NULL;
-/*
--1 : failed to initialize
-0  : not initialized
-1  : succeeded to initialize
-*/
-static int hal_initialized = 0;
-
-int hal_device_board_get_backend(void)
-{
-       int ret;
-
-       if (hal_device_board_funcs)
-               return 0;
-
-       ret = hal_common_get_backend(HAL_MODULE_DEVICE_BOARD, (void **)&hal_device_board_funcs);
-       if (ret < 0) {
-                _E("Failed to get board backend");
-               hal_initialized = -1;
-               return -EINVAL;
-       }
-
-       hal_initialized = 1;
-       return 0;
-}
-
-int hal_device_board_put_backend(void)
-{
-       if (!hal_device_board_funcs)
-               return 0;
-
-       hal_common_put_backend(HAL_MODULE_DEVICE_BOARD, (void *)hal_device_board_funcs);
-       hal_device_board_funcs = NULL;
-       hal_initialized = 0;
-
-       return 0;
-}
-
-int hal_device_board_get_device_serial_number(char *buffer, const int max_len)
-{
-       int ret ;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_device_serial_number)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_device_serial_number(buffer, max_len);
-}
-
-int hal_device_board_get_device_revision(int *revision)
-{
-       int ret ;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_device_revision)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_device_revision(revision);
-}
-
-int hal_device_board_set_boot_success(void)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->set_boot_success)
-               return -ENODEV;
-
-       return hal_device_board_funcs->set_boot_success();
-}
-
-
-int hal_device_board_clear_boot_mode(void)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->clear_boot_mode)
-               return -ENODEV;
-
-       return hal_device_board_funcs->clear_boot_mode();
-}
-
-int hal_device_board_get_boot_mode(char *buffer, const int max_len)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_boot_mode)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_boot_mode(buffer, max_len);
-}
-
-int hal_device_board_get_boot_reason(char *buffer, const int max_len)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_boot_reason)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_boot_reason(buffer, max_len);
-}
-
-int hal_device_board_get_current_partition(char *partition_ab)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_current_partition)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_current_partition(partition_ab);
-}
-
-int hal_device_board_switch_partition(char partition_ab)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->switch_partition)
-               return -ENODEV;
-
-       return hal_device_board_funcs->switch_partition(partition_ab);
-}
-
-int hal_device_board_set_partition_ab_cloned(void)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->set_partition_ab_cloned)
-               return -ENODEV;
-
-       return hal_device_board_funcs->set_partition_ab_cloned();
-}
-
-int hal_device_board_clear_partition_ab_cloned(void)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->clear_partition_ab_cloned)
-               return -ENODEV;
-
-       return hal_device_board_funcs->clear_partition_ab_cloned();
-}
-
-int hal_device_board_get_partition_ab_cloned(int *cloned)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_partition_ab_cloned)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_partition_ab_cloned(cloned);
-}
-
-int hal_device_board_set_partition_status(char partition_ab, const char *status)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->set_partition_status)
-               return -ENODEV;
-
-       return hal_device_board_funcs->set_partition_status(partition_ab, status);
-}
-
-int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_partition_status)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_partition_status(partition_ab, buffer, max_len);
-}
-
-int hal_device_board_set_upgrade_status(int status)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->set_upgrade_status)
-               return -ENODEV;
-
-       return hal_device_board_funcs->set_upgrade_status(status);
-}
-
-int hal_device_board_get_upgrade_status(int *status)
-{
-       int ret;
-
-       if (!hal_device_board_funcs && !hal_initialized) {
-               if ((ret = hal_device_board_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_board_funcs ||
-           !hal_device_board_funcs->get_upgrade_status)
-               return -ENODEV;
-
-       return hal_device_board_funcs->get_upgrade_status(status);
-}
diff --git a/src/hal-api-device-board.c b/src/hal-api-device-board.c
new file mode 100644 (file)
index 0000000..67550fc
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <hal/hal-common.h>
+
+#include "hal-device-board-interface.h"
+#include "common.h"
+
+static hal_backend_device_board_funcs *hal_device_board_funcs = NULL;
+
+int hal_device_board_get_backend(void)
+{
+       int ret;
+
+       if (hal_device_board_funcs)
+               return 0;
+
+       hal_device_board_funcs = calloc(1, sizeof(hal_backend_device_board_funcs));
+       if (!hal_device_board_funcs)
+               return -ENOMEM;
+
+       ret = hal_common_get_backend(HAL_MODULE_DEVICE_BOARD, (void **)&hal_device_board_funcs);
+       if (ret < 0) {
+                _E("Failed to get device-board backend");
+               free(hal_device_board_funcs);
+               hal_device_board_funcs = NULL;
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+int hal_device_board_put_backend(void)
+{
+       if (!hal_device_board_funcs)
+               return 0;
+
+       hal_common_put_backend(HAL_MODULE_DEVICE_BOARD, (void *)hal_device_board_funcs);
+       free(hal_device_board_funcs);
+       hal_device_board_funcs = NULL;
+
+       return 0;
+}
+
+int hal_device_board_get_device_serial_number(char *buffer, const int max_len)
+{
+       int ret ;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_device_serial_number)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_device_serial_number(buffer, max_len);
+}
+
+int hal_device_board_get_device_revision(int *revision)
+{
+       int ret ;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_device_revision)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_device_revision(revision);
+}
+
+int hal_device_board_set_boot_success(void)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->set_boot_success)
+               return -ENODEV;
+
+       return hal_device_board_funcs->set_boot_success();
+}
+
+
+int hal_device_board_clear_boot_mode(void)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->clear_boot_mode)
+               return -ENODEV;
+
+       return hal_device_board_funcs->clear_boot_mode();
+}
+
+int hal_device_board_get_boot_mode(char *buffer, const int max_len)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_boot_mode)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_boot_mode(buffer, max_len);
+}
+
+int hal_device_board_get_boot_reason(char *buffer, const int max_len)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_boot_reason)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_boot_reason(buffer, max_len);
+}
+
+int hal_device_board_get_current_partition(char *partition_ab)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_current_partition)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_current_partition(partition_ab);
+}
+
+int hal_device_board_switch_partition(char partition_ab)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->switch_partition)
+               return -ENODEV;
+
+       return hal_device_board_funcs->switch_partition(partition_ab);
+}
+
+int hal_device_board_set_partition_ab_cloned(void)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->set_partition_ab_cloned)
+               return -ENODEV;
+
+       return hal_device_board_funcs->set_partition_ab_cloned();
+}
+
+int hal_device_board_clear_partition_ab_cloned(void)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->clear_partition_ab_cloned)
+               return -ENODEV;
+
+       return hal_device_board_funcs->clear_partition_ab_cloned();
+}
+
+int hal_device_board_get_partition_ab_cloned(int *cloned)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_partition_ab_cloned)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_partition_ab_cloned(cloned);
+}
+
+int hal_device_board_set_partition_status(char partition_ab, const char *status)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->set_partition_status)
+               return -ENODEV;
+
+       return hal_device_board_funcs->set_partition_status(partition_ab, status);
+}
+
+int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_partition_status)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_partition_status(partition_ab, buffer, max_len);
+}
+
+int hal_device_board_set_upgrade_status(int status)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->set_upgrade_status)
+               return -ENODEV;
+
+       return hal_device_board_funcs->set_upgrade_status(status);
+}
+
+int hal_device_board_get_upgrade_status(int *status)
+{
+       int ret;
+
+       if (!hal_device_board_funcs) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_board_funcs ||
+           !hal_device_board_funcs->get_upgrade_status)
+               return -ENODEV;
+
+       return hal_device_board_funcs->get_upgrade_status(status);
+}