foobar2000 SDK
2015-08-03
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
foobar2000
SDK
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
17
void
completion_notify::g_signal_completion_async
(
completion_notify_ptr
p_notify,
unsigned
p_code) {
18
if
(p_notify.
is_valid
()) {
19
static_api_ptr_t<main_thread_callback_manager>
()->add_callback(
new
service_impl_t<main_thread_callback_myimpl>
(p_notify,p_code));
20
}
21
}
22
23
void
completion_notify::on_completion_async
(
unsigned
p_code) {
24
static_api_ptr_t<main_thread_callback_manager>
()->add_callback(
new
service_impl_t<main_thread_callback_myimpl>
(
this
,p_code));
25
}
26
27
28
completion_notify::ptr
completion_notify_receiver::create_or_get_task
(
unsigned
p_id) {
29
completion_notify_orphanable_ptr
ptr;
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
37
completion_notify_ptr
completion_notify_receiver::create_task
(
unsigned
p_id) {
38
completion_notify_orphanable_ptr
ptr;
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
49
void
completion_notify_receiver::orphan_task
(
unsigned
p_id) {
50
completion_notify_orphanable_ptr
ptr;
51
if
(m_tasks.query(p_id,ptr)) {
52
ptr->orphan();
53
m_tasks.remove(p_id);
54
}
55
}
56
57
completion_notify_receiver::~completion_notify_receiver
() {
58
orphan_all_tasks();
59
}
60
61
void
completion_notify_receiver::orphan_all_tasks
() {
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
75
completionNotifyFunc_t
m_func;
76
};
77
}
78
79
namespace
fb2k
{
80
81
completion_notify::ptr
makeCompletionNotify
(
completionNotifyFunc_t
func ) {
82
service_ptr_t<completion_notify_func>
n =
new
service_impl_t< completion_notify_func >
;
83
n->m_func = func;
84
return
n;
85
}
86
87
}
completion_notify
Generic service for receiving notifications about async operation completion. Used by various other s...
Definition:
completion_notify.h:4
completion_notify_receiver::have_task
bool have_task(unsigned p_id) const
Definition:
completion_notify.cpp:45
completion_notify_receiver::orphan_task
void orphan_task(unsigned p_id)
Definition:
completion_notify.cpp:49
service_impl_t
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition:
service_impl.h:4
completion_notify::g_signal_completion_async
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.
Definition:
completion_notify.cpp:17
service_ptr_t::is_valid
bool is_valid() const
Definition:
service.h:119
completion_notify_receiver::orphan_all_tasks
void orphan_all_tasks()
Definition:
completion_notify.cpp:61
completion_notify::on_completion_async
void on_completion_async(unsigned p_code)
Helper. Queues a notification, using main_thread_callback.
Definition:
completion_notify.cpp:23
completion_notify_receiver::~completion_notify_receiver
~completion_notify_receiver()
Definition:
completion_notify.cpp:57
fb2k::makeCompletionNotify
completion_notify::ptr makeCompletionNotify(completionNotifyFunc_t func)
Modern completion_notify helper.
Definition:
completion_notify.cpp:81
completion_notify_receiver::create_task
completion_notify_ptr create_task(unsigned p_id)
Definition:
completion_notify.cpp:37
foobar2000.h
fb2k::completionNotifyFunc_t
std::function< void(unsigned)> completionNotifyFunc_t
Definition:
completion_notify.h:79
completion_notify_create
service_nnptr_t< completion_notify_orphanable > completion_notify_create(t_receiver *p_receiver, unsigned p_taskid)
Definition:
completion_notify.h:50
completion_notify_receiver::create_or_get_task
completion_notify::ptr create_or_get_task(unsigned p_id)
Definition:
completion_notify.cpp:28
service_ptr_t< completion_notify >
main_thread_callback::callback_run
virtual void callback_run()=0
Gets called from main app thread. See main_thread_callback_manager description for more info...
static_api_ptr_t
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition:
service.h:533
fb2k
Definition:
completion_notify.cpp:79
main_thread_callback
Callback object class for main_thread_callback_manager service.
Definition:
main_thread_callback.h:4
Generated by
1.8.11