summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kdbus/kdbus-enum.c
blob: 4f1e5797895fc7dce98177b77db670d3e919768f (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
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2013-2015 Kay Sievers
 *
 * kdbus is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 */

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>

#include "kdbus-util.h"
#include "kdbus-enum.h"

struct kdbus_enum_table {
	long long id;
	const char *name;
};

#define TABLE(what) static struct kdbus_enum_table kdbus_table_##what[]
#define ENUM(_id) { .id = _id, .name = STRINGIFY(_id) }
#define LOOKUP(what)							\
	const char *enum_##what(long long id)				\
	{								\
		for (size_t i = 0; i < ELEMENTSOF(kdbus_table_##what); i++) \
			if (id == kdbus_table_##what[i].id)		\
				return kdbus_table_##what[i].name;	\
		return "UNKNOWN";					\
	}

TABLE(CMD) = {
	ENUM(KDBUS_CMD_BUS_MAKE),
	ENUM(KDBUS_CMD_ENDPOINT_MAKE),
	ENUM(KDBUS_CMD_HELLO),
	ENUM(KDBUS_CMD_SEND),
	ENUM(KDBUS_CMD_RECV),
	ENUM(KDBUS_CMD_LIST),
	ENUM(KDBUS_CMD_NAME_RELEASE),
	ENUM(KDBUS_CMD_CONN_INFO),
	ENUM(KDBUS_CMD_MATCH_ADD),
	ENUM(KDBUS_CMD_MATCH_REMOVE),
};
LOOKUP(CMD);

TABLE(MSG) = {
	ENUM(_KDBUS_ITEM_NULL),
	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