diff mbox

[18/20] monitor: Turn int command_mode into bool in_command_mode

Message ID 1432294585-5984-19-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster May 22, 2015, 11:36 a.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 monitor.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

Eric Blake May 22, 2015, 10:56 p.m. UTC | #1
On 05/22/2015 05:36 AM, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  monitor.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 

Might be worth mentioning in the commit message that...

>  
> -static inline int qmp_cmd_mode(const Monitor *mon)
> -{
> -    return mon->qmp.command_mode;
> -}

...qmp_cmd_mode() is now inlined into its callers.

Nice, fixes up a mis-use of 'int' that I complained about when writing
commit 2d5a8346

Reviewed-by: Eric Blake <eblake@redhat.com>
Markus Armbruster May 26, 2015, 9:49 a.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> On 05/22/2015 05:36 AM, Markus Armbruster wrote:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  monitor.c | 23 ++++++++++++-----------
>>  1 file changed, 12 insertions(+), 11 deletions(-)
>> 
>
> Might be worth mentioning in the commit message that...
>
>>  
>> -static inline int qmp_cmd_mode(const Monitor *mon)
>> -{
>> -    return mon->qmp.command_mode;
>> -}
>
> ...qmp_cmd_mode() is now inlined into its callers.

Can do.

> Nice, fixes up a mis-use of 'int' that I complained about when writing
> commit 2d5a8346
>
> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks!
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 6e9cc8c..f31a05d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -164,7 +164,12 @@  struct MonFdset {
 typedef struct {
     QObject *id;
     JSONMessageParser parser;
-    int command_mode;
+    /*
+     * When a client connects, we're in capabilities negotiation mode.
+     * When command qmp_capabilities succeeds, we go into command
+     * mode.
+     */
+    bool in_command_mode;       /* are we in command mode? */
 } MonitorQMP;
 
 /*
@@ -226,11 +231,6 @@  Monitor *default_mon;
 static void monitor_command_cb(void *opaque, const char *cmdline,
                                void *readline_opaque);
 
-static inline int qmp_cmd_mode(const Monitor *mon)
-{
-    return mon->qmp.command_mode;
-}
-
 /* Return true if in control mode, false otherwise */
 static inline int monitor_ctrl_mode(const Monitor *mon)
 {
@@ -446,7 +446,7 @@  static void monitor_qapi_event_emit(QAPIEvent event, QObject *data)
 
     trace_monitor_protocol_event_emit(event, data);
     QLIST_FOREACH(mon, &mon_list, entry) {
-        if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) {
+        if (monitor_ctrl_mode(mon) && mon->qmp.in_command_mode) {
             monitor_json_emitter(mon, data);
         }
     }
@@ -566,7 +566,7 @@  static void monitor_qapi_event_init(void)
 static int do_qmp_capabilities(Monitor *mon, const QDict *params,
                                QObject **ret_data)
 {
-    mon->qmp.command_mode = 1;
+    mon->qmp.in_command_mode = true;
     return 0;
 }
 
@@ -4701,13 +4701,14 @@  static int monitor_can_read(void *opaque)
 static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd)
 {
     bool is_cap = cmd->mhandler.cmd_new == do_qmp_capabilities;
-    if (is_cap && qmp_cmd_mode(mon)) {
+
+    if (is_cap && mon->qmp.in_command_mode) {
         qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND,
                       "Capabilities negotiation is already complete, command "
                       "'%s' ignored", cmd->name);
         return true;
     }
-    if (!is_cap && !qmp_cmd_mode(mon)) {
+    if (!is_cap && !mon->qmp.in_command_mode) {
         qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND,
                       "Expecting capabilities negotiation with "
                       "'qmp_capabilities' before command '%s'", cmd->name);
@@ -5111,7 +5112,7 @@  static void monitor_qmp_event(void *opaque, int event)
 
     switch (event) {
     case CHR_EVENT_OPENED:
-        mon->qmp.command_mode = 0;
+        mon->qmp.in_command_mode = false;
         data = get_qmp_greeting();
         monitor_json_emitter(mon, data);
         qobject_decref(data);