1 /*
2  * Copyright (C) 2022 Intel Corporation.
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef _COMMAND_H_
6 #define _COMMAND_H_
7 #include <pthread.h>
8 #include <sys/queue.h>
9 
10 
11 #define DESTROY "destroy"
12 #define BLKRESCAN "blkrescan"
13 #define REGISTER_VM_EVENT_CLIENT "register_vm_event_client"
14 
15 #define CMDS_NUM 3U
16 #define CMD_NAME_MAX 32U
17 #define CMD_ARG_MAX 320U
18 
19 typedef int (cmd_handler)(void *arg, void *command_para);
20 struct handler_args {
21 	void *channel_arg;
22 	void *ctx_arg;
23 };
24 struct command_handler {
25 	struct handler_args *arg;
26 	cmd_handler *fn;
27 };
28 struct command_parameters {
29 	int fd;
30 	char option[CMD_ARG_MAX];
31 };
32 struct command {
33 	const char name[CMD_NAME_MAX]; /**< command name */
34 	struct command_parameters para;
35 
36 	/* command handler */
37 	struct command_handler cmd_handler;
38 };
39 /**
40  * @brief register command handler, other module can use this interface to
41  * register multiple handler for one command.
42  *
43  * @param fn the command handler which will be registered
44  * @param arg the parameter which will be passed into hanlder
45  * @param cmd_name the command name
46  */
47 int register_command_handler(cmd_handler *fn, struct handler_args *arg, const char *cmd_name);
48 /**
49  * @brief find a command instance by name
50  *
51  * @param name the command name
52  * @return command instance
53  */
54 struct command *find_command(const char *name);
55 /**
56  * @brief dispatch the command and invoke registered handler.
57  *
58  * @param arg command instance
59  * @return the flag indicates the state of command handler execution
60  */
61 int dispatch_command_handlers(void *arg);
62 #endif
63