bzr branch
http://darksoft.org/webbzr/alps/pcitool
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
1 |
#define _BSD_SOURCE
|
303
by Suren A. Chilingaryan
Initial integration of XML support |
2 |
#define _DEFAULT_SOURCE
|
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
3 |
|
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
4 |
#include <stdio.h> |
247
by Suren A. Chilingaryan
New error reporting public interface |
5 |
#include <stdlib.h> |
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
6 |
#include <stdarg.h> |
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
7 |
#include <string.h> |
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
8 |
|
241
by Suren A. Chilingaryan
Further adjustments to get ready for independent event plugins |
9 |
#include "export.h" |
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
10 |
#include "error.h" |
11 |
||
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
12 |
#define PCILIB_LOGGER_HISTORY 16
|
13 |
||
247
by Suren A. Chilingaryan
New error reporting public interface |
14 |
void pcilib_print_error(void *arg, const char *file, int line, pcilib_log_priority_t prio, const char *msg, va_list va) { |
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
15 |
size_t size = strlen(msg) + strlen(file) + 64; |
16 |
char *stmp = alloca(size * sizeof(char*)); |
|
17 |
||
18 |
if (stmp) { |
|
19 |
sprintf(stmp, "%s [%s:%d]\n", msg, file, line); |
|
20 |
vprintf(stmp, va); |
|
21 |
} else { |
|
22 |
// Bad for multithreading...
|
|
23 |
vprintf(msg, va); |
|
24 |
printf(" [%s:%d]\n", file, line); |
|
25 |
}
|
|
247
by Suren A. Chilingaryan
New error reporting public interface |
26 |
}
|
27 |
||
28 |
static void *pcilib_logger_argument = NULL; |
|
29 |
static pcilib_log_priority_t pcilib_logger_min_prio = PCILIB_LOG_WARNING; |
|
30 |
static pcilib_logger_t pcilib_logger = pcilib_print_error; |
|
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
31 |
static char *pcilib_logger_history[PCILIB_LOGGER_HISTORY] = {0}; |
32 |
static int pcilib_logger_history_pointer = 0; |
|
33 |
||
34 |
static int pcilib_log_check_history(pcilib_log_flags_t flags, const char *msg) { |
|
35 |
int i; |
|
36 |
||
37 |
if ((flags&PCILIB_LOG_ONCE) == 0) |
|
38 |
return 0; |
|
39 |
||
40 |
for (i = 0; ((i < PCILIB_LOGGER_HISTORY)&&(pcilib_logger_history[i])); i++) { |
|
41 |
if (!strcmp(msg, pcilib_logger_history[i])) |
|
42 |
return -1; |
|
43 |
}
|
|
44 |
||
45 |
if (pcilib_logger_history[pcilib_logger_history_pointer]) |
|
46 |
free(pcilib_logger_history[pcilib_logger_history_pointer]); |
|
47 |
||
48 |
pcilib_logger_history[pcilib_logger_history_pointer] = strdup(msg); |
|
49 |
||
50 |
if (++pcilib_logger_history_pointer == PCILIB_LOGGER_HISTORY) |
|
51 |
pcilib_logger_history_pointer = 0; |
|
52 |
||
53 |
return 0; |
|
54 |
}
|
|
55 |
||
56 |
void pcilib_log_message(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, ...) { |
|
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
57 |
va_list va; |
247
by Suren A. Chilingaryan
New error reporting public interface |
58 |
|
250
by Suren A. Chilingaryan
Provide an interface for logging debug messages |
59 |
if ((!prio)||(prio >= pcilib_logger_min_prio)) { |
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
60 |
if (pcilib_log_check_history(flags, msg)) |
61 |
return; |
|
62 |
||
247
by Suren A. Chilingaryan
New error reporting public interface |
63 |
va_start(va, msg); |
64 |
pcilib_logger(pcilib_logger_argument, file, line, prio, msg, va); |
|
65 |
va_end(va); |
|
66 |
}
|
|
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
67 |
}
|
68 |
||
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
69 |
void pcilib_log_vmessage(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, va_list va) { |
250
by Suren A. Chilingaryan
Provide an interface for logging debug messages |
70 |
if ((!prio)||(prio >= pcilib_logger_min_prio)) { |
263
by Suren A. Chilingaryan
Support pcilib_log_once calls |
71 |
if (pcilib_log_check_history(flags, msg)) |
72 |
return; |
|
73 |
||
250
by Suren A. Chilingaryan
Provide an interface for logging debug messages |
74 |
pcilib_logger(pcilib_logger_argument, file, line, prio, msg, va); |
75 |
}
|
|
76 |
}
|
|
77 |
||
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
78 |
|
247
by Suren A. Chilingaryan
New error reporting public interface |
79 |
int pcilib_set_logger(pcilib_log_priority_t min_prio, pcilib_logger_t logger, void *arg) { |
80 |
pcilib_logger_min_prio = min_prio; |
|
81 |
pcilib_logger_argument = arg; |
|
82 |
||
83 |
if (logger) pcilib_logger = logger; |
|
84 |
else logger = pcilib_print_error; |
|
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
85 |
|
86 |
return 0; |
|
87 |
}
|
|
346.1.7
by Vasilii Chernov
Change error logging method in Python wrap. Move functions, that converts values between PyObject and pcilib_value_t to py.c |
88 |
|
89 |
pcilib_logger_t pcilib_get_logger() { |
|
90 |
return pcilib_logger; |
|
91 |
}
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
92 |
|
346.1.16
by Vasilii Chernov
1. Add cmake BUILD_PYTHON_MODULES option. |
93 |
pcilib_log_priority_t pcilib_get_log_level() { |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
94 |
return pcilib_logger_min_prio; |
346.1.7
by Vasilii Chernov
Change error logging method in Python wrap. Move functions, that converts values between PyObject and pcilib_value_t to py.c |
95 |
}
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
96 |
|
346.1.16
by Vasilii Chernov
1. Add cmake BUILD_PYTHON_MODULES option. |
97 |
void* pcilib_get_logger_context() { |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
98 |
return pcilib_logger_argument; |
346.1.7
by Vasilii Chernov
Change error logging method in Python wrap. Move functions, that converts values between PyObject and pcilib_value_t to py.c |
99 |
}
|