David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 1 | /* |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 2 | * QError Module |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2009 Red Hat Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Luiz Capitulino <lcapitulino@redhat.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. |
| 10 | * See the COPYING.LIB file in the top-level directory. |
| 11 | */ |
| 12 | #ifndef QERROR_H |
| 13 | #define QERROR_H |
| 14 | |
| 15 | #include "qdict.h" |
| 16 | #include "qstring.h" |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 17 | #include "qemu-error.h" |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 18 | #include <stdarg.h> |
| 19 | |
| 20 | typedef struct QErrorStringTable { |
| 21 | const char *desc; |
| 22 | const char *error_fmt; |
| 23 | } QErrorStringTable; |
| 24 | |
| 25 | typedef struct QError { |
| 26 | QObject_HEAD; |
| 27 | QDict *error; |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 28 | Location loc; |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 29 | int linenr; |
| 30 | const char *file; |
| 31 | const char *func; |
| 32 | const QErrorStringTable *entry; |
| 33 | } QError; |
| 34 | |
| 35 | QError *qerror_new(void); |
| 36 | QError *qerror_from_info(const char *file, int linenr, const char *func, |
| 37 | const char *fmt, va_list *va); |
| 38 | QString *qerror_human(const QError *qerror); |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 39 | void qerror_print(QError *qerror); |
| 40 | void qerror_report_internal(const char *file, int linenr, const char *func, |
| 41 | const char *fmt, ...) |
| 42 | __attribute__ ((format(printf, 4, 5))); |
| 43 | #define qerror_report(fmt, ...) \ |
| 44 | qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__) |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 45 | QError *qobject_to_qerror(const QObject *obj); |
| 46 | |
| 47 | /* |
| 48 | * QError class list |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 49 | * Please keep the definitions in alphabetical order. |
| 50 | * Use "grep '^#define QERR_' qerror.h | sort -c" to check. |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 51 | */ |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 52 | #define QERR_BAD_BUS_FOR_DEVICE \ |
| 53 | "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }" |
| 54 | |
| 55 | #define QERR_BUS_NOT_FOUND \ |
| 56 | "{ 'class': 'BusNotFound', 'data': { 'bus': %s } }" |
| 57 | |
| 58 | #define QERR_BUS_NO_HOTPLUG \ |
| 59 | "{ 'class': 'BusNoHotplug', 'data': { 'bus': %s } }" |
| 60 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 61 | #define QERR_COMMAND_NOT_FOUND \ |
| 62 | "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }" |
| 63 | |
| 64 | #define QERR_DEVICE_ENCRYPTED \ |
| 65 | "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" |
| 66 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 67 | #define QERR_DEVICE_INIT_FAILED \ |
| 68 | "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }" |
| 69 | |
| 70 | #define QERR_DEVICE_IN_USE \ |
| 71 | "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }" |
| 72 | |
| 73 | #define QERR_DEVICE_LOCKED \ |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 74 | "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }" |
| 75 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 76 | #define QERR_DEVICE_MULTIPLE_BUSSES \ |
| 77 | "{ 'class': 'DeviceMultipleBusses', 'data': { 'device': %s } }" |
| 78 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 79 | #define QERR_DEVICE_NOT_ACTIVE \ |
| 80 | "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }" |
| 81 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 82 | #define QERR_DEVICE_NOT_ENCRYPTED \ |
| 83 | "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" |
| 84 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 85 | #define QERR_DEVICE_NOT_FOUND \ |
| 86 | "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }" |
| 87 | |
| 88 | #define QERR_DEVICE_NOT_REMOVABLE \ |
| 89 | "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }" |
| 90 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 91 | #define QERR_DEVICE_NO_BUS \ |
| 92 | "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }" |
| 93 | |
| 94 | #define QERR_DUPLICATE_ID \ |
| 95 | "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }" |
| 96 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 97 | #define QERR_FD_NOT_FOUND \ |
| 98 | "{ 'class': 'FdNotFound', 'data': { 'name': %s } }" |
| 99 | |
| 100 | #define QERR_FD_NOT_SUPPLIED \ |
| 101 | "{ 'class': 'FdNotSupplied', 'data': {} }" |
| 102 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 103 | #define QERR_INVALID_BLOCK_FORMAT \ |
| 104 | "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" |
| 105 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 106 | #define QERR_INVALID_PARAMETER \ |
| 107 | "{ 'class': 'InvalidParameter', 'data': { 'name': %s } }" |
| 108 | |
| 109 | #define QERR_INVALID_PARAMETER_TYPE \ |
| 110 | "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }" |
| 111 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 112 | #define QERR_INVALID_PARAMETER_VALUE \ |
| 113 | "{ 'class': 'InvalidParameterValue', 'data': { 'name': %s, 'expected': %s } }" |
| 114 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 115 | #define QERR_INVALID_PASSWORD \ |
| 116 | "{ 'class': 'InvalidPassword', 'data': {} }" |
| 117 | |
| 118 | #define QERR_JSON_PARSING \ |
| 119 | "{ 'class': 'JSONParsing', 'data': {} }" |
| 120 | |
| 121 | #define QERR_KVM_MISSING_CAP \ |
| 122 | "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }" |
| 123 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 124 | #define QERR_MIGRATION_EXPECTED \ |
| 125 | "{ 'class': 'MigrationExpected', 'data': {} }" |
| 126 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 127 | #define QERR_MISSING_PARAMETER \ |
| 128 | "{ 'class': 'MissingParameter', 'data': { 'name': %s } }" |
| 129 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 130 | #define QERR_NO_BUS_FOR_DEVICE \ |
| 131 | "{ 'class': 'NoBusForDevice', 'data': { 'device': %s, 'bus': %s } }" |
| 132 | |
| 133 | #define QERR_OPEN_FILE_FAILED \ |
| 134 | "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }" |
| 135 | |
| 136 | #define QERR_PROPERTY_NOT_FOUND \ |
| 137 | "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }" |
| 138 | |
| 139 | #define QERR_PROPERTY_VALUE_BAD \ |
| 140 | "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 141 | |
| 142 | #define QERR_PROPERTY_VALUE_IN_USE \ |
| 143 | "{ 'class': 'PropertyValueInUse', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 144 | |
| 145 | #define QERR_PROPERTY_VALUE_NOT_FOUND \ |
| 146 | "{ 'class': 'PropertyValueNotFound', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 147 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 148 | #define QERR_QMP_BAD_INPUT_OBJECT \ |
| 149 | "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }" |
| 150 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 151 | #define QERR_QMP_BAD_INPUT_OBJECT_MEMBER \ |
| 152 | "{ 'class': 'QMPBadInputObjectMember', 'data': { 'member': %s, 'expected': %s } }" |
| 153 | |
| 154 | #define QERR_QMP_EXTRA_MEMBER \ |
| 155 | "{ 'class': 'QMPExtraInputObjectMember', 'data': { 'member': %s } }" |
| 156 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 157 | #define QERR_SET_PASSWD_FAILED \ |
| 158 | "{ 'class': 'SetPasswdFailed', 'data': {} }" |
| 159 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 160 | #define QERR_TOO_MANY_FILES \ |
| 161 | "{ 'class': 'TooManyFiles', 'data': {} }" |
| 162 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 163 | #define QERR_UNDEFINED_ERROR \ |
| 164 | "{ 'class': 'UndefinedError', 'data': {} }" |
| 165 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 166 | #define QERR_VNC_SERVER_FAILED \ |
| 167 | "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }" |
| 168 | |
| 169 | #endif /* QERROR_H */ |