2009-07-20 Joe Auricchio <jauricchio@gmail.com>
[grub2/phcoder.git] / include / grub / handler.h
blob3331bb4177f619dc583272e911b826053f7d1857
1 /* handler.h - header for grub handler */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef GRUB_HANDLER_HEADER
21 #define GRUB_HANDLER_HEADER 1
23 #include <grub/list.h>
24 #include <grub/err.h>
26 struct grub_handler
28 struct grub_handler *next;
29 const char *name;
30 grub_err_t (*init) (void);
31 grub_err_t (*fini) (void);
33 typedef struct grub_handler *grub_handler_t;
35 struct grub_handler_class
37 struct grub_handler_class *next;
38 const char *name;
39 grub_handler_t handler_list;
40 grub_handler_t cur_handler;
42 typedef struct grub_handler_class *grub_handler_class_t;
44 extern grub_handler_class_t EXPORT_VAR(grub_handler_class_list);
46 void EXPORT_FUNC(grub_handler_register) (grub_handler_class_t class,
47 grub_handler_t handler);
48 void EXPORT_FUNC(grub_handler_unregister) (grub_handler_class_t class,
49 grub_handler_t handler);
50 grub_err_t EXPORT_FUNC(grub_handler_set_current) (grub_handler_class_t class,
51 grub_handler_t handler);
53 #define GRUB_AS_HANDLER(ptr) \
54 ((GRUB_FIELD_MATCH (ptr, grub_handler_t, next) && \
55 GRUB_FIELD_MATCH (ptr, grub_handler_t, name) && \
56 GRUB_FIELD_MATCH (ptr, grub_handler_t, init) && \
57 GRUB_FIELD_MATCH (ptr, grub_handler_t, fini)) ? \
58 (grub_handler_t) ptr : grub_assert_fail ())
60 #endif /* ! GRUB_HANDLER_HEADER */