From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyyUe-0001gI-7j for qemu-devel@nongnu.org; Wed, 18 Nov 2015 03:53:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyyUd-00046L-2B for qemu-devel@nongnu.org; Wed, 18 Nov 2015 03:53:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyyUc-00045i-Rm for qemu-devel@nongnu.org; Wed, 18 Nov 2015 03:53:31 -0500 From: Eric Blake Date: Wed, 18 Nov 2015 01:53:00 -0700 Message-Id: <1447836791-369-26-git-send-email-eblake@redhat.com> In-Reply-To: <1447836791-369-1-git-send-email-eblake@redhat.com> References: <1447836791-369-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v12 25/36] qapi: Add alias for ErrorClass List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Luiz Capitulino , armbru@redhat.com, Michael Roth The qapi enum ErrorClass is unusual that it uses 'CamelCase' names, contrary to our documented convention of preferring 'lower-case'. However, this enum is entrenched in the API; we cannot change what strings QMP outputs. Meanwhile, we want to simplify how c_enum_const() is used to generate enum constants, by moving away from the heuristics of camel_to_upper() to a more straightforward c_name(N).upper() - but doing so will rename all of the ErrorClass constants and cause churn to all client files, where the new names are aesthetically less pleasing (ERROR_CLASS_DEVICENOTFOUND looks like we can't make up our minds on whether to break between words). So as always in computer science, solve the problem by some more indirection: rename the qapi type to QapiErrorClass, and add a new enum ErrorClass in error.h whose members are aliases of the qapi type, but with the spelling expected elsewhere in the tree. Then, when c_enum_const() changes the munging, we only have to adjust the one alias spot. Suggested by: Markus Armbruster Signed-off-by: Eric Blake --- v12: new patch --- include/qapi/error.h | 14 ++++++++++++++ monitor.c | 2 +- qapi/common.json | 5 +++-- qapi/qmp-dispatch.c | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/qapi/error.h b/include/qapi/error.h index b2362a5..299cbf4 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -108,6 +108,20 @@ typedef struct Error Error; /* + * Overall category of an error. + * Based on the qapi type QapiErrorClass, but reproduced here for nicer + * enum names. + */ +typedef enum ErrorClass { + ERROR_CLASS_GENERIC_ERROR = QAPI_ERROR_CLASS_GENERIC_ERROR, + ERROR_CLASS_COMMAND_NOT_FOUND = QAPI_ERROR_CLASS_COMMAND_NOT_FOUND, + ERROR_CLASS_DEVICE_ENCRYPTED = QAPI_ERROR_CLASS_DEVICE_ENCRYPTED, + ERROR_CLASS_DEVICE_NOT_ACTIVE = QAPI_ERROR_CLASS_DEVICE_NOT_ACTIVE, + ERROR_CLASS_DEVICE_NOT_FOUND = QAPI_ERROR_CLASS_DEVICE_NOT_FOUND, + ERROR_CLASS_KVM_MISSING_CAP = QAPI_ERROR_CLASS_KVM_MISSING_CAP, +} ErrorClass; + +/* * Get @err's human-readable error message. */ const char *error_get_pretty(Error *err); diff --git a/monitor.c b/monitor.c index 3a0df08..030e2b3 100644 --- a/monitor.c +++ b/monitor.c @@ -403,7 +403,7 @@ static QDict *build_qmp_error_dict(Error *err) QObject *obj; obj = qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %s } }", - ErrorClass_lookup[error_get_class(err)], + QapiErrorClass_lookup[error_get_class(err)], error_get_pretty(err)); return qobject_to_qdict(obj); diff --git a/qapi/common.json b/qapi/common.json index bad56bf..6fb40e7 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -3,7 +3,7 @@ # QAPI common definitions ## -# @ErrorClass +# @QapiErrorClass # # QEMU error classes # @@ -24,7 +24,8 @@ # # Since: 1.2 ## -{ 'enum': 'ErrorClass', +{ 'enum': 'QapiErrorClass', + # Keep this in sync with ErrorClass in error.h 'data': [ 'GenericError', 'CommandNotFound', 'DeviceEncrypted', 'DeviceNotActive', 'DeviceNotFound', 'KVMMissingCap' ] } diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 7bcc860..f36933d 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -114,7 +114,7 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp) QObject *qmp_build_error_object(Error *err) { return qobject_from_jsonf("{ 'class': %s, 'desc': %s }", - ErrorClass_lookup[error_get_class(err)], + QapiErrorClass_lookup[error_get_class(err)], error_get_pretty(err)); } -- 2.4.3