foobar2000 SDK  2015-01-14
threaded_process.h
Go to the documentation of this file.
1 class NOVTABLE threaded_process_status {
3 public:
4  enum {progress_min = 0, progress_max = 5000};
5 
7  virtual void set_progress(t_size p_state) = 0;
9  virtual void set_progress_secondary(t_size p_state) = 0;
11  virtual void set_item(const char * p_item,t_size p_item_len = ~0) = 0;
13  virtual void set_item_path(const char * p_item,t_size p_item_len = ~0) = 0;
15  virtual void set_title(const char * p_title,t_size p_title_len = ~0) = 0;
17  virtual void force_update() = 0;
19  virtual bool is_paused() = 0;
20 
23  virtual bool process_pause() = 0;
24 
26  void poll_pause() {if (!process_pause()) throw exception_aborted();}
27 
29  void set_progress(t_size p_state,t_size p_max);
31  void set_progress_secondary(t_size p_state,t_size p_max);
33  void set_progress_float(double p_state);
35  void set_progress_secondary_float(double p_state);
36 protected:
39 };
40 
42 class NOVTABLE threaded_process_callback : public service_base {
43 public:
46  virtual void on_init(HWND p_wnd) {}
48  virtual void run(threaded_process_status & p_status,abort_callback & p_abort) = 0;
50  virtual void on_done(HWND p_wnd,bool p_was_aborted) {}
51 
52  FB2K_MAKE_SERVICE_INTERFACE(threaded_process_callback,service_base);
53 };
54 
55 
58 class NOVTABLE threaded_process : public service_base {
59 public:
60  enum {
62  flag_show_abort = 1,
64  flag_show_minimize = 1 << 1,
66  flag_show_progress = 1 << 2,
68  flag_show_progress_dual = 1 << 3,
70  flag_show_item = 1 << 4,
72  flag_show_pause = 1 << 5,
74  flag_high_priority = 1 << 6,
76  flag_show_delayed = 1 << 7,
78  flag_no_focus = 1 << 8,
79  };
80 
88  virtual bool run_modal(service_ptr_t<threaded_process_callback> p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len = ~0) = 0;
95  virtual bool run_modeless(service_ptr_t<threaded_process_callback> p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len = ~0) = 0;
96 
97 
99  static bool g_run_modal(service_ptr_t<threaded_process_callback> p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len = ~0);
101  static bool g_run_modeless(service_ptr_t<threaded_process_callback> p_callback,unsigned p_flags,HWND p_parent,const char * p_title,t_size p_title_len = ~0);
102 
104  static bool g_query_preventStandby();
105 
106  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(threaded_process);
107 };
108 
109 
111 template<typename TTarget> class threaded_process_callback_redir : public threaded_process_callback {
112 public:
113  threaded_process_callback_redir(TTarget * target) : m_target(target) {}
114  void on_init(HWND p_wnd) {m_target->tpc_on_init(p_wnd);}
115  void run(threaded_process_status & p_status,abort_callback & p_abort) {m_target->tpc_run(p_status, p_abort);}
116  void on_done(HWND p_wnd,bool p_was_aborted) {m_target->tpc_on_done(p_wnd, p_was_aborted); }
117 private:
119 };
virtual void on_done(HWND p_wnd, bool p_was_aborted)
Called after the worker thread has finished executing.
void poll_pause()
Automatically sleeps if the process is paused.
Callback class passed to your threaded_process client code; allows you to give various visual feedbac...
Helper - forward threaded_process_callback calls to a service object that for whatever reason cannot ...
virtual void on_init(HWND p_wnd)
Called from the main thread before spawning the worker thread. Note that you should not access the w...
void run(threaded_process_status &p_status, abort_callback &p_abort)
Called from the worker thread. Do all the hard work here.
size_t t_size
Definition: int_types.h:48
Callback class for the threaded_process API. You must implement this to create your own threaded_proc...
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
void on_init(HWND p_wnd)
Called from the main thread before spawning the worker thread. Note that you should not access the w...
void on_done(HWND p_wnd, bool p_was_aborted)
Called after the worker thread has finished executing.
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
threaded_process_callback_redir(TTarget *target)
The threaded_process API allows you to easily put timeconsuming tasks in worker threads, with progress dialog giving nice feedback to the user. Thanks to this API you can perform such tasks with no user interface related programming at all.
const service_ptr_t< TTarget > m_target