tb_addon.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #include "tb_system.h"
  6. #include "tb_addon.h"
  7. namespace tb {
  8. // We can't use a linked list object since we don't know if its constructor
  9. // would run before of after any widget factory constructor that add itself
  10. // to it. Using a manual one way link list is very simple.
  11. TBAddonFactory *g_registered_addon_factories = nullptr;
  12. TBAddonFactory::TBAddonFactory()
  13. : next(g_registered_addon_factories)
  14. {
  15. g_registered_addon_factories = this;
  16. }
  17. // ======================================================================================
  18. TBLinkListOf<TBAddon> m_addons;
  19. bool TBInitAddons()
  20. {
  21. TBAddonFactory *f = g_registered_addon_factories;
  22. while (f)
  23. {
  24. TBAddon *addon = f->Create();
  25. if (!addon || !addon->Init())
  26. {
  27. delete addon;
  28. TBDebugOut("Failed initiating addon\n");
  29. return false;
  30. }
  31. m_addons.AddLast(addon);
  32. f = f->next;
  33. }
  34. return true;
  35. }
  36. void TBShutdownAddons()
  37. {
  38. while (TBAddon *addon = m_addons.GetLast())
  39. {
  40. addon->Shutdown();
  41. m_addons.Delete(addon);
  42. }
  43. }
  44. }; // namespace tb