hdt: Convert syslinux module to use the new framework
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 03:01:30 +0000 (20:01 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 03:01:30 +0000 (20:01 -0700)
Impact: Add the concept of default_callback per set of modules

Syslinux only implements a default show command. Previously, this was
triggered by the `show list' command line. It is not really intuitive
and may be confusing (it has another meaning in the DMI module).

There is now the concept of default callback, one that would be
triggered when only `show', `set', ... is entered in the command line.
A common usecase may be that `show' triggers a summary display.

Misc.: small fix in the DMI module.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/hdt/hdt-cli-dmi.c
com32/hdt/hdt-cli-syslinux.c
com32/hdt/hdt-cli.c
com32/hdt/hdt-cli.h

index 6fb954e..5025bd3 100644 (file)
@@ -456,7 +456,7 @@ struct cli_module_descr dmi_show_modules = {
 
 struct cli_mode_descr dmi_mode = {
        .mode = DMI_MODE,
-       .name = "dmi",
+       .name = CLI_DMI,
        .default_modules = NULL,
        .show_modules = &dmi_show_modules,
        .set_modules = NULL,
index e483864..168a3d3 100644 (file)
@@ -47,26 +47,16 @@ void main_show_syslinux(int argc __unused, char **argv __unused,
   more_printf(" Copyright  : %s\n", hardware->sv->copyright_string + 1);
 }
 
-static void show_syslinux_help()
-{
-  more_printf("Show supports the following commands : %s\n",
-              CLI_SHOW_LIST);
-}
+struct cli_module_descr syslinux_show_modules = {
+       .modules = NULL,
+       .nb_modules = 0,
+       .default_callback = main_show_syslinux,
+};
 
-static void syslinux_show(char *item, struct s_hardware *hardware)
-{
-  if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
-    main_show_syslinux(0, NULL, hardware);
-    return;
-  }
-  show_syslinux_help();
-}
-
-void handle_syslinux_commands(char *cli_line, struct s_hardware *hardware)
-{
-  if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
-    syslinux_show(strstr(cli_line, "show") + sizeof(CLI_SHOW),
-                  hardware);
-    return;
-  }
-}
+struct cli_mode_descr syslinux_mode = {
+       .mode = SYSLINUX_MODE,
+       .name = CLI_SYSLINUX,
+       .default_modules = NULL,
+       .show_modules = &syslinux_show_modules,
+       .set_modules = NULL,
+};
index 99163c4..a35eed2 100644 (file)
@@ -36,6 +36,7 @@
 struct cli_mode_descr *list_modes[] = {
        &hdt_mode,
        &dmi_mode,
+       &syslinux_mode,
 };
 
 /**
@@ -333,12 +334,26 @@ static void exec_command(char *line,
                /* Execute the callback */
                if (current_module != NULL)
                        return current_module->exec(argc, argv, hardware);
+               else {
+                       if (current_mode->show_modules->default_callback != NULL)
+                               return current_mode->show_modules
+                                                  ->default_callback(argc,
+                                                                     argv,
+                                                                     hardware);
+               }
        } else if (!strncmp(line, CLI_SET, sizeof(CLI_SET) - 1)) {
                find_cli_callback_descr(module, current_mode->set_modules,
                                        &current_module);
                /* Execute the callback */
                if (current_module != NULL)
                        return current_module->exec(argc, argv, hardware);
+               else {
+                       if (current_mode->set_modules->default_callback != NULL)
+                               return current_mode->set_modules
+                                                  ->default_callback(argc,
+                                                                     argv,
+                                                                     hardware);
+               }
        }
        dprintf("CLI DEBUG: callback not found!\n", argc);
 
@@ -364,9 +379,6 @@ old_cli:
        case VESA_MODE:
                handle_vesa_commands(line, hardware);
                break;
-       case SYSLINUX_MODE:
-               handle_syslinux_commands(line, hardware);
-               break;
        case KERNEL_MODE:
                handle_kernel_commands(line, hardware);
                break;
index 186c015..99e9cc6 100644 (file)
@@ -104,6 +104,7 @@ struct cli_mode_descr {
 struct cli_module_descr {
        struct cli_callback_descr* modules;
        const int nb_modules;
+       void ( * default_callback ) ( int argc, char** argv, struct s_hardware *hardware );
 };
 
 /* Describe a callback (belongs to a mode and a module) */
@@ -113,10 +114,11 @@ struct cli_callback_descr {
 };
 
 /* List of implemented modes */
-#define MAX_MODES 2
+#define MAX_MODES 3
 struct cli_mode_descr *list_modes[MAX_MODES];
 struct cli_mode_descr hdt_mode;
 struct cli_mode_descr dmi_mode;
+struct cli_mode_descr syslinux_mode;
 
 /* cli helpers */
 void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found);