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