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, |
David 'Digit' Turner | 47dc1f4 | 2011-05-09 17:10:43 +0200 | [diff] [blame] | 37 | const char *fmt, va_list *va) GCC_FMT_ATTR(4, 0); |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 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, |
David 'Digit' Turner | 47dc1f4 | 2011-05-09 17:10:43 +0200 | [diff] [blame] | 41 | const char *fmt, ...) GCC_FMT_ATTR(4, 5); |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 42 | #define qerror_report(fmt, ...) \ |
| 43 | qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__) |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 44 | QError *qobject_to_qerror(const QObject *obj); |
| 45 | |
| 46 | /* |
| 47 | * QError class list |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 48 | * Please keep the definitions in alphabetical order. |
| 49 | * Use "grep '^#define QERR_' qerror.h | sort -c" to check. |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 50 | */ |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 51 | #define QERR_BAD_BUS_FOR_DEVICE \ |
| 52 | "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }" |
| 53 | |
| 54 | #define QERR_BUS_NOT_FOUND \ |
| 55 | "{ 'class': 'BusNotFound', 'data': { 'bus': %s } }" |
| 56 | |
| 57 | #define QERR_BUS_NO_HOTPLUG \ |
| 58 | "{ 'class': 'BusNoHotplug', 'data': { 'bus': %s } }" |
| 59 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 60 | #define QERR_COMMAND_NOT_FOUND \ |
| 61 | "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }" |
| 62 | |
| 63 | #define QERR_DEVICE_ENCRYPTED \ |
| 64 | "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" |
| 65 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 66 | #define QERR_DEVICE_INIT_FAILED \ |
| 67 | "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }" |
| 68 | |
| 69 | #define QERR_DEVICE_IN_USE \ |
| 70 | "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }" |
| 71 | |
| 72 | #define QERR_DEVICE_LOCKED \ |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 73 | "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }" |
| 74 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 75 | #define QERR_DEVICE_MULTIPLE_BUSSES \ |
| 76 | "{ 'class': 'DeviceMultipleBusses', 'data': { 'device': %s } }" |
| 77 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 78 | #define QERR_DEVICE_NOT_ACTIVE \ |
| 79 | "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }" |
| 80 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 81 | #define QERR_DEVICE_NOT_ENCRYPTED \ |
| 82 | "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" |
| 83 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 84 | #define QERR_DEVICE_NOT_FOUND \ |
| 85 | "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }" |
| 86 | |
| 87 | #define QERR_DEVICE_NOT_REMOVABLE \ |
| 88 | "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }" |
| 89 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 90 | #define QERR_DEVICE_NO_BUS \ |
| 91 | "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }" |
| 92 | |
David 'Digit' Turner | 47dc1f4 | 2011-05-09 17:10:43 +0200 | [diff] [blame] | 93 | #define QERR_DEVICE_NO_HOTPLUG \ |
| 94 | "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }" |
| 95 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 96 | #define QERR_DUPLICATE_ID \ |
| 97 | "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }" |
| 98 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 99 | #define QERR_FD_NOT_FOUND \ |
| 100 | "{ 'class': 'FdNotFound', 'data': { 'name': %s } }" |
| 101 | |
| 102 | #define QERR_FD_NOT_SUPPLIED \ |
| 103 | "{ 'class': 'FdNotSupplied', 'data': {} }" |
| 104 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 105 | #define QERR_INVALID_BLOCK_FORMAT \ |
| 106 | "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" |
| 107 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 108 | #define QERR_INVALID_PARAMETER \ |
| 109 | "{ 'class': 'InvalidParameter', 'data': { 'name': %s } }" |
| 110 | |
| 111 | #define QERR_INVALID_PARAMETER_TYPE \ |
| 112 | "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }" |
| 113 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 114 | #define QERR_INVALID_PARAMETER_VALUE \ |
| 115 | "{ 'class': 'InvalidParameterValue', 'data': { 'name': %s, 'expected': %s } }" |
| 116 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 117 | #define QERR_INVALID_PASSWORD \ |
| 118 | "{ 'class': 'InvalidPassword', 'data': {} }" |
| 119 | |
| 120 | #define QERR_JSON_PARSING \ |
| 121 | "{ 'class': 'JSONParsing', 'data': {} }" |
| 122 | |
| 123 | #define QERR_KVM_MISSING_CAP \ |
| 124 | "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }" |
| 125 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 126 | #define QERR_MIGRATION_EXPECTED \ |
| 127 | "{ 'class': 'MigrationExpected', 'data': {} }" |
| 128 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 129 | #define QERR_MISSING_PARAMETER \ |
| 130 | "{ 'class': 'MissingParameter', 'data': { 'name': %s } }" |
| 131 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 132 | #define QERR_NO_BUS_FOR_DEVICE \ |
| 133 | "{ 'class': 'NoBusForDevice', 'data': { 'device': %s, 'bus': %s } }" |
| 134 | |
| 135 | #define QERR_OPEN_FILE_FAILED \ |
| 136 | "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }" |
| 137 | |
| 138 | #define QERR_PROPERTY_NOT_FOUND \ |
| 139 | "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }" |
| 140 | |
| 141 | #define QERR_PROPERTY_VALUE_BAD \ |
| 142 | "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 143 | |
| 144 | #define QERR_PROPERTY_VALUE_IN_USE \ |
| 145 | "{ 'class': 'PropertyValueInUse', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 146 | |
| 147 | #define QERR_PROPERTY_VALUE_NOT_FOUND \ |
| 148 | "{ 'class': 'PropertyValueNotFound', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 149 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 150 | #define QERR_QMP_BAD_INPUT_OBJECT \ |
| 151 | "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }" |
| 152 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 153 | #define QERR_QMP_BAD_INPUT_OBJECT_MEMBER \ |
| 154 | "{ 'class': 'QMPBadInputObjectMember', 'data': { 'member': %s, 'expected': %s } }" |
| 155 | |
| 156 | #define QERR_QMP_EXTRA_MEMBER \ |
| 157 | "{ 'class': 'QMPExtraInputObjectMember', 'data': { 'member': %s } }" |
| 158 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 159 | #define QERR_SET_PASSWD_FAILED \ |
| 160 | "{ 'class': 'SetPasswdFailed', 'data': {} }" |
| 161 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 162 | #define QERR_TOO_MANY_FILES \ |
| 163 | "{ 'class': 'TooManyFiles', 'data': {} }" |
| 164 | |
David Turner | fd4c007 | 2010-09-09 21:23:36 +0200 | [diff] [blame] | 165 | #define QERR_UNDEFINED_ERROR \ |
| 166 | "{ 'class': 'UndefinedError', 'data': {} }" |
| 167 | |
David 'Digit' Turner | 47dc1f4 | 2011-05-09 17:10:43 +0200 | [diff] [blame] | 168 | #define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \ |
| 169 | "{ 'class': 'UnknownBlockFormatFeature', 'data': { 'device': %s, 'format': %s, 'feature': %s } }" |
| 170 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 171 | #define QERR_VNC_SERVER_FAILED \ |
| 172 | "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }" |
| 173 | |
David 'Digit' Turner | 47dc1f4 | 2011-05-09 17:10:43 +0200 | [diff] [blame] | 174 | #define QERR_FEATURE_DISABLED \ |
| 175 | "{ 'class': 'FeatureDisabled', 'data': { 'name': %s } }" |
| 176 | |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 177 | #endif /* QERROR_H */ |