2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <rte_common.h>
21 #include <rte_malloc.h>
23 #include <cmdline_parse.h>
24 #include <cmdline_parse_string.h>
25 #include <cmdline_socket.h>
29 #include "pipeline_master_be.h"
31 struct pipeline_master {
32 struct app_params *app;
35 } __rte_cache_aligned;
38 pipeline_init(__rte_unused struct pipeline_params *params, void *arg)
40 struct app_params *app = (struct app_params *) arg;
41 struct pipeline_master *p;
44 /* Check input arguments */
48 /* Memory allocation */
49 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_master));
50 p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
57 p->cl = cmdline_stdin_new(app->cmds, "pipeline> ");
63 p->script_file_done = 0;
64 if (app->script_file == NULL)
65 p->script_file_done = 1;
71 pipeline_free(void *pipeline)
73 struct pipeline_master *p = (struct pipeline_master *) pipeline;
78 cmdline_stdin_exit(p->cl);
85 pipeline_run(void *pipeline)
87 struct pipeline_master *p = (struct pipeline_master *) pipeline;
90 if (p->script_file_done == 0) {
91 struct app_params *app = p->app;
92 int fd = open(app->script_file, O_RDONLY);
95 printf("Cannot open CLI script file \"%s\"\n",
98 struct cmdline *file_cl;
100 printf("Running CLI script file \"%s\" ...\n",
102 file_cl = cmdline_new(p->cl->ctx, "", fd, 1);
103 cmdline_interact(file_cl);
107 p->script_file_done = 1;
110 status = cmdline_poll(p->cl);
112 rte_panic("CLI poll error (%" PRId32 ")\n", status);
113 else if (status == RDLINE_EXITED) {
114 cmdline_stdin_exit(p->cl);
115 rte_exit(0, "Bye!\n");
122 pipeline_timer(__rte_unused void *pipeline)
128 struct pipeline_be_ops pipeline_master_be_ops = {
129 .f_init = pipeline_init,
130 .f_free = pipeline_free,
131 .f_run = pipeline_run,
132 .f_timer = pipeline_timer,