foobar2000 SDK  2015-08-03
completion_notify.h
Go to the documentation of this file.
1 #include <functional>
2 
5 public:
9  virtual void on_completion(unsigned p_code) = 0;
10 
12  void on_completion_async(unsigned p_code);
13 
15  static void g_signal_completion_async(service_ptr_t<completion_notify> p_notify,unsigned p_code);
16 
18 };
19 
22 public:
23  void on_completion(unsigned p_code) {}
24 };
25 
28 public:
29  virtual void orphan() = 0;
30 };
31 
34 template<typename t_receiver>
36 public:
37  void on_completion(unsigned p_code) {
38  if (m_receiver != NULL) {
39  m_receiver->on_task_completion(m_taskid,p_code);
40  }
41  }
42  void setup(t_receiver * p_receiver, unsigned p_task_id) {m_receiver = p_receiver; m_taskid = p_task_id;}
43  void orphan() {m_receiver = NULL; m_taskid = 0;}
44 private:
45  t_receiver * m_receiver;
46  unsigned m_taskid;
47 };
48 
49 template<typename t_receiver>
50 service_nnptr_t<completion_notify_orphanable> completion_notify_create(t_receiver * p_receiver,unsigned p_taskid) {
52  instance->setup(p_receiver,p_taskid);
53  return instance;
54 }
55 
60 
63 public:
64  completion_notify::ptr create_or_get_task(unsigned p_id);
65  completion_notify_ptr create_task(unsigned p_id);
66  bool have_task(unsigned p_id) const;
67  void orphan_task(unsigned p_id);
69  void orphan_all_tasks();
70 
71  virtual void on_task_completion(unsigned p_id,unsigned p_status) {}
72 private:
73  static void orphanfunc(unsigned,completion_notify_orphanable_nnptr p_item) {p_item->orphan();}
75 };
76 
77 namespace fb2k {
78 
79  typedef std::function<void (unsigned)> completionNotifyFunc_t;
80 
82  completion_notify::ptr makeCompletionNotify( completionNotifyFunc_t );
83 }
void on_completion(unsigned p_code)
Called when an async operation has been completed. Note that on_completion is always called from main...
Generic service for receiving notifications about async operation completion. Used by various other s...
Definition: map.h:16
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
service_ptr_t< completion_notify > completion_notify_ptr
static void g_signal_completion_async(service_ptr_t< completion_notify > p_notify, unsigned p_code)
Helper. Checks for null ptr and calls on_completion_async when the ptr is not null.
virtual void on_task_completion(unsigned p_id, unsigned p_status)
Implementation helper.
FB2K_MAKE_SERVICE_INTERFACE(completion_notify, service_base)
Implementation helper.
service_nnptr_t< completion_notify_orphanable > completion_notify_orphanable_nnptr
void on_completion(unsigned p_code)
Called when an async operation has been completed. Note that on_completion is always called from main...
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes. This assumes that the pointers are valid all the time (can&#39;t point to null). Mainly intended to be used for scenarios where null pointers are not valid and relevant code should crash ASAP if somebody passes invalid pointers around. You want to use service_ptr_t<> rather than service_nnptr_t<> most of the time.
Definition: service.h:51
void on_completion_async(unsigned p_code)
Helper. Queues a notification, using main_thread_callback.
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
service_ptr_t< completion_notify_orphanable > completion_notify_orphanable_ptr
completion_notify::ptr makeCompletionNotify(completionNotifyFunc_t func)
Modern completion_notify helper.
service_nnptr_t< completion_notify > completion_notify_nnptr
Helper implementation. IMPLEMENTATION WARNING: If process being completed creates a window taking cal...
std::function< void(unsigned)> completionNotifyFunc_t
void setup(t_receiver *p_receiver, unsigned p_task_id)
Helper base class for classes that manage nonblocking tasks and get notified back thru completion_not...
service_nnptr_t< completion_notify_orphanable > completion_notify_create(t_receiver *p_receiver, unsigned p_taskid)
static void orphanfunc(unsigned, completion_notify_orphanable_nnptr p_item)
pfc::map_t< unsigned, completion_notify_orphanable_nnptr > m_tasks
virtual void on_completion(unsigned p_code)=0
Called when an async operation has been completed. Note that on_completion is always called from main...