handler.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* handler.c - grub handler function */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2009 Free Software Foundation, Inc.
  5. *
  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.
  10. *
  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.
  15. *
  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/>.
  18. */
  19. #include <grub/handler.h>
  20. GRUB_EXPORT(grub_handler_class_list);
  21. GRUB_EXPORT(grub_handler_register);
  22. GRUB_EXPORT(grub_handler_unregister);
  23. GRUB_EXPORT(grub_handler_set_current);
  24. grub_handler_class_t grub_handler_class_list;
  25. void
  26. grub_handler_register (grub_handler_class_t class, grub_handler_t handler)
  27. {
  28. int first_handler = (class->handler_list == 0);
  29. grub_list_push (GRUB_AS_LIST_P (&class->handler_list),
  30. GRUB_AS_LIST (handler));
  31. if (first_handler)
  32. {
  33. grub_list_push (GRUB_AS_LIST_P (&grub_handler_class_list),
  34. GRUB_AS_LIST (class));
  35. grub_handler_set_current (class, handler);
  36. }
  37. }
  38. void
  39. grub_handler_unregister (grub_handler_class_t class, grub_handler_t handler)
  40. {
  41. grub_list_remove (GRUB_AS_LIST_P (&class->handler_list),
  42. GRUB_AS_LIST (handler));
  43. if (class->handler_list == 0)
  44. grub_list_remove (GRUB_AS_LIST_P (&grub_handler_class_list),
  45. GRUB_AS_LIST (class));
  46. }
  47. grub_err_t
  48. grub_handler_set_current (grub_handler_class_t class, grub_handler_t handler)
  49. {
  50. if (class->cur_handler && class->cur_handler->fini)
  51. if ((class->cur_handler->fini) () != GRUB_ERR_NONE)
  52. return grub_errno;
  53. if (handler->init)
  54. if ((handler->init) () != GRUB_ERR_NONE)
  55. return grub_errno;
  56. class->cur_handler = handler;
  57. return GRUB_ERR_NONE;
  58. }