---
com32/include/syslinux/callback.h | 67 ++++++++++++++++++++++++++++++++
com32/lib/syslinux/callback.c | 76 +++++++++++++++++++++++++++++++++++++
2 files changed, 143 insertions(+), 0 deletions(-)
create mode 100644 com32/include/syslinux/callback.h
create mode 100644 com32/lib/syslinux/callback.c
diff --git a/com32/include/syslinux/callback.h
b/com32/include/syslinux/callback.h
new file mode 100644
index 0000000..40de8f4
--- /dev/null
+++ b/com32/include/syslinux/callback.h
@@ -0,0 +1,67 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * syslinux/callback.h
+ *
+ * sensible callback framework
+ */
+
+#ifndef _SYSLINUX_CALLBACK_H
+#define _SYSLINUX_CALLBACK_H
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <assert.h>
+
+struct callback_record;
+
+typedef void (*callback_t)(const void *rarg, va_list ap);
+
+#define DECLARE_CALLBACK(name) \
+struct callback_record name = { \
+ .function = NULL, \
+ .next = &name, \
+ .prev = &name, \
+}
+
+
+struct callback_record {
+ callback_t function;
+ struct callback_record *next;
+ struct callback_record *prev;
+ const void *rarg;
+};
+
+
+struct callback_record* register_callback(struct callback_record *head,
callback_t callback, const void *rarg);
+int unregister_callback(struct callback_record *cb);
+int invoke_callbacks(struct callback_record *head, ...);
+
+#endif /* _SYSLINUX_CALLBACK_H */
diff --git a/com32/lib/syslinux/callback.c b/com32/lib/syslinux/callback.c
new file mode 100644
index 0000000..60d6025
--- /dev/null
+++ b/com32/lib/syslinux/callback.c
@@ -0,0 +1,76 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * syslinux/callback.c
+ *
+ * sensible callback framework
+ */
+
+#include <syslinux/callback.h>
+
+struct callback_record* register_callback(struct callback_record *head,
callback_t callback, const void *rarg)
+{
+ struct callback_record *new;
+
+ new = malloc(sizeof(struct callback_record));
+ if (!new)
+ return NULL;
+
+ new->function = callback;
+ new->rarg = rarg;
+ new->next = head->next;
+ new->prev = head;
+ head->next->prev = new;
+ head->next = new;
+ return new;
+}
+
+int unregister_callback(struct callback_record *cb)
+{
+ cb->next->prev = cb->prev;
+ cb->prev->next = cb->next;
+ free(cb);
+ return 0;
+}
+
+int invoke_callbacks(struct callback_record *head, ...)
+{
+ va_list ap;
+ struct callback_record *curr;
+
+ curr = head;
+ do {
+ if (curr->function) {
+ va_start(ap, head);
+ curr->function(curr->rarg, ap);
+ va_end(ap);
+ }
+ curr = curr->next;
+ } while(curr != head);
+ return 0;
+}
--
1.6.0.2
---
com32/include/syslinux/callback.h | 67 ++++++++++++++++++++++++++++++++
com32/lib/syslinux/callback.c | 76 +++++++++++++++++++++++++++++++++++++
2 files changed, 143 insertions(+), 0 deletions(-)
create mode 100644 com32/include/syslinux/callback.h
create mode 100644 com32/lib/syslinux/callback.c
diff --git a/com32/include/syslinux/callback.h
b/com32/include/syslinux/callback.h
new file mode 100644
index 0000000..40de8f4
--- /dev/null
+++ b/com32/include/syslinux/callback.h
@@ -0,0 +1,67 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * syslinux/callback.h
+ *
+ * sensible callback framework
+ */
+
+#ifndef _SYSLINUX_CALLBACK_H
+#define _SYSLINUX_CALLBACK_H
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <assert.h>
+
+struct callback_record;
+
+typedef void (*callback_t)(const void *rarg, va_list ap);
+
+#define DECLARE_CALLBACK(name) \
+struct callback_record name = { \
+ .function = NULL, \
+ .next = &name, \
+ .prev = &name, \
+}
+
+
+struct callback_record {
+ callback_t function;
+ struct callback_record *next;
+ struct callback_record *prev;
+ const void *rarg;
+};
+
+
+struct callback_record* register_callback(struct callback_record *head,
callback_t callback, const void *rarg);
+int unregister_callback(struct callback_record *cb);
+int invoke_callbacks(struct callback_record *head, ...);
+
+#endif /* _SYSLINUX_CALLBACK_H */
diff --git a/com32/lib/syslinux/callback.c b/com32/lib/syslinux/callback.c
new file mode 100644
index 0000000..60d6025
--- /dev/null
+++ b/com32/lib/syslinux/callback.c
@@ -0,0 +1,76 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * syslinux/callback.c
+ *
+ * sensible callback framework
+ */
+
+#include <syslinux/callback.h>
+
+struct callback_record* register_callback(struct callback_record *head,
callback_t callback, const void *rarg)
+{
+ struct callback_record *new;
+
+ new = malloc(sizeof(struct callback_record));
+ if (!new)
+ return NULL;
+
+ new->function = callback;
+ new->rarg = rarg;
+ new->next = head->next;
+ new->prev = head;
+ head->next->prev = new;
+ head->next = new;
+ return new;
+}
+
+int unregister_callback(struct callback_record *cb)
+{
+ cb->next->prev = cb->prev;
+ cb->prev->next = cb->next;
+ free(cb);
+ return 0;
+}
+
+int invoke_callbacks(struct callback_record *head, ...)
+{
+ va_list ap;
+ struct callback_record *curr;
+
+ curr = head;
+ do {
+ if (curr->function) {
+ va_start(ap, head);
+ curr->function(curr->rarg, ap);
+ va_end(ap);
+ }
+ curr = curr->next;
+ } while(curr != head);
+ return 0;
+}
--
1.6.0.2