-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallback.cpp
102 lines (95 loc) · 2.02 KB
/
callback.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <map>
#ifdef __cplusplus
extern "C" {
#endif
#include <Python.h>
#ifdef __cplusplus
}
#endif
#include "wkhtmltox/pdf.h"
#include "callback.h"
typedef std::map<wkhtmltopdf_converter*, convertor_callbacks_t> callback_map_t;
static callback_map_t callbacks;
#ifdef __cplusplus
extern "C" {
#endif
lookup_error_t add_callback(callback_type_t cb_type, wkhtmltopdf_converter *conv, PyObject *callback)
{
lookup_error_t res = LOOKUP_ERROR_SUCCESS;
switch(cb_type)
{
case PDF_CALLBACK_WARNING:
callbacks[conv].warning_cb = callback;
break;
case PDF_CALLBACK_ERROR:
callbacks[conv].error_cb = callback;
break;
case PDF_CALLBACK_FINISH:
callbacks[conv].finish_cb = callback;
break;
case PDF_CALLBACK_PROGRESS:
callbacks[conv].progress_cb = callback;
break;
case PDF_CALLBACK_PHASE:
callbacks[conv].phase_cb = callback;
break;
default:
res = LOOKUP_ERROR_FAIL;
break;
}
return res;
}
PyObject *get_callback(callback_type_t cb_type, wkhtmltopdf_converter *conv)
{
PyObject *res = NULL;
if (callbacks.count(conv))
{
switch(cb_type)
{
case PDF_CALLBACK_WARNING:
res = callbacks[conv].warning_cb;
break;
case PDF_CALLBACK_ERROR:
res = callbacks[conv].error_cb;
break;
case PDF_CALLBACK_FINISH:
res = callbacks[conv].finish_cb;
break;
case PDF_CALLBACK_PROGRESS:
res = callbacks[conv].progress_cb;
break;
case PDF_CALLBACK_PHASE:
res = callbacks[conv].phase_cb;
break;
}
}
return res;
}
void del_callback(callback_type_t cb_type, wkhtmltopdf_converter *conv)
{
switch(cb_type)
{
case PDF_CALLBACK_WARNING:
callbacks[conv].warning_cb = NULL;
break;
case PDF_CALLBACK_ERROR:
callbacks[conv].error_cb = NULL;
break;
case PDF_CALLBACK_FINISH:
callbacks[conv].finish_cb = NULL;
break;
case PDF_CALLBACK_PROGRESS:
callbacks[conv].progress_cb = NULL;
break;
case PDF_CALLBACK_PHASE:
callbacks[conv].phase_cb = NULL;
break;
}
}
void clean_all(wkhtmltopdf_converter *conv)
{
callbacks.erase(conv);
}
#ifdef __cplusplus
}
#endif