2010-08-10 18:58:50 +00:00
|
|
|
#include "util.h"
|
2012-05-29 04:22:58 +00:00
|
|
|
#include "../debug.h"
|
2011-10-26 09:11:03 +00:00
|
|
|
|
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
/*
|
|
|
|
* Default error logging functions
|
|
|
|
*/
|
|
|
|
static int perf_stdio__error(const char *format, va_list args)
|
2010-03-24 19:40:14 +00:00
|
|
|
{
|
2012-05-29 04:22:58 +00:00
|
|
|
fprintf(stderr, "Error:\n");
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
return 0;
|
2010-03-24 19:40:14 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
static int perf_stdio__warning(const char *format, va_list args)
|
2012-03-16 08:50:52 +00:00
|
|
|
{
|
2012-05-29 04:22:58 +00:00
|
|
|
fprintf(stderr, "Warning:\n");
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
return 0;
|
2012-03-16 08:50:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
static struct perf_error_ops default_eops =
|
2010-05-17 00:04:27 +00:00
|
|
|
{
|
2012-05-29 04:22:58 +00:00
|
|
|
.error = perf_stdio__error,
|
|
|
|
.warning = perf_stdio__warning,
|
|
|
|
};
|
2010-05-17 00:04:27 +00:00
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
static struct perf_error_ops *perf_eops = &default_eops;
|
2010-11-06 08:47:24 +00:00
|
|
|
|
2011-10-26 10:00:55 +00:00
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
int ui__error(const char *format, ...)
|
2011-10-26 10:00:55 +00:00
|
|
|
{
|
2012-05-29 04:22:58 +00:00
|
|
|
int ret;
|
|
|
|
va_list args;
|
2011-10-26 14:04:37 +00:00
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
va_start(args, format);
|
|
|
|
ret = perf_eops->error(format, args);
|
|
|
|
va_end(args);
|
2011-10-26 10:00:55 +00:00
|
|
|
|
2012-05-29 04:22:58 +00:00
|
|
|
return ret;
|
2010-03-24 19:40:14 +00:00
|
|
|
}
|
2010-11-27 04:41:01 +00:00
|
|
|
|
2011-10-26 14:04:37 +00:00
|
|
|
int ui__warning(const char *format, ...)
|
2010-11-27 04:41:01 +00:00
|
|
|
{
|
2012-05-29 04:22:58 +00:00
|
|
|
int ret;
|
2010-11-27 04:41:01 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2012-05-29 04:22:58 +00:00
|
|
|
ret = perf_eops->warning(format, args);
|
2011-10-26 10:00:55 +00:00
|
|
|
va_end(args);
|
2012-05-29 04:22:58 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-10-26 10:00:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 04:22:58 +00: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 10:00:55 +00:00
|
|
|
{
|
2012-05-29 04:22:58 +00:00
|
|
|
if (perf_eops != &default_eops)
|
|
|
|
return -1;
|
2011-10-26 10:00:55 +00:00
|
|
|
|
2012-05-29 04:22:58 +00: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 04:41:01 +00:00
|
|
|
}
|