xref: /openbmc/qemu/include/qapi/qmp/dispatch.h (revision 50243407)
1 /*
2  * Core Definitions for QAPI/QMP Dispatch
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10  * See the COPYING.LIB file in the top-level directory.
11  *
12  */
13 
14 #ifndef QAPI_QMP_DISPATCH_H
15 #define QAPI_QMP_DISPATCH_H
16 
17 #include "monitor/monitor.h"
18 #include "qemu/queue.h"
19 
20 typedef void (QmpCommandFunc)(QDict *, QObject **, Error **);
21 
22 typedef enum QmpCommandOptions
23 {
24     QCO_NO_OPTIONS            =  0x0,
25     QCO_NO_SUCCESS_RESP       =  (1U << 0),
26     QCO_ALLOW_OOB             =  (1U << 1),
27     QCO_ALLOW_PRECONFIG       =  (1U << 2),
28     QCO_COROUTINE             =  (1U << 3),
29 } QmpCommandOptions;
30 
31 typedef struct QmpCommand
32 {
33     const char *name;
34     /* Runs in coroutine context if QCO_COROUTINE is set */
35     QmpCommandFunc *fn;
36     QmpCommandOptions options;
37     QTAILQ_ENTRY(QmpCommand) node;
38     bool enabled;
39     const char *disable_reason;
40 } QmpCommand;
41 
42 typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList;
43 
44 void qmp_register_command(QmpCommandList *cmds, const char *name,
45                           QmpCommandFunc *fn, QmpCommandOptions options);
46 const QmpCommand *qmp_find_command(const QmpCommandList *cmds,
47                                    const char *name);
48 void qmp_disable_command(QmpCommandList *cmds, const char *name,
49                          const char *err_msg);
50 void qmp_enable_command(QmpCommandList *cmds, const char *name);
51 
52 bool qmp_command_is_enabled(const QmpCommand *cmd);
53 bool qmp_command_available(const QmpCommand *cmd, Error **errp);
54 const char *qmp_command_name(const QmpCommand *cmd);
55 bool qmp_has_success_response(const QmpCommand *cmd);
56 QDict *qmp_error_response(Error *err);
57 QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
58                     bool allow_oob, Monitor *cur_mon);
59 bool qmp_is_oob(const QDict *dict);
60 
61 typedef void (*qmp_cmd_callback_fn)(const QmpCommand *cmd, void *opaque);
62 
63 void qmp_for_each_command(const QmpCommandList *cmds, qmp_cmd_callback_fn fn,
64                           void *opaque);
65 
66 #endif
67