Xenomai
3.0-rc3
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
smokey.h
1
/*
2
* Copyright (C) 2014 Philippe Gerum <rpm@xenomai.org>.
3
*
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
8
*
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
13
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17
*/
18
#ifndef _XENOMAI_SMOKEY_SMOKEY_H
19
#define _XENOMAI_SMOKEY_SMOKEY_H
20
21
#include <boilerplate/list.h>
22
#include <boilerplate/libc.h>
23
#include <copperplate/clockobj.h>
24
25
#define SMOKEY_INT(__name) { \
26
.name = # __name, \
27
.parser = smokey_int, \
28
.matched = 0, \
29
}
30
31
#define SMOKEY_BOOL(__name) { \
32
.name = # __name, \
33
.parser = smokey_bool, \
34
.matched = 0, \
35
}
36
37
#define SMOKEY_STRING(__name) { \
38
.name = # __name, \
39
.parser = smokey_string, \
40
.matched = 0, \
41
}
42
43
#define SMOKEY_ARGLIST(__args...) ((struct smokey_arg[]){ __args })
44
45
#define SMOKEY_NOARGS (((struct smokey_arg[]){ { .name = NULL } }))
46
47
struct
smokey_arg {
48
const
char
*name;
49
int (*parser)(
const
char
*s,
50
struct
smokey_arg *arg);
51
union
{
52
int
n_val;
53
char
*s_val;
54
} u;
55
int
matched;
56
};
57
58
struct
smokey_test {
59
const
char
*name;
60
struct
smokey_arg *args;
61
int
nargs;
62
const
char
*description;
63
int (*run)(
struct
smokey_test *t,
64
int
argc,
char
*
const
argv[]);
65
struct
{
66
int
id;
67
struct
pvholder next;
68
} __reserved;
69
};
70
71
#define for_each_smokey_test(__pos) \
72
pvlist_for_each_entry((__pos), &smokey_test_list, __reserved.next)
73
74
#define __SMOKEYPLUG_CTOR_PRIO 310
75
76
#define __smokey_arg_count(__args) \
77
(sizeof(__args) / sizeof(__args[0]))
78
79
#define smokey_test_plugin(__plugin, __args, __desc) \
80
static int run_ ## __plugin(struct smokey_test *t, \
81
int argc, char *const argv[]); \
82
static struct smokey_test __plugin = { \
83
.name = #__plugin, \
84
.args = (__args), \
85
.nargs = __smokey_arg_count(__args), \
86
.description = (__desc), \
87
.run = run_ ## __plugin, \
88
}; \
89
void smokey_plugin_ ## __plugin(void); \
90
__attribute__((constructor(__SMOKEYPLUG_CTOR_PRIO))) \
91
void smokey_plugin_ ## __plugin(void) \
92
{ \
93
smokey_register_plugin(&(__plugin)); \
94
}
95
96
#define SMOKEY_ARG(__plugin, __arg) (smokey_lookup_arg(&(__plugin), # __arg))
97
#define SMOKEY_ARG_ISSET(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->matched)
98
#define SMOKEY_ARG_INT(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.n_val)
99
#define SMOKEY_ARG_STRING(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.s_val)
100
101
#ifdef __cplusplus
102
extern
"C"
{
103
#endif
104
105
void
smokey_register_plugin(
struct
smokey_test *t);
106
107
int
smokey_int(
const
char
*s,
struct
smokey_arg *arg);
108
109
int
smokey_bool(
const
char
*s,
struct
smokey_arg *arg);
110
111
int
smokey_string(
const
char
*s,
struct
smokey_arg *arg);
112
113
struct
smokey_arg *smokey_lookup_arg(
struct
smokey_test *t,
114
const
char
*arg);
115
116
int
smokey_parse_args(
struct
smokey_test *t,
117
int
argc,
char
*
const
argv[]);
118
119
void
smokey_note(
const
char
*fmt, ...);
120
121
#ifdef __cplusplus
122
}
123
#endif
124
125
extern
struct
pvlist smokey_test_list;
126
127
extern
int
smokey_keep_going;
128
129
extern
int
smokey_quiet_mode;
130
131
#endif
/* _XENOMAI_SMOKEY_SMOKEY_H */
include
smokey
smokey.h
Generated by
1.8.8