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