Commit | Line | Data |
---|---|---|
1e6dd077 | 1 | #include "util.h" |
ba47a142 | 2 | #include "../debug.h" |
1056d3dd | 3 | |
1056d3dd | 4 | |
ba47a142 NK |
5 | /* |
6 | * Default error logging functions | |
7 | */ | |
8 | static int perf_stdio__error(const char *format, va_list args) | |
53c54019 | 9 | { |
ba47a142 NK |
10 | fprintf(stderr, "Error:\n"); |
11 | vfprintf(stderr, format, args); | |
12 | return 0; | |
53c54019 ACM |
13 | } |
14 | ||
ba47a142 | 15 | static int perf_stdio__warning(const char *format, va_list args) |
aa49f6ec | 16 | { |
ba47a142 NK |
17 | fprintf(stderr, "Warning:\n"); |
18 | vfprintf(stderr, format, args); | |
19 | return 0; | |
aa49f6ec NK |
20 | } |
21 | ||
ba47a142 | 22 | static struct perf_error_ops default_eops = |
a9a4ab74 | 23 | { |
ba47a142 NK |
24 | .error = perf_stdio__error, |
25 | .warning = perf_stdio__warning, | |
26 | }; | |
a9a4ab74 | 27 | |
ba47a142 | 28 | static struct perf_error_ops *perf_eops = &default_eops; |
a3da8e45 | 29 | |
ae55795e | 30 | |
ba47a142 | 31 | int ui__error(const char *format, ...) |
ae55795e | 32 | { |
ba47a142 NK |
33 | int ret; |
34 | va_list args; | |
4610e413 | 35 | |
ba47a142 NK |
36 | va_start(args, format); |
37 | ret = perf_eops->error(format, args); | |
38 | va_end(args); | |
ae55795e | 39 | |
ba47a142 | 40 | return ret; |
53c54019 | 41 | } |
068ffaa8 | 42 | |
4610e413 | 43 | int ui__warning(const char *format, ...) |
068ffaa8 | 44 | { |
ba47a142 | 45 | int ret; |
068ffaa8 ACM |
46 | va_list args; |
47 | ||
48 | va_start(args, format); | |
ba47a142 | 49 | ret = perf_eops->warning(format, args); |
ae55795e | 50 | va_end(args); |
ba47a142 NK |
51 | |
52 | return ret; | |
ae55795e ACM |
53 | } |
54 | ||
ba47a142 NK |
55 | /** |
56 | * perf_error__register - Register error logging functions | |
57 | * @eops: The pointer to error logging function struct | |
58 | * | |
59 | * Register UI-specific error logging functions. Before calling this, | |
60 | * other logging functions should be unregistered, if any. | |
61 | */ | |
62 | int perf_error__register(struct perf_error_ops *eops) | |
ae55795e | 63 | { |
ba47a142 NK |
64 | if (perf_eops != &default_eops) |
65 | return -1; | |
ae55795e | 66 | |
ba47a142 NK |
67 | perf_eops = eops; |
68 | return 0; | |
69 | } | |
70 | ||
71 | /** | |
72 | * perf_error__unregister - Unregister error logging functions | |
73 | * @eops: The pointer to error logging function struct | |
74 | * | |
75 | * Unregister already registered error logging functions. | |
76 | */ | |
77 | int perf_error__unregister(struct perf_error_ops *eops) | |
78 | { | |
79 | if (perf_eops != eops) | |
80 | return -1; | |
81 | ||
82 | perf_eops = &default_eops; | |
83 | return 0; | |
068ffaa8 | 84 | } |