4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <rte_common.h>
38 #include <rte_malloc.h>
40 #include <cmdline_parse.h>
41 #include <cmdline_parse_string.h>
42 #include <cmdline_socket.h>
46 #include "pipeline_master_be.h"
48 struct pipeline_master {
49 struct app_params *app;
53 } __rte_cache_aligned;
56 pipeline_init(__rte_unused struct pipeline_params *params, void *arg)
58 struct app_params *app = (struct app_params *) arg;
59 struct pipeline_master *p;
62 /* Check input arguments */
66 /* Memory allocation */
67 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_master));
68 p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
75 p->cl = cmdline_stdin_new(app->cmds, "pipeline> ");
81 p->post_init_done = 0;
82 p->script_file_done = 0;
83 if (app->script_file == NULL)
84 p->script_file_done = 1;
90 pipeline_free(void *pipeline)
92 struct pipeline_master *p = (struct pipeline_master *) pipeline;
97 cmdline_stdin_exit(p->cl);
104 pipeline_run(void *pipeline)
106 struct pipeline_master *p = (struct pipeline_master *) pipeline;
107 struct app_params *app = p->app;
110 /* Application post-init phase */
111 if (p->post_init_done == 0) {
114 p->post_init_done = 1;
117 /* Run startup script file */
118 if (p->script_file_done == 0) {
119 struct app_params *app = p->app;
120 int fd = open(app->script_file, O_RDONLY);
123 printf("Cannot open CLI script file \"%s\"\n",
126 struct cmdline *file_cl;
128 printf("Running CLI script file \"%s\" ...\n",
130 file_cl = cmdline_new(p->cl->ctx, "", fd, 1);
131 cmdline_interact(file_cl);
135 p->script_file_done = 1;
138 /* Command Line Interface (CLI) */
139 status = cmdline_poll(p->cl);
141 rte_panic("CLI poll error (%" PRId32 ")\n", status);
142 else if (status == RDLINE_EXITED) {
143 cmdline_stdin_exit(p->cl);
144 rte_exit(0, "Bye!\n");
151 pipeline_timer(__rte_unused void *pipeline)
156 struct pipeline_be_ops pipeline_master_be_ops = {
157 .f_init = pipeline_init,
158 .f_free = pipeline_free,
159 .f_run = pipeline_run,
160 .f_timer = pipeline_timer,