From: Anthony Liguori <aliguori@us.ibm.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: pbonzini@redhat.com, hollisb@linux.vnet.ibm.com,
qemu-devel@nongnu.org, kraxel@redhat.com
Subject: [Qemu-devel] Re: [PATCH 2/7] Introduce QError
Date: Thu, 29 Oct 2009 15:14:12 -0500 [thread overview]
Message-ID: <4AE9F794.4030204@us.ibm.com> (raw)
In-Reply-To: <1256841750-15228-3-git-send-email-lcapitulino@redhat.com>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> Makefile | 2 +-
> qerror.c | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> qerror.h | 48 ++++++++++++
> qobject.h | 1 +
> 4 files changed, 290 insertions(+), 1 deletions(-)
> create mode 100644 qerror.c
> create mode 100644 qerror.h
>
> diff --git a/Makefile b/Makefile
> index 813bd0a..325e583 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -125,7 +125,7 @@ obj-y += net.o net-queue.o
> obj-y += qemu-char.o aio.o net-checksum.o savevm.o
> obj-y += msmouse.o ps2.o
> obj-y += qdev.o qdev-properties.o
> -obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o qjson.o
> +obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o qjson.o qerror.o
> obj-y += qemu-config.o
>
> obj-$(CONFIG_BRLAPI) += baum.o
> diff --git a/qerror.c b/qerror.c
> new file mode 100644
> index 0000000..0359d65
> --- /dev/null
> +++ b/qerror.c
> @@ -0,0 +1,240 @@
> +/*
> + * QError: QEMU Error data-type.
> + *
> + * Copyright (C) 2009 Red Hat Inc.
> + *
> + * Authors:
> + * Luiz Capitulino <lcapitulino@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2. See
> + * the COPYING file in the top-level directory.
> + */
> +#include "qint.h"
> +#include "qjson.h"
> +#include "qerror.h"
> +#include "qstring.h"
> +#include "sysemu.h"
> +#include "qemu-common.h"
> +
> +static void qerror_destroy_obj(QObject *obj);
> +
> +static const QType qerror_type = {
> + .code = QTYPE_QERROR,
> + .destroy = qerror_destroy_obj,
> +};
> +
> +/**
> + * The 'desc' member is a printf-like string, the format of the format
> + * string is:
> + *
> + * %(KEY)TYPE
> + *
> + * Where KEY is a QDict key and TYPE is the type of its value, KEY and
> + * its value must be passed to qerror_from_info().
> + *
> + * Example:
> + *
> + * "foo error on device: %(device)s slot: %(slot_nr)s"
> + *
> + * A single percent sign can be printed if followed by a second one,
> + * for example:
> + *
> + * "running out of foo: %(foo)d%%"
> + *
> + * Valid types are:
> + *
> + * s (string)
> + * d (integer)
> + */
> +static QErrorTable qerror_table[] = {
> + {
> + .code = QERR_UNKNOWN,
> + .desc = "unknown error",
> + },
> +};
> +
> +/**
> + * qerror_new(): Create a new QError
> + *
> + * Return strong reference.
> + */
> +QError *qerror_new(void)
> +{
> + QError *qerr;
> +
> + qerr = qemu_mallocz(sizeof(*qerr));
> + QOBJECT_INIT(qerr, &qerror_type);
> +
> + return qerr;
> +}
> +
> +/**
> + * qerror_from_info(): Create a new QError from error information
> + *
> + * The information consists of:
> + *
> + * - code: error code
> + * - file: the file of where the error happend
> + * - linenr: the line number of where the error happend
> + * - fmt: JSON printf-like format
> + * - va: va_list of all arguments
> + *
> + * Return strong reference.
> + */
> +QError *qerror_from_info(QErrorCode code, const char *file, int linenr,
> + const char *fmt, va_list *va)
> +{
>
va_list doesn't need to be a pointer.
Shouldn't this take a ... too?
> diff --git a/qerror.h b/qerror.h
> new file mode 100644
> index 0000000..2fd0d58
> --- /dev/null
> +++ b/qerror.h
> @@ -0,0 +1,48 @@
> +/*
> + * QError header file.
> + *
> + * Copyright (C) 2009 Red Hat Inc.
> + *
> + * Authors:
> + * Luiz Capitulino <lcapitulino@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2. See
> + * the COPYING file in the top-level directory.
> + */
> +#ifndef QERROR_H
> +#define QERROR_H
> +
> +#include <stdarg.h>
> +#include "qobject.h"
> +
> +/*
> + * IMPORTANT: errors numbers must not change after they have been
> + * added here.
> + */
> +typedef enum QErrorCode {
> + QERR_UNKNOWN,
> + QERR_MAX,
> +} QErrorCode;
> +
> +struct QError;
> +
> +typedef struct QErrorTable {
> + QErrorCode code;
> + const char *desc;
> +} QErrorTable;
> +
> +typedef struct QError {
> + QObject_HEAD;
> + int linenr; /* error line number */
> + const char *file; /* error file */
> + QObject *data; /* error specific data */
> + const QErrorTable *entry;
> +} QError;
> +
> +QError *qerror_new(void);
> +QError *qerror_from_info(QErrorCode code, const char *file, int linenr,
> + const char *fmt, va_list *va);
>
I don't know how I feel about the linenr/file bit. It seems prone to
misused when used in a public interface (vs. automatically via a macro).
--
Regards,
Anthony Liguori
next prev parent reply other threads:[~2009-10-29 20:14 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-29 18:42 [Qemu-devel] [RFC 0/7] QError v1 Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 1/7] QJSon: Introduce qobject_from_json_va() Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 2/7] Introduce QError Luiz Capitulino
2009-10-29 20:14 ` Anthony Liguori [this message]
2009-10-29 20:48 ` [Qemu-devel] " Luiz Capitulino
2009-10-29 22:08 ` Paolo Bonzini
2009-10-30 2:25 ` Jamie Lokier
2009-10-30 13:05 ` Anthony Liguori
2009-10-30 13:48 ` Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 3/7] monitor: QError support Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 4/7] QError: Add QERR_DEV_NFOUND Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 5/7] qdev: Use QError for not found error Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 6/7] QError: Add do_info_balloon() errors Luiz Capitulino
2009-10-29 18:42 ` [Qemu-devel] [PATCH 7/7] monitor: do_info_balloon(): use QError Luiz Capitulino
2009-10-29 22:12 ` [Qemu-devel] Re: [RFC 0/7] QError v1 Paolo Bonzini
2009-10-30 12:28 ` Luiz Capitulino
2009-10-30 12:56 ` Gerd Hoffmann
2009-10-30 13:09 ` Anthony Liguori
2009-10-30 13:45 ` Paolo Bonzini
2009-10-30 13:47 ` Luiz Capitulino
2009-10-30 13:59 ` Anthony Liguori
2009-10-30 14:46 ` Luiz Capitulino
2009-10-30 16:28 ` Jamie Lokier
2009-10-30 16:34 ` Paolo Bonzini
2009-10-30 17:15 ` Daniel P. Berrange
2009-10-30 17:33 ` Paolo Bonzini
2009-10-30 17:48 ` Anthony Liguori
2009-11-01 12:28 ` Vincent Hanquez
2009-10-30 17:40 ` Anthony Liguori
2009-10-30 18:09 ` Jamie Lokier
2009-10-30 18:10 ` Paolo Bonzini
2009-10-30 19:04 ` Anthony Liguori
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=4AE9F794.4030204@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=hollisb@linux.vnet.ibm.com \
--cc=kraxel@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.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).