xref: /dpdk/examples/multi_process/simple_mp/mp_commands.c (revision 43f062ac3a926e53993b52a3d4333f2de2c6a706)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2023 Intel Corporation
3  */
4 #include <rte_ring.h>
5 #include <rte_mempool.h>
6 #include <rte_string_fns.h>
7 
8 #include "mp_commands.h"
9 
10 void
cmd_send_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)11 cmd_send_parsed(void *parsed_result,
12 		__rte_unused struct cmdline *cl,
13 		__rte_unused void *data)
14 {
15 	void *msg = NULL;
16 	struct cmd_send_result *res = parsed_result;
17 
18 	if (rte_mempool_get(message_pool, &msg) < 0)
19 		rte_panic("Failed to get message buffer\n");
20 	strlcpy((char *)msg, res->message, STR_TOKEN_SIZE);
21 	if (rte_ring_enqueue(send_ring, msg) < 0) {
22 		printf("Failed to send message - message discarded\n");
23 		rte_mempool_put(message_pool, msg);
24 	}
25 }
26 
27 void
cmd_quit_parsed(__rte_unused void * parsed_result,struct cmdline * cl,__rte_unused void * data)28 cmd_quit_parsed(__rte_unused void *parsed_result,
29 			    struct cmdline *cl,
30 			    __rte_unused void *data)
31 {
32 	quit = 1;
33 	cmdline_quit(cl);
34 }
35 
36 void
cmd_help_parsed(__rte_unused void * parsed_result,struct cmdline * cl,__rte_unused void * data)37 cmd_help_parsed(__rte_unused void *parsed_result,
38 			    struct cmdline *cl,
39 			    __rte_unused void *data)
40 {
41 	cmdline_printf(cl, "Simple demo example of multi-process in RTE\n\n"
42 			"This is a readline-like interface that can be used to\n"
43 			"send commands to the simple app. Commands supported are:\n\n"
44 			"- send [string]\n" "- help\n" "- quit\n\n");
45 }
46