Revision | fbfc29e3bf145581e84c12ffc432ab56ce1dea0d (tree) |
---|---|
Zeit | 2019-06-18 15:14:17 |
Autor | Kevin Wolf <kwolf@redh...> |
Commiter | Markus Armbruster |
monitor: Replace monitor_init() with monitor_init_{hmp, qmp}()
Most callers know which monitor type they want to have. Instead of
calling monitor_init() with flags that can describe both types of
monitors, make monitor_init_{hmp,qmp}() public interfaces that take
specific bools instead of flags and call these functions directly.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20190613153405.24769-15-kwolf@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
@@ -731,7 +731,7 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, | ||
731 | 731 | |
732 | 732 | if (qemu_opt_get_bool(opts, "mux", 0)) { |
733 | 733 | assert(permit_mux_mon); |
734 | - monitor_init(chr, MONITOR_USE_READLINE); | |
734 | + monitor_init_hmp(chr, true); | |
735 | 735 | } |
736 | 736 | |
737 | 737 | out: |
@@ -3344,7 +3344,7 @@ int gdbserver_start(const char *device) | ||
3344 | 3344 | /* Initialize a monitor terminal for gdb */ |
3345 | 3345 | mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, |
3346 | 3346 | NULL, NULL, &error_abort); |
3347 | - monitor_init(mon_chr, 0); | |
3347 | + monitor_init_hmp(mon_chr, false); | |
3348 | 3348 | } else { |
3349 | 3349 | qemu_chr_fe_deinit(&s->chr, true); |
3350 | 3350 | mon_chr = s->mon_chr; |
@@ -8,19 +8,14 @@ | ||
8 | 8 | extern __thread Monitor *cur_mon; |
9 | 9 | typedef struct MonitorHMP MonitorHMP; |
10 | 10 | |
11 | -/* flags for monitor_init */ | |
12 | -/* 0x01 unused */ | |
13 | -#define MONITOR_USE_READLINE 0x02 | |
14 | -#define MONITOR_USE_CONTROL 0x04 | |
15 | -#define MONITOR_USE_PRETTY 0x08 | |
16 | - | |
17 | 11 | #define QMP_REQ_QUEUE_LEN_MAX 8 |
18 | 12 | |
19 | 13 | bool monitor_cur_is_qmp(void); |
20 | 14 | |
21 | 15 | void monitor_init_globals(void); |
22 | 16 | void monitor_init_globals_core(void); |
23 | -void monitor_init(Chardev *chr, int flags); | |
17 | +void monitor_init_qmp(Chardev *chr, bool pretty); | |
18 | +void monitor_init_hmp(Chardev *chr, bool use_readline); | |
24 | 19 | void monitor_cleanup(void); |
25 | 20 | |
26 | 21 | int monitor_suspend(Monitor *mon); |
@@ -1395,14 +1395,14 @@ static void monitor_readline_flush(void *opaque) | ||
1395 | 1395 | monitor_flush(&mon->common); |
1396 | 1396 | } |
1397 | 1397 | |
1398 | -void monitor_init_hmp(Chardev *chr, int flags) | |
1398 | +void monitor_init_hmp(Chardev *chr, bool use_readline) | |
1399 | 1399 | { |
1400 | 1400 | MonitorHMP *mon = g_new0(MonitorHMP, 1); |
1401 | 1401 | |
1402 | 1402 | monitor_data_init(&mon->common, false, false, false); |
1403 | 1403 | qemu_chr_fe_init(&mon->common.chr, chr, &error_abort); |
1404 | 1404 | |
1405 | - mon->use_readline = flags & MONITOR_USE_READLINE; | |
1405 | + mon->use_readline = use_readline; | |
1406 | 1406 | if (mon->use_readline) { |
1407 | 1407 | mon->rs = readline_init(monitor_readline_printf, |
1408 | 1408 | monitor_readline_flush, |
@@ -163,9 +163,6 @@ extern int mon_refcount; | ||
163 | 163 | |
164 | 164 | extern HMPCommand hmp_cmds[]; |
165 | 165 | |
166 | -void monitor_init_qmp(Chardev *chr, int flags); | |
167 | -void monitor_init_hmp(Chardev *chr, int flags); | |
168 | - | |
169 | 166 | int monitor_puts(Monitor *mon, const char *str); |
170 | 167 | void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, |
171 | 168 | bool use_io_thread); |
@@ -551,15 +551,6 @@ void monitor_data_destroy(Monitor *mon) | ||
551 | 551 | qemu_mutex_destroy(&mon->mon_lock); |
552 | 552 | } |
553 | 553 | |
554 | -void monitor_init(Chardev *chr, int flags) | |
555 | -{ | |
556 | - if (flags & MONITOR_USE_CONTROL) { | |
557 | - monitor_init_qmp(chr, flags); | |
558 | - } else { | |
559 | - monitor_init_hmp(chr, flags); | |
560 | - } | |
561 | -} | |
562 | - | |
563 | 554 | void monitor_cleanup(void) |
564 | 555 | { |
565 | 556 | /* |
@@ -364,18 +364,15 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) | ||
364 | 364 | monitor_list_append(&mon->common); |
365 | 365 | } |
366 | 366 | |
367 | -void monitor_init_qmp(Chardev *chr, int flags) | |
367 | +void monitor_init_qmp(Chardev *chr, bool pretty) | |
368 | 368 | { |
369 | 369 | MonitorQMP *mon = g_new0(MonitorQMP, 1); |
370 | 370 | |
371 | - /* Only HMP supports readline */ | |
372 | - assert(!(flags & MONITOR_USE_READLINE)); | |
373 | - | |
374 | 371 | /* Note: we run QMP monitor in I/O thread when @chr supports that */ |
375 | 372 | monitor_data_init(&mon->common, true, false, |
376 | 373 | qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT)); |
377 | 374 | |
378 | - mon->pretty = flags & MONITOR_USE_PRETTY; | |
375 | + mon->pretty = pretty; | |
379 | 376 | |
380 | 377 | qemu_mutex_init(&mon->qmp_queue_lock); |
381 | 378 | mon->qmp_requests = g_queue_new(); |
@@ -16,7 +16,11 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp) | ||
16 | 16 | return -1; |
17 | 17 | } |
18 | 18 | |
19 | -void monitor_init(Chardev *chr, int flags) | |
19 | +void monitor_init_qmp(Chardev *chr, bool pretty) | |
20 | +{ | |
21 | +} | |
22 | + | |
23 | +void monitor_init_hmp(Chardev *chr, bool use_readline) | |
20 | 24 | { |
21 | 25 | } |
22 | 26 |
@@ -71,7 +71,8 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) | ||
71 | 71 | */ |
72 | 72 | __thread Monitor *cur_mon; |
73 | 73 | int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } |
74 | -void monitor_init(Chardev *chr, int flags) {} | |
74 | +void monitor_init_qmp(Chardev *chr, bool pretty) {} | |
75 | +void monitor_init_hmp(Chardev *chr, bool use_readline) {} | |
75 | 76 | |
76 | 77 | |
77 | 78 | static void test_socket_fd_pass_name_good(void) |
@@ -2299,25 +2299,27 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) | ||
2299 | 2299 | static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) |
2300 | 2300 | { |
2301 | 2301 | Chardev *chr; |
2302 | + bool qmp; | |
2303 | + bool pretty = false; | |
2302 | 2304 | const char *chardev; |
2303 | 2305 | const char *mode; |
2304 | - int flags; | |
2305 | 2306 | |
2306 | 2307 | mode = qemu_opt_get(opts, "mode"); |
2307 | 2308 | if (mode == NULL) { |
2308 | 2309 | mode = "readline"; |
2309 | 2310 | } |
2310 | 2311 | if (strcmp(mode, "readline") == 0) { |
2311 | - flags = MONITOR_USE_READLINE; | |
2312 | + qmp = false; | |
2312 | 2313 | } else if (strcmp(mode, "control") == 0) { |
2313 | - flags = MONITOR_USE_CONTROL; | |
2314 | + qmp = true; | |
2314 | 2315 | } else { |
2315 | 2316 | error_setg(errp, "unknown monitor mode \"%s\"", mode); |
2316 | 2317 | return -1; |
2317 | 2318 | } |
2318 | 2319 | |
2319 | - if (qemu_opt_get_bool(opts, "pretty", 0)) | |
2320 | - flags |= MONITOR_USE_PRETTY; | |
2320 | + if (qemu_opt_get_bool(opts, "pretty", 0)) { | |
2321 | + pretty = true; | |
2322 | + } | |
2321 | 2323 | |
2322 | 2324 | chardev = qemu_opt_get(opts, "chardev"); |
2323 | 2325 | if (!chardev) { |
@@ -2330,7 +2332,11 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) | ||
2330 | 2332 | return -1; |
2331 | 2333 | } |
2332 | 2334 | |
2333 | - monitor_init(chr, flags); | |
2335 | + if (qmp) { | |
2336 | + monitor_init_qmp(chr, pretty); | |
2337 | + } else { | |
2338 | + monitor_init_hmp(chr, true); | |
2339 | + } | |
2334 | 2340 | return 0; |
2335 | 2341 | } |
2336 | 2342 |