aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/eal_common_class.c
blob: d922266d0fcda90f6c279c9a6527bf85968d99bd (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2018 Gaëtan Rivet
 */

#include <stdio.h>
#include <string.h>
#include <sys/queue.h>

#include <rte_class.h>
#include <rte_debug.h>

static struct rte_class_list rte_class_list =
	TAILQ_HEAD_INITIALIZER(rte_class_list);

__rte_experimental void
rte_class_register(struct rte_class *class)
{
	RTE_VERIFY(class);
	RTE_VERIFY(class->name && strlen(class->name));

	TAILQ_INSERT_TAIL(&rte_class_list, class, next);
	RTE_LOG(DEBUG, EAL, "Registered [%s] device class.\n", class->name);
}

__rte_experimental void
rte_class_unregister(struct rte_class *class)
{
	TAILQ_REMOVE(&rte_class_list, class, next);
	RTE_LOG(DEBUG, EAL, "Unregistered [%s] device class.\n", class->name);
}

__rte_experimental
struct rte_class *
rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp,
	       const void *data)
{
	struct rte_class *cls;

	if (start != NULL)
		cls = TAILQ_NEXT(start, next);
	else
		cls = TAILQ_FIRST(&rte_class_list);
	while (cls != NULL) {
		if (cmp(cls, data) == 0)
			break;
		cls = TAILQ_NEXT(cls, next);
	}
	return cls;
}

static int
cmp_class_name(const struct rte_class *class, const void *_name)
{
	const char *name = _name;

	return strcmp(class->name, name);
}

__rte_experimental
struct rte_class *
rte_class_find_by_name(const char *name)
{
	return rte_class_find(NULL, cmp_class_name, (const void *)name);
}