From patchwork Thu Jan 21 21:09:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 43455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F392EB7CF3 for ; Fri, 22 Jan 2010 08:24:28 +1100 (EST) Received: from localhost ([127.0.0.1]:48256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY4VB-0003L6-0W for incoming@patchwork.ozlabs.org; Thu, 21 Jan 2010 16:23:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NY4II-0000o6-4i for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NY4IC-0000hU-VJ for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:21 -0500 Received: from [199.232.76.173] (port=43484 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY4IC-0000h7-HQ for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48293) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NY4IC-0002ze-0a for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:16 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0LLAFEu005081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Jan 2010 16:10:15 -0500 Received: from localhost (vpn-9-176.rdu.redhat.com [10.11.9.176]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0LLADu0000789; Thu, 21 Jan 2010 16:10:14 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org, armbru@redhat.com, aliguori@us.ibm.com, avi@redhat.com Date: Thu, 21 Jan 2010 19:09:35 -0200 Message-Id: <1264108180-3666-7-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1264108180-3666-1-git-send-email-lcapitulino@redhat.com> References: <1264108180-3666-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 06/11] QMP: Array-based async messages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This commit moves the asynchronous messages names to an array of structs, so that it can be indexed and searched. Signed-off-by: Luiz Capitulino --- monitor.c | 67 +++++++++++++++++++++++++++++++------------------------------ 1 files changed, 34 insertions(+), 33 deletions(-) diff --git a/monitor.c b/monitor.c index 70a59c7..61c0273 100644 --- a/monitor.c +++ b/monitor.c @@ -336,6 +336,38 @@ static void timestamp_put(QDict *qdict) qdict_put_obj(qdict, "timestamp", obj); } +typedef struct MonitorEventName { + const char *name; +} MonitorEventName; + +static const MonitorEventName monitor_events_names[] = { + [QEVENT_DEBUG] = { + .name = "DEBUG", + }, + [QEVENT_SHUTDOWN] = { + .name = "SHUTDOWN", + }, + [QEVENT_RESET] = { + .name = "RESET", + }, + [QEVENT_POWERDOWN] = { + .name = "POWERDOWN", + }, + [QEVENT_STOP] = { + .name = "STOP", + }, + [QEVENT_VNC_CONNECTED] = { + .name = "VNC_CONNECTED", + }, + [QEVENT_VNC_INITIALIZED] = { + .name = "VNC_INITIALIZED", + }, + [QEVENT_VNC_DISCONNECTED] = { + .name = "VNC_DISCONNECTED", + }, + { }, +}; + /** * monitor_protocol_event(): Generate a Monitor event * @@ -344,44 +376,13 @@ static void timestamp_put(QDict *qdict) void monitor_protocol_event(MonitorEvent event, QObject *data) { QDict *qmp; - const char *event_name; Monitor *mon; - assert(event < QEVENT_MAX); - - switch (event) { - case QEVENT_DEBUG: - event_name = "DEBUG"; - break; - case QEVENT_SHUTDOWN: - event_name = "SHUTDOWN"; - break; - case QEVENT_RESET: - event_name = "RESET"; - break; - case QEVENT_POWERDOWN: - event_name = "POWERDOWN"; - break; - case QEVENT_STOP: - event_name = "STOP"; - break; - case QEVENT_VNC_CONNECTED: - event_name = "VNC_CONNECTED"; - break; - case QEVENT_VNC_INITIALIZED: - event_name = "VNC_INITIALIZED"; - break; - case QEVENT_VNC_DISCONNECTED: - event_name = "VNC_DISCONNECTED"; - break; - default: - abort(); - break; - } + assert(event >= 0 && event < QEVENT_MAX); qmp = qdict_new(); timestamp_put(qmp); - qdict_put(qmp, "event", qstring_from_str(event_name)); + qdict_put(qmp, "event", qstring_from_str(monitor_events_names[event].name)); if (data) { qobject_incref(data); qdict_put_obj(qmp, "data", data);