foobar2000 SDK  2015-01-14
completion_notify.h
Go to the documentation of this file.
1 class completion_notify : public service_base {
3 public:
7  virtual void on_completion(unsigned p_code) = 0;
8 
10  void on_completion_async(unsigned p_code);
11 
13  static void g_signal_completion_async(service_ptr_t<completion_notify> p_notify,unsigned p_code);
14 
16 };
17 
20 public:
21  void on_completion(unsigned p_code) {}
22 };
23 
26 public:
27  virtual void orphan() = 0;
28 };
29 
32 template<typename t_receiver>
34 public:
35  void on_completion(unsigned p_code) {
36  if (m_receiver != NULL) {
37  m_receiver->on_task_completion(m_taskid,p_code);
38  }
39  }
40  void setup(t_receiver * p_receiver, unsigned p_task_id) {m_receiver = p_receiver; m_taskid = p_task_id;}
41  void orphan() {m_receiver = NULL; m_taskid = 0;}
42 private:
43  t_receiver * m_receiver;
44  unsigned m_taskid;
45 };
46 
47 template<typename t_receiver>
48 service_nnptr_t<completion_notify_orphanable> completion_notify_create(t_receiver * p_receiver,unsigned p_taskid) {
50  instance->setup(p_receiver,p_taskid);
51  return instance;
52 }
53 
58 
61 public:
62  completion_notify::ptr create_or_get_task(unsigned p_id) {
64  if (!m_tasks.query(p_id,ptr)) {
65  ptr = completion_notify_create(this,p_id);
66  m_tasks.set(p_id,ptr);
67  }
68  return ptr;
69  }
72  if (m_tasks.query(p_id,ptr)) ptr->orphan();
73  ptr = completion_notify_create(this,p_id);
74  m_tasks.set(p_id,ptr);
75  return ptr;
76  }
77  bool have_task(unsigned p_id) const {
78  return m_tasks.have_item(p_id);
79  }
80  void orphan_task(unsigned p_id) {
82  if (m_tasks.query(p_id,ptr)) {
83  ptr->orphan();
84  m_tasks.remove(p_id);
85  }
86  }
89  }
91  m_tasks.enumerate(orphanfunc);
92  m_tasks.remove_all();
93  }
94 
95  virtual void on_task_completion(unsigned p_id,unsigned p_status) {}
96 private:
97  static void orphanfunc(unsigned,completion_notify_orphanable_nnptr p_item) {p_item->orphan();}
99 };
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
bool have_task(unsigned p_id) const
void orphan_task(unsigned p_id)
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'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 create_task(unsigned p_id)
service_nnptr_t< completion_notify > completion_notify_nnptr
Helper implementation. IMPLEMENTATION WARNING: If process being completed creates a window taking cal...
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)
completion_notify::ptr create_or_get_task(unsigned p_id)
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...