osu: Make index of getters and setters using board_params_e 14/316914/6
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 18 Dec 2024 08:19:36 +0000 (17:19 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 3 Jan 2025 06:00:43 +0000 (15:00 +0900)
Make index of getters and setters using enumeration called board_params_e.
It allows specific getter and setter functions to be referenced directly through the
board_params_e enum.

The index of board_params is like below:
{
        BOARD_PARAMS_BOOT_NONE = -1,
        BOARD_PARAMS_BOOT_MODE = 0,
        BOARD_PARAMS_CURRENT_PARTITION,
        BOARD_PARAMS_PARTITION_AB,
        BOARD_PARAMS_PARTITION_AB_CLONED,
        BOARD_PARAMS_PARTITION_STATUS,
        BOARD_PARAMS_UPGRADE_PROGRESS_STATUS,
        BOARD_PARAMS_UPGRADE_STATE,
        BOARD_PARAMS_UPGRADE_TYPE,
        BOARD_PARAMS_MAX,
}

BOARD_PARAMS_BOOT_NONE: index before real board param
BOARD_PARAMS_UPGRADE_TYPE ~ BOARD_PARAMS_UPGRADE_TYPE: index of real board param
BOARD_PARAMS_MAX: index after real board param

Change-Id: I4fc1ecc285cec8fa1205d7a1c31b6a78f98e108d
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
tools/osu/board-params-getter.c
tools/osu/board-params-setter.c
tools/osu/board-params.h

index 929aea9fe4cd4cdf8ef5701bf5b9449563b6b90d..6e587bf6cce4dad191f01bdbde87dcdfb211475a 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "board-params-getter.h"
 #include "board-params-util.h"
+#include "board-params.h"
 
 #define BOARD_PARAM_PARAMS_LEN 2
 
@@ -113,36 +114,48 @@ static int upgrade_type_getter(char **params, size_t params_len, char *buffer, s
        return hal_device_board_get_upgrade_type(buffer, buffer_size);
 }
 
-static struct board_param_getter getters[] = {
-       {
+static struct board_param_getter g_getters[] = {
+       [BOARD_PARAMS_BOOT_MODE] = {
                .param_name = "boot-mode",
                .description = "Get boot mode.",
                .getter = boot_mode_getter
-       }, {
+       },
+       [BOARD_PARAMS_CURRENT_PARTITION] = {
                .param_name = "current-partition",
                .description = "Get current partition (a or b)",
                .getter = current_partition_getter
-       }, {
+       },
+       [BOARD_PARAMS_PARTITION_AB] = {
+               .param_name = "none",
+               .description = "None",
+               .getter = NULL
+       },
+       [BOARD_PARAMS_PARTITION_AB_CLONED] = {
                .param_name = "partition-ab-cloned",
                .description = "Get partition is cloned or not: 1 is cloned, 0 is not cloned.",
                .getter = partition_ab_cloned_getter
-       }, {
+       },
+       [BOARD_PARAMS_PARTITION_STATUS] = {
                .param_name = "partition-status",
                .description = "Get partition status. 1 param is required: 'a' or 'b'.",
                .getter = partition_status_getter
-       }, {
+       },
+       [BOARD_PARAMS_UPGRADE_PROGRESS_STATUS] = {
                .param_name = "upgrade-progress-status",
                .description = "Get current upgrade progress status: -1 ~ 100",
                .getter = upgrade_progress_status_getter
-       }, {
+       },
+       [BOARD_PARAMS_UPGRADE_STATE] = {
                .param_name = "upgrade-state",
                .description = "Get current upgrade state.",
                .getter = upgrade_state_getter
-       }, {
+       },
+       [BOARD_PARAMS_UPGRADE_TYPE] = {
                .param_name = "upgrade-type",
                .description = "Get current upgrade type: offline or online",
                .getter = upgrade_type_getter
-       }, {
+       },
+       [BOARD_PARAMS_MAX] = {
                /* sentinel for this array */
                .param_name = NULL,
                .description = NULL,
@@ -154,9 +167,12 @@ static int get_board_param_getter(const char *param_name, struct board_param_get
 {
        size_t param_name_len = strlen(param_name);
 
-       for (int i = 0; getters[i].param_name != NULL; ++i) {
-               if (strncmp(getters[i].param_name, param_name, param_name_len + 1) == 0) {
-                       *board_param_getter = &getters[i];
+       for (int i = 0; g_getters[i].param_name != NULL; ++i) {
+               if (g_getters[i].getter == NULL)
+                       continue;
+
+               if (strncmp(g_getters[i].param_name, param_name, param_name_len + 1) == 0) {
+                       *board_param_getter = &g_getters[i];
                        return 0;
                }
        }
@@ -167,10 +183,10 @@ static int get_board_param_getter(const char *param_name, struct board_param_get
 static void print_board_param_getters(void)
 {
        printf("Available getter board params:\n");
-       for (int i = 0; getters[i].param_name != NULL; ++i) {
-               if (getters[i].getter == NULL)
+       for (int i = 0; g_getters[i].param_name != NULL; ++i) {
+               if (g_getters[i].getter == NULL)
                        continue;
-               printf("    %s: %s\n", getters[i].param_name, getters[i].description);
+               printf("    %s: %s\n", g_getters[i].param_name, g_getters[i].description);
        }
 
        printf("\n"
index 3bd2b5c369e727f223ede840b50d7a7ea78f2c6f..517bc2d9072207702e395d1ca624f51cb42bacdc 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "board-params-setter.h"
 #include "board-params-util.h"
+#include "board-params.h"
 
 #define BOARD_PARAM_PARAMS_LEN 3
 
@@ -102,35 +103,51 @@ static int upgrade_state_setter(char **params, size_t params_len)
        return  hal_device_board_set_upgrade_state(state_from, state_to);
 }
 
-static struct board_param_setter setters[] = {
-       {
+static struct board_param_setter g_setters[] = {
+       [BOARD_PARAMS_BOOT_MODE] = {
+               .param_name = "none",
+               .description = "None",
+               .setter = NULL
+       },
+       [BOARD_PARAMS_CURRENT_PARTITION] = {
+               .param_name = "none",
+               .description = "None",
+               .setter = NULL
+       },
+       [BOARD_PARAMS_PARTITION_AB] = {
                .param_name = "partition-ab",
                .description = "Switch partition between a/b. "
                                "1 param is required: <a, b or toggle>",
                .setter = partition_ab_setter
-       }, {
+       },
+       [BOARD_PARAMS_PARTITION_AB_CLONED] = {
                .param_name = "partition-ab-cloned",
                .description = "Set cloned flag 0 or 1. "
                                "1 param is required: <0 or 1>",
                .setter = partition_ab_cloned_setter
-       }, {
+       },
+       [BOARD_PARAMS_PARTITION_STATUS] = {
                .param_name = "partition-status",
                .description = "Set partition status. "
                                "2 params are required: <a, b>,<ok, failed or corrupted>",
                .setter = partition_status_setter
-       }, {
+       },
+       [BOARD_PARAMS_UPGRADE_PROGRESS_STATUS] = {
                .param_name = "upgrade-progress-status",
                .description = "Set upgrade progress status. 1 integer is requied: <-1 ~ 100>",
                .setter = upgrade_progress_status_setter
-       }, {
+       },
+       [BOARD_PARAMS_UPGRADE_TYPE] = {
                .param_name = "upgrade-type",
                .description = "Set upgrade type. 1 param is required: <online or offline>",
                .setter = upgrade_type_setter
-       }, {
+       },
+       [BOARD_PARAMS_UPGRADE_STATE] = {
                .param_name = "upgrade-state",
                .description = "Set upgrade state. 2 params are required.",
                .setter = upgrade_state_setter
-       }, {
+       },
+       [BOARD_PARAMS_MAX] = {
                /* sentinel for this array */
                .param_name = NULL,
                .description = NULL,
@@ -142,9 +159,12 @@ static int get_board_param_setter(const char *param_name, struct board_param_set
 {
        size_t param_name_len = strlen(param_name);
 
-       for (int i = 0; setters[i].param_name != NULL; ++i) {
-               if (strncmp(setters[i].param_name, param_name, param_name_len + 1) == 0) {
-                       *board_param_setter = &setters[i];
+       for (int i = 0; g_setters[i].param_name != NULL; ++i) {
+               if (g_setters[i].setter == NULL)
+                       continue;
+
+               if (strncmp(g_setters[i].param_name, param_name, param_name_len + 1) == 0) {
+                       *board_param_setter = &g_setters[i];
                        return 0;
                }
        }
@@ -155,10 +175,10 @@ static int get_board_param_setter(const char *param_name, struct board_param_set
 static void print_board_param_setters(void)
 {
        printf("Available board params:\n");
-       for (int i = 0; setters[i].param_name != NULL; ++i) {
-               if (setters[i].setter == NULL)
+       for (int i = 0; g_setters[i].param_name != NULL; ++i) {
+               if (g_setters[i].setter == NULL)
                        continue;
-               printf("    %s: %s\n", setters[i].param_name, setters[i].description);
+               printf("    %s: %s\n", g_setters[i].param_name, g_setters[i].description);
        }
 
        printf("\n"
index 6a65c2cd202c86cd23a8910f762550eb96247478..5cf1e1b293474f040db0b7d276a85a1392be166a 100644 (file)
 
 #include "board-params-getter.h"
 #include "board-params-setter.h"
+
+typedef enum {
+       BOARD_PARAMS_BOOT_NONE = -1,
+       BOARD_PARAMS_BOOT_MODE = 0,
+       BOARD_PARAMS_CURRENT_PARTITION,
+       BOARD_PARAMS_PARTITION_AB,
+       BOARD_PARAMS_PARTITION_AB_CLONED,
+       BOARD_PARAMS_PARTITION_STATUS,
+       BOARD_PARAMS_UPGRADE_PROGRESS_STATUS,
+       BOARD_PARAMS_UPGRADE_STATE,
+       BOARD_PARAMS_UPGRADE_TYPE,
+       BOARD_PARAMS_MAX,
+} board_params_e;