|
1
|
1 #pragma once
|
|
|
2
|
|
|
3 #include <functional>
|
|
|
4
|
|
|
5 //! (DEPRECATED) This service is used to signal whether something is currently preventing main window from being closed and app from being shut down.
|
|
|
6 class NOVTABLE app_close_blocker : public service_base
|
|
|
7 {
|
|
|
8 public:
|
|
|
9 //! Checks whether this service is currently preventing main window from being closed and app from being shut down.
|
|
|
10 virtual bool query() = 0;
|
|
|
11
|
|
|
12 //! Static helper function, checks whether any of registered app_close_blocker services is currently preventing main window from being closed and app from being shut down.
|
|
|
13 static bool g_query();
|
|
|
14
|
|
|
15 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(app_close_blocker);
|
|
|
16 };
|
|
|
17
|
|
|
18 //! An interface encapsulating a task preventing the foobar2000 application from being closed. Instances of this class need to be registered using app_close_blocking_task_manager methods. \n
|
|
|
19 //! Implementation: it's recommended that you derive from app_close_blocking_task_impl class instead of deriving from app_close_blocking_task directly, it manages registration/unregistration behind-the-scenes.
|
|
|
20 class NOVTABLE app_close_blocking_task {
|
|
|
21 public:
|
|
|
22 //! Retrieves user-friendly name of the task to be shown to the user, should the user try to close foobar2000 while the task is active. \n
|
|
|
23 //! Implementation note: this will NOT be called from register_task() or unregister_task(), only in response to user attempting to close foobar2000. \n
|
|
|
24 //! Common helper implementations of app_close_blocking_task register from base class constructor while intended query_task_name() override is not yet in place.
|
|
|
25 virtual void query_task_name(pfc::string_base & out) = 0;
|
|
|
26
|
|
|
27 protected:
|
|
|
28 app_close_blocking_task() {}
|
|
|
29 ~app_close_blocking_task() {}
|
|
|
30
|
|
|
31 PFC_CLASS_NOT_COPYABLE_EX(app_close_blocking_task);
|
|
|
32 };
|
|
|
33
|
|
|
34 //! Entrypoint class for registering app_close_blocking_task instances. \n
|
|
|
35 //! You can use app_close_blocking_task_impl to call this automatically with your object.
|
|
|
36 class NOVTABLE app_close_blocking_task_manager : public service_base {
|
|
|
37 FB2K_MAKE_SERVICE_COREAPI(app_close_blocking_task_manager);
|
|
|
38 public:
|
|
|
39 //! Registers a task object. \n
|
|
|
40 //! Main thread only.
|
|
|
41 virtual void register_task(app_close_blocking_task * task) = 0;
|
|
|
42 //! Unregisters a task object. \n
|
|
|
43 //! Main thread only.
|
|
|
44 virtual void unregister_task(app_close_blocking_task * task) = 0;
|
|
|
45 };
|
|
|
46
|
|
|
47 //! Helper; implements standard functionality required by app_close_blocking_task implementations - registers/unregisters the task on construction/destruction.
|
|
|
48 class app_close_blocking_task_impl : public app_close_blocking_task {
|
|
|
49 public:
|
|
|
50 app_close_blocking_task_impl(const char * name = "<unnamed task>");
|
|
|
51 app_close_blocking_task_impl(pfc::string8&& name);
|
|
|
52 ~app_close_blocking_task_impl();
|
|
|
53
|
|
|
54 //! Override me, or provide name to constructor
|
|
|
55 void query_task_name(pfc::string_base & out) override;
|
|
|
56
|
|
|
57 app_close_blocking_task_impl( const app_close_blocking_task_impl & ) = delete;
|
|
|
58 void operator=(const app_close_blocking_task_impl & ) = delete;
|
|
|
59 private:
|
|
|
60 const pfc::string8 m_name;
|
|
|
61 };
|
|
|
62
|
|
|
63 class app_close_blocking_task_impl_dynamic : public app_close_blocking_task {
|
|
|
64 public:
|
|
|
65 app_close_blocking_task_impl_dynamic(const char * name = "<unnamed task>") : m_name(name) {}
|
|
|
66 ~app_close_blocking_task_impl_dynamic() { toggle_blocking(false); }
|
|
|
67
|
|
|
68 //! Override me, or provide name to constructor
|
|
|
69 void query_task_name(pfc::string_base & out) override;
|
|
|
70
|
|
|
71 void toggle_blocking(bool state);
|
|
|
72 private:
|
|
|
73 bool m_taskActive = false;
|
|
|
74 const pfc::string8 m_name;
|
|
|
75 };
|
|
|
76
|
|
|
77
|
|
|
78 //! \since 1.4.5
|
|
|
79 //! Provides means for async tasks - running detached from any UI - to reliably finish before the app terminates. \n
|
|
|
80 //! During a late phase of app shutdown, past initquit ops, when no worker code should be still running - a core-managed instance of abort_callback is signaled, \n
|
|
|
81 //! then main thread stalls until all objects created with acquire() have been released. \n
|
|
|
82 //! As this API was introduced out-of-band with 1.4.5, you should use tryGet() to obtain it with FOOBAR2000_TARGET_VERSION < 80, but can safely use ::get() with FOOBAR2000_TARGET_VERSION >= 80.
|
|
|
83 class async_task_manager : public service_base {
|
|
|
84 FB2K_MAKE_SERVICE_COREAPI( async_task_manager );
|
|
|
85 public:
|
|
|
86 virtual abort_callback & get_aborter() = 0;
|
|
|
87 virtual service_ptr acquire() = 0;
|
|
|
88
|
|
|
89 //! acquire() helper; returns nullptr if the API isn't available due to old fb2k
|
|
|
90 static service_ptr g_acquire();
|
|
|
91 };
|
|
|
92
|
|
|
93 // fb2k::spltiTask() moved to threadsLite.h
|