From patchwork Wed Feb 24 17:55:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46158 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 9CAD3B7067 for ; Thu, 25 Feb 2010 05:16:39 +1100 (EST) Received: from localhost ([127.0.0.1]:60542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkLmm-0005t1-9A for incoming@patchwork.ozlabs.org; Wed, 24 Feb 2010 13:16:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NkLTG-00080R-4r for qemu-devel@nongnu.org; Wed, 24 Feb 2010 12:56:26 -0500 Received: from [199.232.76.173] (port=59151 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkLTE-0007zc-Mi for qemu-devel@nongnu.org; Wed, 24 Feb 2010 12:56:24 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NkLT8-0006Tc-5Q for qemu-devel@nongnu.org; Wed, 24 Feb 2010 12:56:23 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:37633) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NkLT4-0006S2-Kl for qemu-devel@nongnu.org; Wed, 24 Feb 2010 12:56:15 -0500 Received: from blackfin.pond.sub.org (pD9E38C12.dip.t-dialin.net [217.227.140.18]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 6AD423127B7 for ; Wed, 24 Feb 2010 18:56:06 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 5C3F3D6; Wed, 24 Feb 2010 18:56:03 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 24 Feb 2010 18:55:55 +0100 Message-Id: <1267034160-3517-44-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1267034160-3517-1-git-send-email-armbru@redhat.com> References: <1267034160-3517-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH RFC 43/48] qemu-option: Functions to convert to/from QDict. 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 FIXME Only string options are implemented. Signed-off-by: Markus Armbruster --- qemu-option.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-option.h | 3 +++ 2 files changed, 57 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index ab488e4..f86aac0 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -29,6 +29,8 @@ #include "qemu-common.h" #include "qemu-error.h" #include "qemu-option.h" +#include "qobject.h" +#include "qstring.h" /* * Extracts the name of an option from the parameter string (p points at the @@ -777,6 +779,58 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *fi return opts; } +static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque) +{ + const char *value; + + if (!strcmp(key, "id")) { + return; + } + + switch (qobject_type(obj)) { + case QTYPE_QSTRING: + value = qstring_get_str(qobject_to_qstring(obj)); + break; + default: + abort(); // FIXME implement + } + qemu_opt_set(opaque, key, value); +} + +QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict) +{ + const char *id; + QemuOpts *opts; + + id = qdict_haskey(qdict, "id") ? qdict_get_str(qdict, "id") : NULL; + opts = qemu_opts_create(list, id, 1); + if (opts == NULL) + return NULL; + + qdict_iter(qdict, qemu_opts_from_qdict_1, opts); + return opts; +} + +static int qemu_opts_to_qdict_1(const char *name, const char *value, + void *opaque) +{ + qdict_put(opaque, name, qstring_from_str(value)); + // FIXME obey QemuOptType + return 0; +} + +QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict) +{ + if (!qdict) { + qdict = qdict_new(); + } + if (opts->id) { + qdict_put(qdict, "id", qstring_from_str(opts->id)); + } + qemu_opt_foreach(opts, qemu_opts_to_qdict_1, qdict, 0); + return qdict; +} + /* Validate parsed opts against descriptions where no * descriptions were provided in the QemuOptsList. */ diff --git a/qemu-option.h b/qemu-option.h index f3f1de7..d735386 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -28,6 +28,7 @@ #include #include "qemu-queue.h" +#include "qdict.h" enum QEMUOptionParType { OPT_FLAG, @@ -118,6 +119,8 @@ void qemu_opts_del(QemuOpts *opts); int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc); int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname); +QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict); +QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict); typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); int qemu_opts_print(QemuOpts *opts, void *dummy);