foobar2000 SDK  2015-08-03
completion_notify.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 namespace {
4  class main_thread_callback_myimpl : public main_thread_callback {
5  public:
6  void callback_run() {
7  m_notify->on_completion(m_code);
8  }
9 
10  main_thread_callback_myimpl(completion_notify_ptr p_notify,unsigned p_code) : m_notify(p_notify), m_code(p_code) {}
11  private:
12  completion_notify_ptr m_notify;
13  unsigned m_code;
14  };
15 }
16 
18  if (p_notify.is_valid()) {
20  }
21 }
22 
25 }
26 
27 
28 completion_notify::ptr completion_notify_receiver::create_or_get_task(unsigned p_id) {
30  if (!m_tasks.query(p_id,ptr)) {
31  ptr = completion_notify_create(this,p_id);
32  m_tasks.set(p_id,ptr);
33  }
34  return ptr;
35 }
36 
39  if (m_tasks.query(p_id,ptr)) ptr->orphan();
40  ptr = completion_notify_create(this,p_id);
41  m_tasks.set(p_id,ptr);
42  return ptr;
43 }
44 
45 bool completion_notify_receiver::have_task(unsigned p_id) const {
46  return m_tasks.have_item(p_id);
47 }
48 
51  if (m_tasks.query(p_id,ptr)) {
52  ptr->orphan();
53  m_tasks.remove(p_id);
54  }
55 }
56 
58  orphan_all_tasks();
59 }
60 
62  m_tasks.enumerate(orphanfunc);
63  m_tasks.remove_all();
64 }
65 
66 namespace {
67  using namespace fb2k;
68 
69  class completion_notify_func : public completion_notify {
70  public:
71  void on_completion(unsigned p_code) {
72  m_func(p_code);
73  }
74 
76  };
77 }
78 
79 namespace fb2k {
80 
81  completion_notify::ptr makeCompletionNotify( completionNotifyFunc_t func ) {
83  n->m_func = func;
84  return n;
85  }
86 
87 }
Generic service for receiving notifications about async operation completion. Used by various other s...
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
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.
bool is_valid() const
Definition: service.h:119
void on_completion_async(unsigned p_code)
Helper. Queues a notification, using main_thread_callback.
completion_notify::ptr makeCompletionNotify(completionNotifyFunc_t func)
Modern completion_notify helper.
completion_notify_ptr create_task(unsigned p_id)
std::function< void(unsigned)> completionNotifyFunc_t
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)
virtual void callback_run()=0
Gets called from main app thread. See main_thread_callback_manager description for more info...
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
Callback object class for main_thread_callback_manager service.