[syslinux] Patch sensible callback framework
Ayvaz, James
James.Ayvaz at hp.com
Wed Apr 28 15:17:16 PDT 2010
> and probably information from the invocation point, e.g. the file descriptor/file pointer.
Sorry, I guess I'm a bit rusty, but is there a generic way to do this?
int invoke_callbacks(callback_record *head, ??? args) {
callback_record *curr;
if (!head) {
return -1;
}
do {
curr = head;
curr->function(args);
curr = curr->next;
} while(curr);
}
And call it like this, with different arguments at each invocation point:
invoke_callbacks(CB_FLOADFILE, clen, -1);
invoke_callbacks(CB_LOADFILE, curr_filename, cur, total);
Thanks.
-----Original Message-----
From: syslinux-bounces at zytor.com [mailto:syslinux-bounces at zytor.com] On Behalf Of H. Peter Anvin
Sent: Tuesday, April 27, 2010 4:38 PM
To: syslinux at zytor.com
Subject: Re: [syslinux] Patch sensible callback framework
On 04/26/2010 08:35 PM, Ayvaz, James wrote:
> This patch adds a simple callback framework.
>
> Modified loadfile and floadfile to look for callbacks and call them if present
>
> Supports multiple callbacks
>
> Modified com32/modules/linux.c to demonstrate functionality (it's a little more complicated than it should be just to demonstrate multiple callbacks). Add progress argument to display a percentage indicator when loading.
>
> Example
>
> boot: linux progress
> Loading vmlinuz 100%
> Loading initrd.img 100%
>
>
> Let me know if you spot any problems. Thanks.
>
This looks a lot better, but I think we can improve it further.
In particular:
a) let register_callback() return a callback record pointer (or NULL on
failure). This pointer can then be passed to unregister_callback()
instead of doing a linear search.
b) Instead of using an integer type for the callback type, make it the
head of a callback list (which is just exported as a normal variable.)
First of all, it makes it easy to create new callbacks, and second, it
means we don't have to walk the whole list of callbacks when we invoke
it; we just walk the exact list of callbacks that we care about.
c) Make the invocation points smaller, e.g. by an callbacks_invoke()
helper function.
d) I suspect we need to pass a few options to the callback. In
particular, we should have a user argument (typically a void *) which is
passed in at register_callback() time, and probably information from the
invocation point, e.g. the file descriptor/file pointer.
-hpa
_______________________________________________
Syslinux mailing list
Submissions to Syslinux at zytor.com
Unsubscribe or set options at:
http://www.zytor.com/mailman/listinfo/syslinux
Please do not send private replies to mailing list traffic.
More information about the Syslinux
mailing list