Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/initquit.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 //! Basic callback startup/shutdown callback, on_init is called after the main window has been created, on_quit is called before the main window is destroyed. \n | |
| 3 //! To register: static initquit_factory_t<myclass> myclass_factory; \n | |
| 4 //! Note that you should be careful with calling other components during on_init/on_quit or \n | |
| 5 //! initializing services that are possibly used by other components by on_init/on_quit - \n | |
| 6 //! initialization order of components is undefined. | |
| 7 //! If some other service that you publish is not properly functional before you receive an on_init() call, \n | |
| 8 //! someone else might call this service before >your< on_init is invoked. | |
| 9 class NOVTABLE initquit : public service_base { | |
| 10 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(initquit); | |
| 11 public: | |
| 12 virtual void on_init() {} | |
| 13 virtual void on_quit() {} | |
| 14 }; | |
| 15 | |
| 16 template<typename T> | |
| 17 class initquit_factory_t : public service_factory_single_t<T> {}; | |
| 18 | |
| 19 | |
| 20 //! \since 1.1 | |
| 21 namespace init_stages { | |
| 22 enum { | |
| 23 before_config_read = 10, | |
| 24 after_config_read = 20, | |
| 25 before_library_init = 30, | |
| 26 // Since foobar2000 v2.0, after_library_init is fired OUT OF ORDER with the rest, after ASYNCHRONOUS library init has completed. | |
| 27 after_library_init = 40, | |
| 28 before_ui_init = 50, | |
| 29 after_ui_init = 60, | |
| 30 }; | |
| 31 }; | |
| 32 | |
| 33 //! \since 1.1 | |
| 34 class NOVTABLE init_stage_callback : public service_base { | |
| 35 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(init_stage_callback) | |
| 36 public: | |
| 37 virtual void on_init_stage(t_uint32 stage) = 0; | |
| 38 | |
| 39 static void dispatch(t_uint32 stage) {FB2K_FOR_EACH_SERVICE(init_stage_callback, on_init_stage(stage));} | |
| 40 }; | |
| 41 | |
| 42 //! Helper for FB2K_RUN_ON_INIT_QUIT() | |
| 43 class initquit_lambda : public initquit { | |
| 44 public: | |
| 45 initquit_lambda(std::function<void()> i, std::function<void()> q) : m_init(i), m_quit(q) {} | |
| 46 void on_init() override { if (m_init) m_init(); } | |
| 47 void on_quit() override { if (m_quit) m_quit(); } | |
| 48 private: | |
| 49 const std::function<void()> m_init, m_quit; | |
| 50 }; | |
| 51 | |
| 52 //! Helper macros to skip implementing initquit.\n | |
| 53 //! Usage: \n | |
| 54 //! void myfunc() { ... } \n | |
| 55 //! FB2K_RUN_ON_INIT(myFunc); | |
| 56 #define FB2K_RUN_ON_INIT_QUIT(funcInit, funcQuit) FB2K_SERVICE_FACTORY_PARAMS(initquit_lambda, funcInit, funcQuit) | |
| 57 #define FB2K_RUN_ON_INIT(func) FB2K_RUN_ON_INIT_QUIT(func, nullptr) | |
| 58 #define FB2K_RUN_ON_QUIT(func) FB2K_RUN_ON_INIT_QUIT(nullptr, func) | |
| 59 | |
| 60 //! Helper for FB2K_ON_INIT_STAGE | |
| 61 class init_stage_callback_lambda : public init_stage_callback { | |
| 62 public: | |
| 63 init_stage_callback_lambda(std::function<void()> f, uint32_t stage) : m_func(f), m_stage(stage) {} | |
| 64 | |
| 65 void on_init_stage(t_uint32 stage) override { | |
| 66 PFC_ASSERT(m_func != nullptr); | |
| 67 if (stage == m_stage) m_func(); | |
| 68 } | |
| 69 | |
| 70 const std::function<void()> m_func; | |
| 71 const uint32_t m_stage; | |
| 72 }; | |
| 73 | |
| 74 //! Helper macro to skip implementing init_stage_callback.\n | |
| 75 //! Usage: \n | |
| 76 //! void myfunc() {...} \n | |
| 77 //! FB2K_ON_INIT_STAGE(myfunc, init_stages::after_ui_init); | |
| 78 #define FB2K_ON_INIT_STAGE(func, stage) FB2K_SERVICE_FACTORY_PARAMS(init_stage_callback_lambda, func, stage) |
