• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision920824165c49bfbd1e0e9e07fd92e0bbbf32aea3 (tree)
Zeit2019-06-18 15:14:17
AutorKevin Wolf <kwolf@redh...>
CommiterMarkus Armbruster

Log Message

monitor: Split Monitor.flags into separate bools

Monitor.flags contains three different flags: One to distinguish HMP
from QMP; one specific to HMP (MONITOR_USE_READLINE) that is ignored
with QMP; and another one specific to QMP (MONITOR_USE_PRETTY) that is
ignored with HMP.

Split the flags field into three bools and move them to the right
subclass. Flags are still in use for the monitor_init() interface.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20190613153405.24769-14-kwolf@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

Ändern Zusammenfassung

Diff

--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1398,12 +1398,12 @@ static void monitor_readline_flush(void *opaque)
13981398 void monitor_init_hmp(Chardev *chr, int flags)
13991399 {
14001400 MonitorHMP *mon = g_new0(MonitorHMP, 1);
1401- bool use_readline = flags & MONITOR_USE_READLINE;
14021401
1403- monitor_data_init(&mon->common, flags, false, false);
1402+ monitor_data_init(&mon->common, false, false, false);
14041403 qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
14051404
1406- if (use_readline) {
1405+ mon->use_readline = flags & MONITOR_USE_READLINE;
1406+ if (mon->use_readline) {
14071407 mon->rs = readline_init(monitor_readline_printf,
14081408 monitor_readline_flush,
14091409 mon,
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -121,7 +121,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
121121 Monitor *old_mon;
122122 MonitorHMP hmp = {};
123123
124- monitor_data_init(&hmp.common, 0, true, false);
124+ monitor_data_init(&hmp.common, false, true, false);
125125
126126 old_mon = cur_mon;
127127 cur_mon = &hmp.common;
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -86,8 +86,8 @@ typedef struct HMPCommand {
8686 struct Monitor {
8787 CharBackend chr;
8888 int reset_seen;
89- int flags;
9089 int suspend_cnt; /* Needs to be accessed atomically */
90+ bool is_qmp;
9191 bool skip_flush;
9292 bool use_io_thread;
9393
@@ -112,6 +112,7 @@ struct Monitor {
112112
113113 struct MonitorHMP {
114114 Monitor common;
115+ bool use_readline;
115116 /*
116117 * State used only in the thread "owning" the monitor.
117118 * If @use_io_thread, this is @mon_iothread. (This does not actually happen
@@ -125,6 +126,7 @@ struct MonitorHMP {
125126 typedef struct {
126127 Monitor common;
127128 JSONMessageParser parser;
129+ bool pretty;
128130 /*
129131 * When a client connects, we're in capabilities negotiation mode.
130132 * @commands is &qmp_cap_negotiation_commands then. When command
@@ -148,7 +150,7 @@ typedef struct {
148150 */
149151 static inline bool monitor_is_qmp(const Monitor *mon)
150152 {
151- return mon->flags & MONITOR_USE_CONTROL;
153+ return mon->is_qmp;
152154 }
153155
154156 typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList;
@@ -165,7 +167,7 @@ void monitor_init_qmp(Chardev *chr, int flags);
165167 void monitor_init_hmp(Chardev *chr, int flags);
166168
167169 int monitor_puts(Monitor *mon, const char *str);
168-void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
170+void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
169171 bool use_io_thread);
170172 void monitor_data_destroy(Monitor *mon);
171173 int monitor_can_read(void *opaque);
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -78,14 +78,18 @@ bool monitor_cur_is_qmp(void)
7878 * Note: not all HMP monitors use readline, e.g., gdbserver has a
7979 * non-interactive HMP monitor, so readline is not used there.
8080 */
81-static inline bool monitor_uses_readline(const Monitor *mon)
81+static inline bool monitor_uses_readline(const MonitorHMP *mon)
8282 {
83- return mon->flags & MONITOR_USE_READLINE;
83+ return mon->use_readline;
8484 }
8585
8686 static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)
8787 {
88- return !monitor_is_qmp(mon) && !monitor_uses_readline(mon);
88+ if (monitor_is_qmp(mon)) {
89+ return false;
90+ }
91+
92+ return !monitor_uses_readline(container_of(mon, MonitorHMP, common));
8993 }
9094
9195 static void monitor_flush_locked(Monitor *mon);
@@ -521,17 +525,17 @@ static void monitor_iothread_init(void)
521525 mon_iothread = iothread_create("mon_iothread", &error_abort);
522526 }
523527
524-void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
528+void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
525529 bool use_io_thread)
526530 {
527531 if (use_io_thread && !mon_iothread) {
528532 monitor_iothread_init();
529533 }
530534 qemu_mutex_init(&mon->mon_lock);
535+ mon->is_qmp = is_qmp;
531536 mon->outbuf = qstring_new();
532537 mon->skip_flush = skip_flush;
533538 mon->use_io_thread = use_io_thread;
534- mon->flags = flags;
535539 }
536540
537541 void monitor_data_destroy(Monitor *mon)
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -87,8 +87,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
8787 const QObject *data = QOBJECT(rsp);
8888 QString *json;
8989
90- json = mon->common.flags & MONITOR_USE_PRETTY ?
91- qobject_to_json_pretty(data) : qobject_to_json(data);
90+ json = mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(data);
9291 assert(json != NULL);
9392
9493 qstring_append_chr(json, '\n');
@@ -373,9 +372,11 @@ void monitor_init_qmp(Chardev *chr, int flags)
373372 assert(!(flags & MONITOR_USE_READLINE));
374373
375374 /* Note: we run QMP monitor in I/O thread when @chr supports that */
376- monitor_data_init(&mon->common, flags, false,
375+ monitor_data_init(&mon->common, true, false,
377376 qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
378377
378+ mon->pretty = flags & MONITOR_USE_PRETTY;
379+
379380 qemu_mutex_init(&mon->qmp_queue_lock);
380381 mon->qmp_requests = g_queue_new();
381382