Received: from eggs.gnu.org ([208.118.235.92]:51321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfzGG-0003B6-Hh for qemu-devel@nongnu.org; Tue, 04 Dec 2012 15:38:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfzGE-0006bY-Ot for qemu-devel@nongnu.org; Tue, 04 Dec 2012 15:38:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:27712) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfzGE-0006bQ-Gk for qemu-devel@nongnu.org; Tue, 04 Dec 2012 15:38:34 -0500 Date: Tue, 4 Dec 2012 17:41:42 -0200 From: Eduardo Habkost Message-ID: <20121204194142.GF4986@otherpad.lan.raisama.net> References: <1354649683-9078-1-git-send-email-ehabkost@redhat.com> <1354649683-9078-6-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1354649683-9078-6-git-send-email-ehabkost@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Igor Mammedov , Don Slutz , Andreas =?iso-8859-1?Q?F=E4rber?= On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote: > From: Igor Mammedov >=20 > Signed-off-by: Igor Mammedov > Acked-by: Andreas F=E4rber Reviewed-by: Eduardo Habkost > --- > qapi/qapi-visit-core.c | 11 +++++++++++ > qapi/qapi-visit-core.h | 2 ++ > qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ > 3 files changed, 35 insertions(+) >=20 > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c > index 7a82b63..5c8705e 100644 > --- a/qapi/qapi-visit-core.c > +++ b/qapi/qapi-visit-core.c > @@ -311,3 +311,14 @@ void input_type_enum(Visitor *v, int *obj, const c= har *strings[], > g_free(enum_str); > *obj =3D value; > } > + > +void visit_type_freq(Visitor *v, int64_t *obj, const char *name, Error= **errp) > +{ > + if (!error_is_set(errp)) { > + if (v->type_freq) { > + v->type_freq(v, obj, name, errp); > + } else { > + v->type_int(v, obj, name, errp); > + } > + } > +} > diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h > index 60aceda..e5e7dd7 100644 > --- a/qapi/qapi-visit-core.h > +++ b/qapi/qapi-visit-core.h > @@ -62,6 +62,7 @@ struct Visitor > void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Err= or **errp); > /* visit_type_size() falls back to (*type_uint64)() if type_size i= s unset */ > void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Err= or **errp); > + void (*type_freq)(Visitor *v, int64_t *obj, const char *name, Erro= r **errp); > }; > =20 > void visit_start_handle(Visitor *v, void **obj, const char *kind, > @@ -91,5 +92,6 @@ void visit_type_size(Visitor *v, uint64_t *obj, const= char *name, Error **errp); > void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **= errp); > void visit_type_str(Visitor *v, char **obj, const char *name, Error **= errp); > void visit_type_number(Visitor *v, double *obj, const char *name, Erro= r **errp); > +void visit_type_freq(Visitor *v, int64_t *obj, const char *name, Error= **errp); > =20 > #endif > diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c > index 497eb9a..74fe395 100644 > --- a/qapi/string-input-visitor.c > +++ b/qapi/string-input-visitor.c > @@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool = *present, > *present =3D true; > } > =20 > +static void parse_type_freq(Visitor *v, int64_t *obj, const char *name= , > + Error **errp) > +{ > + StringInputVisitor *siv =3D DO_UPCAST(StringInputVisitor, visitor,= v); > + char *endp =3D (char *) siv->string; > + long long val =3D 0; > + > + errno =3D 0; > + if (siv->string) { > + val =3D strtosz_suffix_unit(siv->string, &endp, > + STRTOSZ_DEFSUFFIX_B, 1000); > + } > + if (!siv->string || val =3D=3D -1 || *endp) { > + error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, > + "a value representable as a non-negative int64"); > + return; > + } > + > + *obj =3D val; > +} > + > Visitor *string_input_get_visitor(StringInputVisitor *v) > { > return &v->visitor; > @@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const = char *str) > v->visitor.type_str =3D parse_type_str; > v->visitor.type_number =3D parse_type_number; > v->visitor.start_optional =3D parse_start_optional; > + v->visitor.type_freq =3D parse_type_freq; > =20 > v->string =3D str; > return v; > --=20 > 1.7.11.7 >=20 >=20 --=20 Eduardo