2010-08-11 02:58:50 +08:00
|
|
|
#include "util.h"
|
2012-05-29 12:22:58 +08:00
|
|
|
#include "../debug.h"
|
2011-10-26 17:11:03 +08:00
|
|
|
|
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
/*
|
|
|
|
* Default error logging functions
|
|
|
|
*/
|
|
|
|
static int perf_stdio__error(const char *format, va_list args)
|
2010-03-25 03:40:14 +08:00
|
|
|
{
|
2012-05-29 12:22:58 +08:00
|
|
|
fprintf(stderr, "Error:\n");
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
return 0;
|
2010-03-25 03:40:14 +08:00
|
|
|
}
|
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
static int perf_stdio__warning(const char *format, va_list args)
|
2012-03-16 16:50:52 +08:00
|
|
|
{
|
2012-05-29 12:22:58 +08:00
|
|
|
fprintf(stderr, "Warning:\n");
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
return 0;
|
2012-03-16 16:50:52 +08:00
|
|
|
}
|
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
static struct perf_error_ops default_eops =
|
2010-05-17 08:04:27 +08:00
|
|
|
{
|
2012-05-29 12:22:58 +08:00
|
|
|
.error = perf_stdio__error,
|
|
|
|
.warning = perf_stdio__warning,
|
|
|
|
};
|
2010-05-17 08:04:27 +08:00
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
static struct perf_error_ops *perf_eops = &default_eops;
|
2010-11-06 16:47:24 +08:00
|
|
|
|
2011-10-26 18:00:55 +08:00
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
int ui__error(const char *format, ...)
|
2011-10-26 18:00:55 +08:00
|
|
|
{
|
2012-05-29 12:22:58 +08:00
|
|
|
int ret;
|
|
|
|
va_list args;
|
2011-10-26 22:04:37 +08:00
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
va_start(args, format);
|
|
|
|
ret = perf_eops->error(format, args);
|
|
|
|
va_end(args);
|
2011-10-26 18:00:55 +08:00
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
return ret;
|
2010-03-25 03:40:14 +08:00
|
|
|
}
|
2010-11-27 12:41:01 +08:00
|
|
|
|
2011-10-26 22:04:37 +08:00
|
|
|
int ui__warning(const char *format, ...)
|
2010-11-27 12:41:01 +08:00
|
|
|
{
|
2012-05-29 12:22:58 +08:00
|
|
|
int ret;
|
2010-11-27 12:41:01 +08:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2012-05-29 12:22:58 +08:00
|
|
|
ret = perf_eops->warning(format, args);
|
2011-10-26 18:00:55 +08:00
|
|
|
va_end(args);
|
2012-05-29 12:22:58 +08:00
|
|
|
|
|
|
|
return ret;
|
2011-10-26 18:00:55 +08:00
|
|
|
}
|
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
/**
|
|
|
|
* perf_error__register - Register error logging functions
|
|
|
|
* @eops: The pointer to error logging function struct
|
|
|
|
*
|
|
|
|
* Register UI-specific error logging functions. Before calling this,
|
|
|
|
* other logging functions should be unregistered, if any.
|
|
|
|
*/
|
|
|
|
int perf_error__register(struct perf_error_ops *eops)
|
2011-10-26 18:00:55 +08:00
|
|
|
{
|
2012-05-29 12:22:58 +08:00
|
|
|
if (perf_eops != &default_eops)
|
|
|
|
return -1;
|
2011-10-26 18:00:55 +08:00
|
|
|
|
2012-05-29 12:22:58 +08:00
|
|
|
perf_eops = eops;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* perf_error__unregister - Unregister error logging functions
|
|
|
|
* @eops: The pointer to error logging function struct
|
|
|
|
*
|
|
|
|
* Unregister already registered error logging functions.
|
|
|
|
*/
|
|
|
|
int perf_error__unregister(struct perf_error_ops *eops)
|
|
|
|
{
|
|
|
|
if (perf_eops != eops)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
perf_eops = &default_eops;
|
|
|
|
return 0;
|
2010-11-27 12:41:01 +08:00
|
|
|
}
|