#include "chardev/char-fe.h"
#include "monitor/monitor.h"
-#include "qapi/qapi-types-misc.h"
+#include "qapi/qapi-types-control.h"
#include "qapi/qmp/dispatch.h"
#include "qapi/qmp/json-parser.h"
#include "qemu/readline.h"
* '.' other form of optional type (for 'i' and 'l')
* 'b' boolean
* user mode accepts "on" or "off"
- * '-' optional parameter (eg. '-f')
+ * '-' optional parameter (eg. '-f'); if followed by a 's', it
+ * specifies an optional string param (e.g. '-fs' allows '-f foo')
*
*/
const char *help;
const char *flags; /* p=preconfig */
void (*cmd)(Monitor *mon, const QDict *qdict);
+ /*
+ * If implementing a command that takes no arguments and simply
+ * prints formatted data, then leave @cmd NULL, and then set
+ * @cmd_info_hrt to the corresponding QMP handler that returns
+ * the formatted text.
+ */
+ HumanReadableText *(*cmd_info_hrt)(Error **errp);
+ bool coroutine;
/*
* @sub_table is a list of 2nd level of commands. If it does not exist,
* cmd should be used. If it exists, sub_table[?].cmd should be
struct Monitor {
CharBackend chr;
int reset_seen;
- int flags;
int suspend_cnt; /* Needs to be accessed atomically */
+ bool is_qmp;
bool skip_flush;
bool use_io_thread;
- gchar *mon_cpu_path;
+ char *mon_cpu_path;
QTAILQ_ENTRY(Monitor) entry;
/*
* Members that are protected by the per-monitor lock
*/
QLIST_HEAD(, mon_fd_t) fds;
- QString *outbuf;
+ GString *outbuf;
guint out_watch;
/* Read under either BQL or mon_lock, written with BQL+mon_lock. */
int mux_out;
struct MonitorHMP {
Monitor common;
+ bool use_readline;
/*
* State used only in the thread "owning" the monitor.
* If @use_io_thread, this is @mon_iothread. (This does not actually happen
typedef struct {
Monitor common;
JSONMessageParser parser;
+ bool pretty;
/*
* When a client connects, we're in capabilities negotiation mode.
* @commands is &qmp_cap_negotiation_commands then. When command
* qmp_capabilities succeeds, we go into command mode, and
* @command becomes &qmp_commands.
*/
- QmpCommandList *commands;
+ const QmpCommandList *commands;
bool capab_offered[QMP_CAPABILITY__MAX]; /* capabilities offered */
bool capab[QMP_CAPABILITY__MAX]; /* offered and accepted */
/*
*/
static inline bool monitor_is_qmp(const Monitor *mon)
{
- return mon->flags & MONITOR_USE_CONTROL;
+ return mon->is_qmp;
}
typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList;
extern IOThread *mon_iothread;
-extern QEMUBH *qmp_dispatcher_bh;
+extern Coroutine *qmp_dispatcher_co;
+extern bool qmp_dispatcher_co_shutdown;
+extern bool qmp_dispatcher_co_busy;
extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands;
extern QemuMutex monitor_lock;
extern MonitorList mon_list;
extern int mon_refcount;
-void monitor_init_qmp(Chardev *chr, int flags);
+extern HMPCommand hmp_cmds[];
-int monitor_puts(Monitor *mon, const char *str);
-void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
+void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
bool use_io_thread);
+void monitor_data_destroy(Monitor *mon);
int monitor_can_read(void *opaque);
void monitor_list_append(Monitor *mon);
void monitor_fdsets_cleanup(void);
void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
void monitor_data_destroy_qmp(MonitorQMP *mon);
-void monitor_qmp_bh_dispatcher(void *data);
+void coroutine_fn monitor_qmp_dispatcher_co(void *data);
+
+int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
+void help_cmd(Monitor *mon, const char *name);
+void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
+int hmp_compare_cmd(const char *name, const char *list);
#endif