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 cmdline *pipe_cl;
33 struct pipeline_master {
34 struct app_params *app;
37 } __rte_cache_aligned;
40 pipeline_init(__rte_unused struct pipeline_params *params, void *arg)
42 struct app_params *app = (struct app_params *) arg;
43 struct pipeline_master *p;
46 /* Check input arguments */
50 /* Memory allocation */
51 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_master));
52 p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
59 p->cl = cmdline_stdin_new(app->cmds, "pipeline> ");
66 p->script_file_done = 0;
67 if (app->script_file == NULL)
68 p->script_file_done = 1;
74 pipeline_free(void *pipeline)
76 struct pipeline_master *p = (struct pipeline_master *) pipeline;
81 cmdline_stdin_exit(p->cl);
88 pipeline_run(void *pipeline)
90 struct pipeline_master *p = (struct pipeline_master *) pipeline;
94 if (p->script_file_done == 0) {
95 struct app_params *app = p->app;
96 int fd = open(app->script_file, O_RDONLY);
99 printf("Cannot open CLI script file \"%s\"\n",
102 struct cmdline *file_cl;
104 printf("Running CLI script file \"%s\" ...\n",
106 file_cl = cmdline_new(p->cl->ctx, "", fd, 1);
107 cmdline_interact(file_cl);
111 p->script_file_done = 1;
114 status = cmdline_poll(p->cl);
116 rte_panic("CLI poll error (%" PRId32 ")\n", status);
117 else if (status == RDLINE_EXITED) {
118 cmdline_stdin_exit(p->cl);
119 rte_exit(0, "Bye!\n");
126 pipeline_timer(__rte_unused void *pipeline)
132 struct pipeline_be_ops pipeline_master_be_ops = {
133 .f_init = pipeline_init,
134 .f_free = pipeline_free,
135 .f_run = pipeline_run,
136 .f_timer = pipeline_timer,