From patchwork Fri Sep 25 14:03:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 522830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 484F21402A2 for ; Sat, 26 Sep 2015 00:17:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=lPW44R4Z; dkim-atps=neutral Received: from localhost ([::1]:42069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfTo6-0001rt-Ej for incoming@patchwork.ozlabs.org; Fri, 25 Sep 2015 10:17:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfTcF-0007HS-Nl for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:04:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfTc9-0003ii-VZ for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:04:47 -0400 Received: from mail-wi0-x22e.google.com ([2a00:1450:400c:c05::22e]:34470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfTc9-0003iD-OS for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:04:41 -0400 Received: by wicfx3 with SMTP id fx3so23394352wic.1 for ; Fri, 25 Sep 2015 07:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=WKusL5PPR1dZGa8ACzhKr9Pz3mVOAhSpUxwRUjI6LdQ=; b=lPW44R4ZbPd0IEM8tGzEg+lifEw4r+lPwdNhAF3FjwHSNQCOfPay+KnyvRjVx14b6t yK3KOdnOu1jrapmkF/8TrEjIzz1APgouerN+CH3tlBVdS2Hh/boEzOtXdZ6qmj/yKvyD mvxipderycJFDfkgsfq91txALSfnZdCUco/HzrW0K4oi5LHRXUTM9j4qX4reZP3JR+sy 07PHOltIo842riDJafl46YrPTtgASEdHYC1p+GzKlWMTTrxJzGV1D0zmxsw9cl7Xipzn 3LSxCXEra8NLWpjfnc8bnhAED26ojVzkYCjQtdePXq1HC6enDw2i/Gn/zrGmtwYAVvFD 8QZg== X-Received: by 10.194.116.106 with SMTP id jv10mr7365988wjb.0.1443189881172; Fri, 25 Sep 2015 07:04:41 -0700 (PDT) Received: from localhost ([149.6.167.210]) by smtp.gmail.com with ESMTPSA id gl4sm3524579wjb.29.2015.09.25.07.04.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Sep 2015 07:04:40 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 25 Sep 2015 16:03:53 +0200 Message-Id: <1443189844-20341-26-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443189844-20341-1-git-send-email-marcandre.lureau@redhat.com> References: <1443189844-20341-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22e Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 25/36] qmp: introduce async command type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau Learn a new type of command, QmpCommandFuncAsync. They can return later thanks to QmpReturn. This commit introduces the new types and register functions. Signed-off-by: Marc-André Lureau --- include/qapi/qmp/dispatch.h | 5 +++++ qapi/qmp-dispatch.c | 3 +++ qapi/qmp-registry.c | 26 ++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 747fff9..e45ab9f 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -36,10 +36,12 @@ struct QmpClient { }; typedef void (QmpCommandFunc)(QDict *, QObject **, Error **); +typedef void (QmpCommandFuncAsync)(QDict *, QmpReturn *); typedef enum QmpCommandType { QCT_NORMAL, + QCT_ASYNC, } QmpCommandType; typedef enum QmpCommandOptions @@ -53,6 +55,7 @@ typedef struct QmpCommand const char *name; QmpCommandType type; QmpCommandFunc *fn; + QmpCommandFuncAsync *fn_async; QmpCommandOptions options; QTAILQ_ENTRY(QmpCommand) node; bool enabled; @@ -60,6 +63,8 @@ typedef struct QmpCommand void qmp_register_command(const char *name, QmpCommandFunc *fn, QmpCommandOptions options); +void qmp_register_async_command(const char *name, QmpCommandFuncAsync *fn, + QmpCommandOptions options); QmpCommand *qmp_find_command(const char *name); void qmp_client_init(QmpClient *client, QmpDispatchReturn *return_cb); void qmp_client_destroy(QmpClient *client); diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index d2cc300..83ecab5 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -104,6 +104,9 @@ static QObject *do_qmp_dispatch(QObject *request, QmpReturn *qret, Error **errp) ret = QOBJECT(qdict_new()); } break; + case QCT_ASYNC: + cmd->fn_async(args, qret); + break; } QDECREF(args); diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index 3e4498a..90f6a8c 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -19,17 +19,35 @@ static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands = QTAILQ_HEAD_INITIALIZER(qmp_commands); -void qmp_register_command(const char *name, QmpCommandFunc *fn, - QmpCommandOptions options) +static QmpCommand *qmp_command_new(const char *name, + QmpCommandOptions options) { QmpCommand *cmd = g_malloc0(sizeof(*cmd)); cmd->name = name; - cmd->type = QCT_NORMAL; - cmd->fn = fn; cmd->enabled = true; cmd->options = options; QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node); + + return cmd; +} + +void qmp_register_command(const char *name, QmpCommandFunc *fn, + QmpCommandOptions options) +{ + QmpCommand *cmd = qmp_command_new(name, options); + + cmd->type = QCT_NORMAL; + cmd->fn = fn; +} + +void qmp_register_async_command(const char *name, QmpCommandFuncAsync *fn, + QmpCommandOptions options) +{ + QmpCommand *cmd = qmp_command_new(name, options); + + cmd->type = QCT_ASYNC; + cmd->fn_async = fn; } QmpCommand *qmp_find_command(const char *name)