Skip to contentSkip to conversation

GSoC #03 Menu viewer interface

PATCH New Colin D Bennett 1 participant 1 message Aug 31, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 GSoC #03 Menu viewer interface

This patch introduces a "menu viewer" handler interface. This will allow the graphical menu to be used interchangeably with the terminal based menu that normal.mod provides.

Regards,
Colin

2008-08-30 Colin D Bennett <[email protected]>

Introduced menu_viewer interface.

* include/grub/menu.h: Added.
* include/grub/menu_viewer.h: Added.
* kern/menu_viewer.c: Added.

* include/grub/normal.h (grub_menu_entry): Removed (moved to include/grub/menu.h).
(grub_menu): Likewise. (grub_normal_terminal_menu_viewer): New variable. (grub_menu_run): Removed. (grub_menu_execute_entry): New prototype.

* normal/main.c (grub_normal_execute): Use the menu viewer interface to display the menu.
(GRUB_MODE_INIT): Register the normal.mod 'terminal' menu viewer.

* normal/menu.c (run_menu_entry): Renamed to grub_menu_execute_entry. (grub_menu_execute_entry): Renamed from run_menu_entry, and made it global instead of static.
(grub_menu_run): Renamed to show_menu, and made it static.. (show_menu): Renamed from grub_menu_run. (grub_normal_terminal_menu_viewer): Handler struct definition for the menu viewer interface.
* conf/i386-pc.rmk: Add menu_viewer .c and .h files to kernel.

=== modified file 'conf/i386-pc.rmk'

i386-pc.rmk +2 -0
@@ -49,11 +49,13 @@
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c \
 	kern/env.c \
+	kern/menu_viewer.c \
 	term/i386/pc/console.c \
 	symlist.c
 kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
 	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
+	menu_viewer.h \
 	machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
 	machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \
 	machine/kernel.h machine/pxe.h

=== added file 'include/grub/menu.h'

grub/menu.h +51 -0

51 lines not on this page · raw message

=== added file 'include/grub/menu_viewer.h'

grub/menu_viewer.h +43 -0

43 lines not on this page · raw message

=== modified file 'include/grub/normal.h'

grub/normal.h +4 -29
@@ -25,6 +25,7 @@
 #include <grub/err.h>
 #include <grub/arg.h>
 #include <grub/env.h>
+#include <grub/menu.h>
 
 /* The maximum size of a command-line.  */
 #define GRUB_MAX_CMDLINE	1600
@@ -84,34 +85,6 @@
 };
 typedef struct grub_command *grub_command_t;
 
-/* The menu entry.  */
-struct grub_menu_entry
-{
-  /* The title name.  */
-  const char *title;
-
-    /* The commands associated with this menu entry.  */
-  struct grub_script *commands;
-
-  /* The sourcecode of the menu entry, used by the editor.  */
-  const char *sourcecode;
-
-  /* The next element.  */
-  struct grub_menu_entry *next;
-};
-typedef struct grub_menu_entry *grub_menu_entry_t;
-
-/* The menu.  */
-struct grub_menu
-{
-  /* The size of a menu.  */
-  int size;
-
-  /* The list of menu entries.  */
-  grub_menu_entry_t entry_list;
-};
-typedef struct grub_menu *grub_menu_t;
-
 /* This is used to store the names of filesystem modules for auto-loading.  */
 struct grub_fs_module_list
 {
@@ -123,10 +96,12 @@
 /* To exit from the normal mode.  */
 extern grub_jmp_buf grub_exit_env;
 
+extern struct grub_menu_viewer grub_normal_terminal_menu_viewer;
+
 void grub_enter_normal_mode (const char *config);
 void grub_normal_execute (const char *config, int nested);
-void grub_menu_run (grub_menu_t menu, int nested);
 void grub_menu_entry_run (grub_menu_entry_t entry);
+void grub_menu_execute_entry(grub_menu_entry_t entry);
 void grub_cmdline_run (int nested);
 int grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
 		      int echo_char, int readline);

=== added file 'kern/menu_viewer.c'

menu_viewer.c +63 -0

63 lines not on this page · raw message

=== modified file 'normal/main.c'

main.c +4 -1
@@ -28,6 +28,7 @@
 #include <grub/env.h>
 #include <grub/parser.h>
 #include <grub/script.h>
+#include <grub/menu_viewer.h>
 
 grub_jmp_buf grub_exit_env;
 
@@ -476,7 +477,7 @@
 
   if (menu && menu->size)
     {
-      grub_menu_run (menu, nested);
+      grub_menu_viewer_show_menu (menu, nested);
       if (nested)
 	free_menu (menu);
     }
@@ -519,6 +520,8 @@
   if (mod)
     grub_dl_ref (mod);
 
+  grub_menu_viewer_register (&grub_normal_terminal_menu_viewer);
+
   grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
 
   /* Register a command "normal" for the rescue mode.  */

=== modified file 'normal/menu.c'

menu.c +15 -6
@@ -24,6 +24,7 @@
 #include <grub/time.h>
 #include <grub/env.h>
 #include <grub/script.h>
+#include <grub/menu_viewer.h>
 
 static grub_uint8_t grub_color_menu_normal;
 static grub_uint8_t grub_color_menu_highlight;
@@ -497,8 +498,8 @@
 }
 
 /* Run a menu entry.  */
-static void
-run_menu_entry (grub_menu_entry_t entry)
+void
+grub_menu_execute_entry(grub_menu_entry_t entry)
 {
   grub_script_execute (entry->commands);
   
@@ -507,8 +508,8 @@
     grub_command_execute ("boot", 0);
 }
 
-void
-grub_menu_run (grub_menu_t menu, int nested)
+static grub_err_t
+show_menu (grub_menu_t menu, int nested)
 {
   while (1)
     {
@@ -529,7 +530,7 @@
 
       grub_printf ("  Booting \'%s\'\n\n", e->title);
   
-      run_menu_entry (e);
+      grub_menu_execute_entry (e);
 
       /* Deal with a fallback entry.  */
       /* FIXME: Multiple fallback entries like GRUB Legacy.  */
@@ -542,7 +543,7 @@
 	  e = get_entry (menu, fallback_entry);
 	  grub_env_unset ("fallback");
 	  grub_printf ("\n  Falling back to \'%s\'\n\n", e->title);
-	  run_menu_entry (e);
+	  grub_menu_execute_entry (e);
 	}
 
       if (grub_errno != GRUB_ERR_NONE)
@@ -553,4 +554,12 @@
 	  grub_wait_after_message ();
 	}
     }
+
+  return GRUB_ERR_NONE;
 }
+
+struct grub_menu_viewer grub_normal_terminal_menu_viewer =
+{
+  .name = "terminal",
+  .show_menu = show_menu
+};