eal: move common header files
[dpdk.git] / lib / librte_eal / include / rte_option.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation.
3  */
4
5 #ifndef __INCLUDE_RTE_OPTION_H__
6 #define __INCLUDE_RTE_OPTION_H__
7
8 /**
9  * @file
10  *
11  * This API offers the ability to register options to the EAL command line and
12  * map those options to functions that will be executed at the end of EAL
13  * initialization. These options will be available as part of the EAL command
14  * line of applications and are dynamically managed.
15  *
16  * This is used primarily by DPDK libraries offering command line options.
17  * Currently, this API is limited to registering options without argument.
18  *
19  * The register API can be used to resolve circular dependency issues
20  * between EAL and the library. The library uses EAL, but is also initialized
21  * by EAL. Hence, EAL depends on the init function of the library. The API
22  * introduced in rte_option allows us to register the library init with EAL
23  * (passing a function pointer) and avoid the circular dependency.
24  */
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 typedef int (*rte_option_cb)(void);
31
32 /**
33  * Structure describing an EAL command line option dynamically registered.
34  *
35  * Common EAL options are mostly statically defined.
36  * Some libraries need additional options to be dynamically added.
37  * This structure describes such options.
38  */
39 struct rte_option {
40         TAILQ_ENTRY(rte_option) next; /**< Next entry in the list. */
41         const char *name; /**< The option name. */
42         const char *usage; /**< Option summary string. */
43         rte_option_cb cb;          /**< Function called when option is used. */
44         int enabled;               /**< Set when the option is used. */
45 };
46
47 /**
48  * @warning
49  * @b EXPERIMENTAL: this API may change without prior notice
50  *
51  * Register an option to the EAL command line.
52  * When recognized, the associated function will be executed at the end of EAL
53  * initialization.
54  *
55  * The associated structure must be available the whole time this option is
56  * registered (i.e. not stack memory).
57  *
58  * @param opt
59  *  Structure describing the option to parse.
60  *
61  * @return
62  *  0 on success, <0 otherwise.
63  */
64 __rte_experimental
65 int
66 rte_option_register(struct rte_option *opt);
67
68 #ifdef __cplusplus
69 }
70 #endif
71
72 #endif