Received: from eggs.gnu.org ([2001:4830:134:3::10]:56309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWo0-0002BA-8w for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWny-00039p-V9 for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:23:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60008) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWny-00039T-Lh for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:23:30 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C226C05A290 for ; Mon, 10 Oct 2016 09:23:30 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 10 Oct 2016 13:22:44 +0400 Message-Id: <20161010092301.14974-8-marcandre.lureau@redhat.com> In-Reply-To: <20161010092301.14974-1-marcandre.lureau@redhat.com> References: <20161010092301.14974-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 07/24] qmp: introduce async command type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: eblake@redhat.com, berrange@redhat.com, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Qemu used to have command types, but it was removed in 42a502a7a60632234f0dd5028924926a7eac6c94. Add it back, and add 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=C3=A9 Lureau --- qapi/qmp-dispatch.c | 21 ++++++++++++++------- qapi/qmp-registry.c | 25 ++++++++++++++++++++++--- include/qapi/qmp/dispatch.h | 14 +++++++++++++- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 0c4022f..7e1ef54 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -95,13 +95,20 @@ static QObject *do_qmp_dispatch(QObject *request, Qmp= Return *qret, Error **errp) QINCREF(args); } =20 - cmd->fn(args, &ret, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } else if (cmd->options & QCO_NO_SUCCESS_RESP) { - g_assert(!ret); - } else if (!ret) { - ret =3D QOBJECT(qdict_new()); + switch (cmd->type) { + case QCT_NORMAL: + cmd->fn(args, &ret, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } else if (cmd->options & QCO_NO_SUCCESS_RESP) { + g_assert(!ret); + } else if (!ret) { + ret =3D QOBJECT(qdict_new()); + } + break; + case QCT_ASYNC: + cmd->fn_async(args, qret); + break; } =20 QDECREF(args); diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index e805368..52b5f4c 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -18,16 +18,35 @@ static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =3D QTAILQ_HEAD_INITIALIZER(qmp_commands); =20 -void qmp_register_command(const char *name, QmpCommandFunc *fn, - QmpCommandOptions options) +static QmpCommand *qmp_command_new(const char *name, + QmpCommandOptions options) { QmpCommand *cmd =3D g_malloc0(sizeof(*cmd)); =20 cmd->name =3D name; - cmd->fn =3D fn; cmd->enabled =3D true; cmd->options =3D options; QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node); + + return cmd; +} + +void qmp_register_command(const char *name, QmpCommandFunc *fn, + QmpCommandOptions options) +{ + QmpCommand *cmd =3D qmp_command_new(name, options); + + cmd->type =3D QCT_NORMAL; + cmd->fn =3D fn; +} + +void qmp_register_async_command(const char *name, QmpCommandFuncAsync *f= n, + QmpCommandOptions options) +{ + QmpCommand *cmd =3D qmp_command_new(name, options); + + cmd->type =3D QCT_ASYNC; + cmd->fn_async =3D fn; } =20 void qmp_unregister_command(const char *name) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index bc64d4e..e13e381 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -35,6 +35,12 @@ struct QmpClient { }; =20 typedef void (QmpCommandFunc)(QDict *, QObject **, Error **); +typedef void (QmpCommandFuncAsync)(QDict *, QmpReturn *); + +typedef enum QmpCommandType { + QCT_NORMAL, + QCT_ASYNC, +} QmpCommandType; =20 typedef enum QmpCommandOptions { @@ -44,8 +50,12 @@ typedef enum QmpCommandOptions =20 typedef struct QmpCommand { + QmpCommandType type; const char *name; - QmpCommandFunc *fn; + union { + QmpCommandFunc *fn; + QmpCommandFuncAsync *fn_async; + }; QmpCommandOptions options; QTAILQ_ENTRY(QmpCommand) node; bool enabled; @@ -53,6 +63,8 @@ typedef struct QmpCommand =20 void qmp_register_command(const char *name, QmpCommandFunc *fn, QmpCommandOptions options); +void qmp_register_async_command(const char *name, QmpCommandFuncAsync *f= n, + QmpCommandOptions options); void qmp_unregister_command(const char *name); QmpCommand *qmp_find_command(const char *name); void qmp_client_init(QmpClient *client, QmpDispatchReturn *return_cb); --=20 2.10.0