blob: e3e0a963d03aa3559924af97a33bb67c3f48b275 [file] [log] [blame]
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -03001#include "util.h"
Namhyung Kimba47a142012-05-29 13:22:58 +09002#include "../debug.h"
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03003
Namhyung Kimba47a142012-05-29 13:22:58 +09004
5/*
6 * Default error logging functions
7 */
8static int perf_stdio__error(const char *format, va_list args)
Arnaldo Carvalho de Melo1056d3d2011-10-26 07:11:03 -02009{
Namhyung Kimba47a142012-05-29 13:22:58 +090010 fprintf(stderr, "Error:\n");
Arnaldo Carvalho de Meloae557952011-10-26 08:00:55 -020011 vfprintf(stderr, format, args);
Namhyung Kimba47a142012-05-29 13:22:58 +090012 return 0;
13}
14
15static int perf_stdio__warning(const char *format, va_list args)
16{
17 fprintf(stderr, "Warning:\n");
18 vfprintf(stderr, format, args);
19 return 0;
20}
21
22static struct perf_error_ops default_eops =
23{
24 .error = perf_stdio__error,
25 .warning = perf_stdio__warning,
26};
27
28static struct perf_error_ops *perf_eops = &default_eops;
29
30
31int ui__error(const char *format, ...)
32{
33 int ret;
34 va_list args;
35
36 va_start(args, format);
37 ret = perf_eops->error(format, args);
38 va_end(args);
39
40 return ret;
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -030041}
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020042
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020043int ui__warning(const char *format, ...)
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020044{
Namhyung Kimba47a142012-05-29 13:22:58 +090045 int ret;
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020046 va_list args;
47
48 va_start(args, format);
Namhyung Kimba47a142012-05-29 13:22:58 +090049 ret = perf_eops->warning(format, args);
Arnaldo Carvalho de Meloae557952011-10-26 08:00:55 -020050 va_end(args);
Namhyung Kimba47a142012-05-29 13:22:58 +090051
52 return ret;
Arnaldo Carvalho de Meloae557952011-10-26 08:00:55 -020053}
54
Namhyung Kimba47a142012-05-29 13:22:58 +090055/**
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 */
62int perf_error__register(struct perf_error_ops *eops)
63{
64 if (perf_eops != &default_eops)
65 return -1;
66
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 */
77int 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;
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020084}