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