[syslinux] Patch sensible callback framework
H. Peter Anvin
hpa at zytor.com
Wed Apr 28 16:16:47 PDT 2010
On 04/28/2010 03:17 PM, Ayvaz, James wrote:
>> 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);
>
We could have invoke_callbacks take an ellipsis operator, and pass a
va_list to the called routine:
#include <stdarg.h>
void invoke_callbacks(const callback_record *head, ...)
{
va_list ap;
while (head) {
va_start(ap, head);
head->function(head->pvt, ap);
va_end(ap);
head = head->next;
}
}
This of course means that the callback needs to process the va_list
appropriately.
-hpa
More information about the Syslinux
mailing list