qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com
Subject: [Qemu-devel] Re: [PATCH 01/22] QObject API: add qdict_to_qstring() function
Date: Fri, 9 Apr 2010 14:26:28 -0300	[thread overview]
Message-ID: <20100409142628.0bbfa1ee@redhat.com> (raw)
In-Reply-To: <1270757799-31891-2-git-send-email-miguel.filho@gmail.com>

On Thu,  8 Apr 2010 17:16:18 -0300
Miguel Di Ciurcio Filho <miguel.filho@gmail.com> wrote:

> This is a helper function that converts a QDict to a QString, using the format:
> 
> key1=value1 SPACE key2=value2 SPACE key3=value3
> 
> Handy for debugging and other things.
> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  qdict.c |   39 +++++++++++++++++++++++++++++++++++++++
>  qdict.h |    3 +++
>  2 files changed, 42 insertions(+), 0 deletions(-)
> 
> diff --git a/qdict.c b/qdict.c
> index aae57bf..ca1a60b 100644
> --- a/qdict.c
> +++ b/qdict.c
> @@ -324,6 +324,45 @@ void qdict_iter(const QDict *qdict,
>      }
>  }
>  
> +void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque)
> +{
> +    QString *str = opaque;
> +    
> +    qstring_append(str, key);
> +    qstring_append(str, "=");
> +    switch (qobject_type(obj)) {
> +    case QTYPE_QSTRING:
> +        qstring_append(str, qstring_get_str(qobject_to_qstring(obj)));
> +        break;
> +    case QTYPE_QINT:
> +        qstring_append_int(str, qint_get_int(qobject_to_qint(obj)));
> +        break;
> +    case QTYPE_QBOOL:
> +        qstring_append(str, qbool_get_int(qobject_to_qbool(obj)) ? "true" :
> +        "false" );
> +        break;
> +    default:
> +        qstring_append(str, "NULL");
> +    }
> +
> +    qstring_append(str, " ");
> +}
> +
> +/**
> + * qdict_to_qstring(): Format a string with the keys and values of a QDict
> + *
> + * Return a pointer to a QString, with the following format:
> + *    key1=value1 SPACE key2=value2 SPACE key3=value3
> + */

 It's a good idea to mention that nested lists and dicts are not
supported.

> +QString *qdict_to_qstring(const QDict *qdict)
> +{
> +    QString *str;
> +    str = qstring_new();
> +    qdict_iter(qdict, qdict_to_qstring_iter, str);
> +
> +    return str;
> +}
> +
>  /**
>   * qentry_destroy(): Free all the memory allocated by a QDictEntry
>   */
> diff --git a/qdict.h b/qdict.h
> index 579dcdd..6731555 100644
> --- a/qdict.h
> +++ b/qdict.h
> @@ -3,6 +3,7 @@
>  
>  #include "qobject.h"
>  #include "qlist.h"
> +#include "qstring.h"
>  #include "qemu-queue.h"
>  #include <stdint.h>
>  
> @@ -43,6 +44,8 @@ int qdict_get_bool(const QDict *qdict, const char *key);
>  QList *qdict_get_qlist(const QDict *qdict, const char *key);
>  QDict *qdict_get_qdict(const QDict *qdict, const char *key);
>  const char *qdict_get_str(const QDict *qdict, const char *key);
> +void qdict_to_qstring_iter(const char *key, QObject *obj, void *opaque);
> +QString *qdict_to_qstring(const QDict *qdict);
>  int64_t qdict_get_try_int(const QDict *qdict, const char *key,
>                            int64_t err_value);
>  const char *qdict_get_try_str(const QDict *qdict, const char *key);

  reply	other threads:[~2010-04-09 17:52 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-08 20:16 [Qemu-devel] [PATCH 0/22] Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 01/22] QObject API: add qdict_to_qstring() function Miguel Di Ciurcio Filho
2010-04-09 17:26   ` Luiz Capitulino [this message]
2010-04-08 20:16 ` [Qemu-devel] [PATCH 02/22] net: replace qemu_nic_format_info_str and VLANClientState->info_str by QDicts Miguel Di Ciurcio Filho
2010-04-09 17:41   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 03/22] net: dp8393x: replace qemu_format_nic_info_str by qemu_format_nic_info_dict Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 04/22] net: e1000: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 05/22] net: eepro100: " Miguel Di Ciurcio Filho
2010-04-09 17:42   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 06/22] net: ne2000: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 07/22] net: pcnet: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 08/22] net: lan9118: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 09/22] net: mcf_fec: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 10/22] net: mipsnet: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 11/22] net: rtl8139: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 12/22] net: smc91c111: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 13/22] net: stellaris_enet: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 14/22] net: usb-net: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 15/22] net: virtio-net: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 16/22] net: xilinx_ethlite: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 17/22] net: dump: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 18/22] net: slirp: " Miguel Di Ciurcio Filho
2010-04-09 17:42   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 19/22] net: socket: " Miguel Di Ciurcio Filho
2010-04-09 17:47   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 20/22] net: tap: replace qemu_format_nic_info_str by info_dict Miguel Di Ciurcio Filho
2010-04-09 17:48   ` [Qemu-devel] " Luiz Capitulino
2010-04-08 20:16 ` [Qemu-devel] [PATCH 21/22] net: vde: " Miguel Di Ciurcio Filho
2010-04-08 20:16 ` [Qemu-devel] [PATCH 22/22] monitor/net: Convert do_info_network() to QObject/QMP Miguel Di Ciurcio Filho
2010-04-09 17:52   ` [Qemu-devel] " Luiz Capitulino
2010-04-09 17:25 ` [Qemu-devel] Re: [PATCH 0/22] " Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100409142628.0bbfa1ee@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=armbru@redhat.com \
    --cc=miguel.filho@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).