Changeset 56118 in vbox for trunk/include/VBox/com
- Timestamp:
- May 27, 2015 7:49:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/errorprint.h
r45125 r56118 53 53 54 54 /** 55 * Extended macro that implements all the other CHECK_ERROR2XXX macros. 56 * 57 * Calls the method of the given interface and checks the return status code. 58 * If the status indicates failure, as much information as possible is reported 59 * about the error, including current source file and line. 60 * 61 * After reporting an error, the statement |stmtError| is executed. 62 * 63 * This macro family is intended for command line tools like VBoxManage, but 64 * could also be handy for debugging. 65 * 66 * @param type For defining @a hrc locally inside the the macro 67 * expansion, pass |HRESULT| otherwise |RT_NOTHING|. 68 * @param hrc Name of the HRESULT variable to assign the result of the 69 * method call to. 70 * @param iface The interface pointer (can be a smart pointer object). 71 * @param method The method to invoke together with the parameters. 72 * @param stmtError Statement to be executed after reporting failures. This 73 * can be a |break| or |return| statement, if so desired. 74 * 75 * @remarks Unlike CHECK_ERROR, CHECK_ERROR_RET and family, this macro family 76 * does not presuppose a |rc| variable but instead either let the user 77 * specify the variable to use or employs a local variable |hrcCheck| 78 * within its own scope. 79 * 80 * @sa CHECK_ERROR2, CHECK_ERROR2I, CHECK_ERROR2_STMT, CHECK_ERROR2I_STMT, 81 * CHECK_ERROR2_BREAK, CHECK_ERROR2I_BREAK, CHECK_ERROR2_RET, 82 * CHECK_ERROR2I_RET 83 */ 84 #define CHECK_ERROR2_EX(type, hrc, iface, method, stmtError) \ 85 if (1) { \ 86 type hrc = iface->method; \ 87 if (SUCCEEDED(hrc)) \ 88 { /*likely*/ } \ 89 else \ 90 { \ 91 com::GlueHandleComError(iface, #method, (hrc), __FILE__, __LINE__); \ 92 stmtError; \ 93 } \ 94 } else do { /* nothing */ } while (0) 95 96 97 /** 55 98 * Calls the given method of the given interface and then checks if the return 56 99 * value (COM result code) indicates a failure. If so, prints the failed … … 61 104 * Used by command line tools or for debugging and assumes the |HRESULT rc| 62 105 * variable is accessible for assigning in the current scope. 106 * @sa CHECK_ERROR2, CHECK_ERROR2I 63 107 */ 64 108 #define CHECK_ERROR(iface, method) \ … … 68 112 com::GlueHandleComError(iface, #method, rc, __FILE__, __LINE__); \ 69 113 } while (0) 114 /** 115 * Simplified version of CHECK_ERROR2_EX, no error statement or type necessary. 116 * 117 * @param hrc Name of the HRESULT variable to assign the result of the 118 * method call to. 119 * @param iface The interface pointer (can be a smart pointer object). 120 * @param method The method to invoke together with the parameters. 121 * @sa CHECK_ERROR2I, CHECK_ERROR2_EX 122 */ 123 #define CHECK_ERROR2(hrc, iface, method) CHECK_ERROR2_EX(RT_NOTHING, hrc, iface, method, (void)1) 124 /** 125 * Simplified version of CHECK_ERROR2_EX that uses an internal variable 126 * |hrcCheck| for holding the result and have no error statement. 127 * 128 * @param iface The interface pointer (can be a smart pointer object). 129 * @param method The method to invoke together with the parameters. 130 * @sa CHECK_ERROR2, CHECK_ERROR2_EX 131 */ 132 #define CHECK_ERROR2I(iface, method) CHECK_ERROR2_EX(HRESULT, hrcCheck, iface, method, (void)1) 133 70 134 71 135 /** 72 136 * Same as CHECK_ERROR except that it also executes the statement |stmt| on 73 137 * failure. 138 * @sa CHECK_ERROR2_STMT, CHECK_ERROR2I_STMT 74 139 */ 75 140 #define CHECK_ERROR_STMT(iface, method, stmt) \ … … 82 147 } \ 83 148 } while (0) 84 85 /** 86 * Same as CHECK_ERROR_STMT except that it uses an internal variable |hrcCheck| 87 * for holding the result. 88 */ 89 #define CHECK_ERROR2_STMT(iface, method, stmt) \ 90 do { \ 91 HRESULT hrcCheck = iface->method; \ 92 if (FAILED(hrcCheck)) \ 93 { \ 94 com::GlueHandleComError(iface, #method, hrcCheck, __FILE__, __LINE__); \ 95 stmt; \ 96 } \ 97 } while (0) 149 /** 150 * Simplified version of CHECK_ERROR2_EX (no @a hrc type). 151 * 152 * @param hrc Name of the HRESULT variable to assign the result of the 153 * method call to. 154 * @param iface The interface pointer (can be a smart pointer object). 155 * @param method The method to invoke together with the parameters. 156 * @param stmt Statement to be executed after reporting failures. 157 * @sa CHECK_ERROR2I_STMT, CHECK_ERROR2_EX 158 */ 159 #define CHECK_ERROR2_STMT(hrc, iface, method, stmt) CHECK_ERROR2_EX(RT_NOTHING, hrc, iface, method, stmt) 160 /** 161 * Simplified version of CHECK_ERROR2_EX that uses an internal variable 162 * |hrcCheck| for holding the result. 163 * 164 * @param iface The interface pointer (can be a smart pointer object). 165 * @param method The method to invoke together with the parameters. 166 * @param stmt Statement to be executed after reporting failures. 167 * @sa CHECK_ERROR2_STMT, CHECK_ERROR2_EX 168 */ 169 #define CHECK_ERROR2I_STMT(iface, method, stmt) CHECK_ERROR2_EX(HRESULT, hrcCheck, iface, method, stmt) 98 170 99 171 … … 101 173 * Does the same as CHECK_ERROR(), but executes the |break| statement on 102 174 * failure. 175 * @sa CHECK_ERROR2_BREAK, CHECK_ERROR2I_BREAK 103 176 */ 104 177 #ifdef __GNUC__ … … 126 199 else do {} while (0) 127 200 #endif 128 129 /** 130 * Does the same as CHECK_ERROR(), but executes the |return ret| statement on 131 * failure. 201 /** 202 * Simplified version of CHECK_ERROR2_EX that executes the |break| statement 203 * after error reporting (no @a hrc type). 204 * 205 * @param hrc The result variable (type HRESULT). 206 * @param iface The interface pointer (can be a smart pointer object). 207 * @param method The method to invoke together with the parameters. 208 * @sa CHECK_ERROR2I_BREAK, CHECK_ERROR2_EX 209 */ 210 #define CHECK_ERROR2_BREAK(hrc, iface, method) CHECK_ERROR2_EX(RT_NOTHING, hrc, iface, method, break) 211 /** 212 * Simplified version of CHECK_ERROR2_EX that executes the |break| statement 213 * after error reporting and that uses an internal variable |hrcCheck| for 214 * holding the result. 215 * 216 * @param iface The interface pointer (can be a smart pointer object). 217 * @param method The method to invoke together with the parameters. 218 * @sa CHECK_ERROR2_BREAK, CHECK_ERROR2_EX 219 */ 220 #define CHECK_ERROR2I_BREAK(iface, method) CHECK_ERROR2_EX(HRESULT, hrcCheck, iface, method, break) 221 222 223 /** 224 * Does the same as CHECK_ERROR(), but executes the |return ret| statement on 225 * failure. 226 * @sa CHECK_ERROR2_RET, CHECK_ERROR2I_RET 132 227 */ 133 228 #define CHECK_ERROR_RET(iface, method, ret) \ … … 140 235 } \ 141 236 } while (0) 142 143 /** 144 * Does the same as CHECK_ERROR(), but returns @a ret on failure. 145 * 146 * Unlike CHECK_ERROR and CHECK_ERROR_RET, this macro does not presuppose a 147 * |rc| variable but instead employs a local variable |hrcCheck| in its own 148 * scope. This |hrcCheck| variable can be referenced by the @a rcRet 149 * parameter. 237 /** 238 * Simplified version of CHECK_ERROR2_EX that executes the |return (rcRet)| 239 * statement after error reporting. 240 * 241 * @param iface The interface pointer (can be a smart pointer object). 242 * @param method The method to invoke together with the parameters. 243 * @param rcRet What to return on failure. 244 */ 245 #define CHECK_ERROR2_RET(hrc, iface, method, rcRet) CHECK_ERROR2_EX(RT_NOTHING, hrc, iface, method, return (rcRet)) 246 /** 247 * Simplified version of CHECK_ERROR2_EX that executes the |return (rcRet)| 248 * statement after error reporting and that uses an internal variable |hrcCheck| 249 * for holding the result. 150 250 * 151 251 * @param iface The interface pointer (can be a smart pointer object). … … 154 254 * the status code of the method call. 155 255 */ 156 #define CHECK_ERROR2_RET(iface, method, rcRet) \ 157 do { \ 158 HRESULT hrcCheck = iface->method; \ 159 if (FAILED(hrcCheck)) \ 160 { \ 161 com::GlueHandleComError(iface, #method, hrcCheck, __FILE__, __LINE__); \ 162 return (rcRet); \ 163 } \ 164 } while (0) 256 #define CHECK_ERROR2I_RET(iface, method, rcRet) CHECK_ERROR2_EX(HRESULT, hrcCheck, iface, method, return (rcRet)) 165 257 166 258 … … 168 260 * Check the progress object for an error and if there is one print out the 169 261 * extended error information. 262 * @remarks Requires HRESULT variable named @a rc. 170 263 */ 171 264 #define CHECK_PROGRESS_ERROR(progress, msg) \ … … 173 266 LONG iRc; \ 174 267 rc = progress->COMGETTER(ResultCode)(&iRc); \ 175 if (FAILED( iRc)) \176 { \ 177 rc = iRc; \268 if (FAILED(rc) || FAILED(iRc)) \ 269 { \ 270 if (SUCCEEDED(rc)) rc = iRc; else iRc = rc; \ 178 271 RTMsgError msg; \ 179 272 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, iRc, __FILE__, __LINE__); \ … … 182 275 183 276 /** 184 * Does the same as CHECK_PROGRESS_ERROR(), but executes the |break| statement 185 * on failure. 277 * Does the same as CHECK_PROGRESS_ERROR(), but executes the |break| statement 278 * on failure. 279 * @remarks Requires HRESULT variable named @a rc. 186 280 */ 187 281 #ifdef __GNUC__ … … 191 285 LONG iRc; \ 192 286 rc = progress->COMGETTER(ResultCode)(&iRc); \ 193 if (FAILED( iRc)) \194 { \ 195 rc = iRc; \287 if (FAILED(rc) || FAILED(iRc)) \ 288 { \ 289 if (SUCCEEDED(rc)) rc = iRc; else iRc = rc; \ 196 290 RTMsgError msg; \ 197 291 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, iRc, __FILE__, __LINE__); \ … … 200 294 }) 201 295 #else 202 # 296 #define CHECK_PROGRESS_ERROR_BREAK(progress, msg) \ 203 297 if (1) \ 204 298 { \ 205 299 LONG iRc; \ 206 300 rc = progress->COMGETTER(ResultCode)(&iRc); \ 207 if (FAILED( iRc)) \208 { \ 209 rc = iRc; \301 if (FAILED(rc) || FAILED(iRc)) \ 302 { \ 303 if (SUCCEEDED(rc)) rc = iRc; else iRc = rc; \ 210 304 RTMsgError msg; \ 211 305 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, iRc, __FILE__, __LINE__); \ … … 217 311 218 312 /** 219 * 220 * 313 * Does the same as CHECK_PROGRESS_ERROR(), but executes the |return ret| 314 * statement on failure. 221 315 */ 222 316 #define CHECK_PROGRESS_ERROR_RET(progress, msg, ret) \ 223 317 do { \ 224 318 LONG iRc; \ 225 progress->COMGETTER(ResultCode)(&iRc); \ 226 if (FAILED(iRc)) \ 319 HRESULT hrcCheck = progress->COMGETTER(ResultCode)(&iRc); \ 320 if (SUCCEEDED(hrcCheck) && SUCCEEDED(iRc)) \ 321 { /* likely */ } \ 322 else \ 227 323 { \ 228 324 RTMsgError msg; \ 229 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, iRc, __FILE__, __LINE__); \ 325 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, \ 326 SUCCEEDED(hrcCheck) ? iRc : hrcCheck, __FILE__, __LINE__); \ 230 327 return (ret); \ 231 328 } \ … … 248 345 249 346 /** 250 * Does the same as ASSERT(), but executes the |return ret| statement if the 251 * expression to assert is false; 347 * Does the same as ASSERT(), but executes the |return ret| statement if the 348 * expression to assert is false; 349 * @remarks WARNING! @a expr is evalutated TWICE! 252 350 */ 253 351 #define ASSERT_RET(expr, ret) \ … … 255 353 256 354 /** 257 * Does the same as ASSERT(), but executes the |break| statement if the 258 * expression to assert is false; 355 * Does the same as ASSERT(), but executes the |break| statement if the 356 * expression to assert is false; 357 * @remarks WARNING! @a expr is evalutated TWICE! 259 358 */ 260 359 #define ASSERT_BREAK(expr, ret) \
Note:
See TracChangeset
for help on using the changeset viewer.