aboutsummaryrefslogtreecommitdiff
path: root/tools/perf/ui/util.c
blob: 689b27c34246c5086419a059d61fbf4a2c4b048f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: GPL-2.0
#include "util.h"
#include "../util/debug.h"
#include <stdio.h>

/*
 * Default error logging functions
 */
static int perf_stdio__error(const char *format, va_list args)
{
	fprintf(stderr, "Error:\n");
	vfprintf(stderr, format, args);
	return 0;
}

static int perf_stdio__warning(const char *format, va_list args)
{
	fprintf(stderr, "Warning:\n");
	vfprintf(stderr, format, args);
	return 0;
}

static struct perf_error_ops default_eops =
{
	.error		= perf_stdio__error,
	.warning	= perf_stdio__warning,
};

static struct perf_error_ops *perf_eops = &default_eops;


int ui__error(const char *format, ...)
{
	int ret;
	va_list args;

	va_start(args, format);
	ret = perf_eops->error(format, args);
	va_end(args);

	return ret;
}

int ui__warning(const char *format, ...)
{
	int ret;
	va_list args;

	va_start(args, format);
	ret = perf_eops->warning(format, args);
	va_end(args);

	return ret;
}

/**
 * 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)
{
	if (perf_eops != &default_eops)
		return -1;

	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;
}