xref: /dpdk/examples/cmdline/parse_obj_list.h (revision 25d11a86c56d50947af33d0b79ede622809bd8b9)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
4  * All rights reserved.
5  */
6 
7 #ifndef _PARSE_OBJ_LIST_H_
8 #define _PARSE_OBJ_LIST_H_
9 
10 /* This file is an example of extension of libcmdline. It provides an
11  * example of objects stored in a list. */
12 
13 #include <sys/queue.h>
14 #include <cmdline_parse.h>
15 
16 #define OBJ_NAME_LEN_MAX 64
17 
18 struct object {
19 	SLIST_ENTRY(object) next;
20 	char name[OBJ_NAME_LEN_MAX];
21 	cmdline_ipaddr_t ip;
22 };
23 
24 /* define struct object_list */
25 SLIST_HEAD(object_list, object);
26 
27 /* data is a pointer to a list */
28 struct token_obj_list_data {
29 	struct object_list *list;
30 };
31 
32 struct token_obj_list {
33 	struct cmdline_token_hdr hdr;
34 	struct token_obj_list_data obj_list_data;
35 };
36 typedef struct token_obj_list parse_token_obj_list_t;
37 
38 extern struct cmdline_token_ops token_obj_list_ops;
39 
40 int parse_obj_list(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res,
41 	unsigned ressize);
42 int complete_get_nb_obj_list(cmdline_parse_token_hdr_t *tk);
43 int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk, int idx,
44 			      char *dstbuf, unsigned int size);
45 int get_help_obj_list(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size);
46 
47 #define TOKEN_OBJ_LIST_INITIALIZER(structure, field, obj_list_ptr)  \
48 {								    \
49 	.hdr = {						    \
50 		.ops = &token_obj_list_ops,			    \
51 		.offset = offsetof(structure, field),		    \
52 	},							    \
53 		.obj_list_data = {				    \
54 		.list = obj_list_ptr,				    \
55 	},							    \
56 }
57 
58 #endif /* _PARSE_OBJ_LIST_H_ */
59