On Tue, Jul 22, 2008 at 2:03 AM, Bean <[EMAIL PROTECTED]> wrote:
> Your idea seems fine, but there is a slightly efficiency issue. For
> example, when we need to call a function in the handler, we need to
> acquire it using name. We need to do this in every call, as the
> handler could be changed next time.
>
> My suggestion is to use function pointer instead of name, for example,
>
> grub_handler_register (&grub_handler_input_head, my_handler);
>
> Then we can always use grub_handler_input_head->getkey() to read a key.
>
> The drawback is that we need to define grub_handler_**_head as global 
> variable.
>

Hi,

Ok, I come up with a mixed solution. We can still register handler
using string, like this:

grub_handler_register ("input", my_input_handler);

We don't need grub_handler_add. Whenever it sees a new string,
grub_handler_register would create a item in the handler table.

To get the handler, we use:

grub_get_handler ("input", &local_input_handler_head);

The handler is managed as linked list, the head always points to
current selection, so we can use local_input_handler_head to call the
handler function.

To reduce unnecessary grub_get_handler calls, we export important
handler head as global variable, for example, we can use the following
in grub_main:

grub_get_handler ("input", &grub_input_handler_head);
grub_get_handler ("output", &grub_output_handler_head);
...

Other modules can use grub_input_handler_head directly to access input
handlers, but for custom handler such as "foo", they need to use
grub_get_handler to get the handler pointer.

-- 
Bean


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to