#include <cmdline_rdline.h>
#include <cmdline_parse.h>
#include <cmdline_parse_ipaddr.h>
#include <cmdline_parse_num.h>
#include <cmdline_parse_string.h>
struct cmd_help_result {
cmdline_fixed_string_t help;
};
static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
struct cmdline *cl,
__attribute__((unused)) void *data)
{
cmdline_printf(cl,
"commands:\n"
"- attach <devargs>\n"
"- detach <devargs>\n"
"- list\n\n");
}
cmdline_parse_token_string_t cmd_help_help =
TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
cmdline_parse_inst_t cmd_help = {
.f = cmd_help_parsed,
.data = NULL,
.help_str = "show help",
.tokens = {
(void *)&cmd_help_help,
NULL,
},
};
struct cmd_quit_result {
cmdline_fixed_string_t quit;
};
static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
struct cmdline *cl,
__attribute__((unused)) void *data)
{
cmdline_quit(cl);
}
cmdline_parse_token_string_t cmd_quit_quit =
TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
cmdline_parse_inst_t cmd_quit = {
.f = cmd_quit_parsed,
.data = NULL,
.help_str = "quit",
.tokens = {
(void *)&cmd_quit_quit,
NULL,
},
};
struct cmd_list_result {
cmdline_fixed_string_t list;
};
static void cmd_list_parsed(__attribute__((unused)) void *parsed_result,
struct cmdline *cl,
__attribute__((unused)) void *data)
{
uint16_t port_id;
char dev_name[RTE_DEV_NAME_MAX_LEN];
cmdline_printf(cl, "list all etherdev\n");
if (strlen(dev_name) > 0)
cmdline_printf(cl, "%d\t%s\n", port_id, dev_name);
else
printf("empty dev_name is not expected!\n");
}
}
cmdline_parse_token_string_t cmd_list_list =
TOKEN_STRING_INITIALIZER(struct cmd_list_result, list, "list");
cmdline_parse_inst_t cmd_list = {
.f = cmd_list_parsed,
.data = NULL,
.help_str = "list all devices",
.tokens = {
(void *)&cmd_list_list,
NULL,
},
};
struct cmd_dev_attach_result {
cmdline_fixed_string_t attach;
cmdline_fixed_string_t devargs;
};
static void cmd_dev_attach_parsed(void *parsed_result,
struct cmdline *cl,
__attribute__((unused)) void *data)
{
struct cmd_dev_attach_result *res = parsed_result;
memset(&da, 0, sizeof(da));
cmdline_printf(cl, "cannot parse devargs\n");
if (da.args)
free(da.args);
return;
}
cmdline_printf(cl, "attached device %s\n", da.name);
else
cmdline_printf(cl, "failed to attached device %s\n",
da.name);
}
cmdline_parse_token_string_t cmd_dev_attach_attach =
TOKEN_STRING_INITIALIZER(struct cmd_dev_attach_result, attach,
"attach");
cmdline_parse_token_string_t cmd_dev_attach_devargs =
TOKEN_STRING_INITIALIZER(struct cmd_dev_attach_result, devargs, NULL);
cmdline_parse_inst_t cmd_attach_device = {
.f = cmd_dev_attach_parsed,
.data = NULL,
.help_str = "attach a device",
.tokens = {
(void *)&cmd_dev_attach_attach,
(void *)&cmd_dev_attach_devargs,
NULL,
},
};
struct cmd_dev_detach_result {
cmdline_fixed_string_t detach;
cmdline_fixed_string_t devargs;
};
static void cmd_dev_detach_parsed(void *parsed_result,
struct cmdline *cl,
__attribute__((unused)) void *data)
{
struct cmd_dev_detach_result *res = parsed_result;
memset(&da, 0, sizeof(da));
cmdline_printf(cl, "cannot parse devargs\n");
if (da.args)
free(da.args);
return;
}
printf("detaching...\n");
cmdline_printf(cl, "detached device %s\n",
da.name);
else
cmdline_printf(cl, "failed to dettach device %s\n",
da.name);
}
cmdline_parse_token_string_t cmd_dev_detach_detach =
TOKEN_STRING_INITIALIZER(struct cmd_dev_detach_result, detach,
"detach");
cmdline_parse_token_string_t cmd_dev_detach_devargs =
TOKEN_STRING_INITIALIZER(struct cmd_dev_detach_result, devargs, NULL);
cmdline_parse_inst_t cmd_detach_device = {
.f = cmd_dev_detach_parsed,
.data = NULL,
.help_str = "detach a device",
.tokens = {
(void *)&cmd_dev_detach_detach,
(void *)&cmd_dev_detach_devargs,
NULL,
},
};
cmdline_parse_ctx_t main_ctx[] = {
(cmdline_parse_inst_t *)&cmd_help,
(cmdline_parse_inst_t *)&cmd_quit,
(cmdline_parse_inst_t *)&cmd_list,
(cmdline_parse_inst_t *)&cmd_attach_device,
(cmdline_parse_inst_t *)&cmd_detach_device,
NULL,
};