hdt: Execute hdt default callbacks in each mode if needed
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Wed, 25 Mar 2009 05:37:53 +0000 (22:37 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Wed, 25 Mar 2009 05:37:53 +0000 (22:37 -0700)
Impact: One can switch modes without going back through hdt

Given a command `dmi> show foo', the ordering of callbacks is now
the following:
1/ execute module 'foo' of commands set 'show' of mode dmi
2/ execute default callback of commands set 'show' of mode dmi
3/ [NEW] execute module 'foo' of commands set 'show' of mode hdt

(2/ is executed if 1/ doesn't exist, 3/ is executed if 2/ doesn't exist
either, if 3/ doesn't exist an error is displayed).

This allows for instance to switch between modes without exiting first
to hdt.

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

index 12bbb98..18c023d 100644 (file)
@@ -429,13 +429,17 @@ 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 != NULL &&
+                        current_mode->show_modules->default_callback != NULL)
+                       return current_mode->show_modules
+                                          ->default_callback(argc,
+                                                             argv,
+                                                             hardware);
                else {
-                       if (current_mode->show_modules != NULL &&
-                           current_mode->show_modules->default_callback != NULL)
-                               return current_mode->show_modules
-                                                  ->default_callback(argc,
-                                                                     argv,
-                                                                     hardware);
+                       find_cli_callback_descr(module, hdt_mode.show_modules,
+                                               &current_module);
+                       if (current_module != NULL)
+                               return current_module->exec(argc, argv, hardware);
                }
        } else if (!strncmp(command, CLI_SET, sizeof(CLI_SET) - 1)) {
                dprintf("CLI DEBUG: %s command detected\n", CLI_SET);
@@ -444,13 +448,17 @@ static void exec_command(char *line,
                /* Execute the callback */
                if (current_module != NULL)
                        return current_module->exec(argc, argv, hardware);
+               else if (current_mode->set_modules != NULL &&
+                        current_mode->set_modules->default_callback != NULL)
+                       return current_mode->set_modules
+                                          ->default_callback(argc,
+                                                             argv,
+                                                             hardware);
                else {
-                       if (current_mode->set_modules != NULL &&
-                           current_mode->set_modules->default_callback != NULL)
-                               return current_mode->set_modules
-                                                  ->default_callback(argc,
-                                                                     argv,
-                                                                     hardware);
+                       find_cli_callback_descr(module, hdt_mode.set_modules,
+                                               &current_module);
+                       if (current_module != NULL)
+                               return current_module->exec(argc, argv, hardware);
                }
        }
        dprintf("CLI DEBUG: callback not found!\n", argc);