2009-08-17 Robert Millan <rmh.grub@aybabtu.com>
[grub2/phcoder/solaris.git] / kern / handler.c
blob2bf85313cfa1d8b393807fbb677dc3453c91593e
1 /* handler.c - grub handler function */
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 #include <grub/handler.h>
22 grub_handler_class_t grub_handler_class_list;
24 void
25 grub_handler_register (grub_handler_class_t class, grub_handler_t handler)
27 int first_handler = (class->handler_list == 0);
29 grub_list_push (GRUB_AS_LIST_P (&class->handler_list),
30 GRUB_AS_LIST (handler));
32 if (first_handler)
34 grub_list_push (GRUB_AS_LIST_P (&grub_handler_class_list),
35 GRUB_AS_LIST (class));
36 grub_handler_set_current (class, handler);
40 void
41 grub_handler_unregister (grub_handler_class_t class, grub_handler_t handler)
43 grub_list_remove (GRUB_AS_LIST_P (&class->handler_list),
44 GRUB_AS_LIST (handler));
46 if (class->handler_list == 0)
47 grub_list_remove (GRUB_AS_LIST_P (&grub_handler_class_list),
48 GRUB_AS_LIST (class));
51 grub_err_t
52 grub_handler_set_current (grub_handler_class_t class, grub_handler_t handler)
54 if (class->cur_handler && class->cur_handler->fini)
55 if ((class->cur_handler->fini) () != GRUB_ERR_NONE)
56 return grub_errno;
58 if (handler->init)
59 if ((handler->init) () != GRUB_ERR_NONE)
60 return grub_errno;
62 class->cur_handler = handler;
63 return GRUB_ERR_NONE;