Changeset 16530 in vbox for trunk/include/VBox/com
- Timestamp:
- Feb 5, 2009 4:08:49 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 42461
- Location:
- trunk/include/VBox/com
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/assert.h
r13856 r16530 137 137 if (!SUCCEEDED (rc)) { throw rc; } else do {} while (0) 138 138 139 /*140 * A section of helpful macros for error output141 */142 143 /**144 * Prints a line describing the given COM result code.145 * Used by command line tools or for debugging.146 */147 #define PRINT_RC_MESSAGE(rc) \148 do { \149 RTPrintf ("[!] Primary RC = %Rhra\n", rc); \150 Log (("[!] Primary RC = %Rhra\n", rc)); \151 } while (0)152 153 /**154 * Prints the extended error information.155 * Used by command line tools or for debugging.156 *157 * @param info com::ErrorInfo instance158 */159 #define PRINT_ERROR_INFO(info) \160 do { \161 RTPrintf ("[!] Full error info present: %RTbool, basic error info present: %RTbool\n", \162 info.isFullAvailable(), info.isBasicAvailable()); \163 Log (("[!] Full error info present: %RTbool, basic error info present: %RTbool\n", \164 info.isFullAvailable(), info.isBasicAvailable())); \165 if (info.isFullAvailable() || info.isBasicAvailable()) { \166 RTPrintf ("[!] Result Code = %Rhra\n", info.getResultCode()); \167 RTPrintf ("[!] Text = %ls\n", info.getText().raw()); \168 RTPrintf ("[!] Component = %ls, Interface: %ls, {%RTuuid}\n", \169 info.getComponent().raw(), info.getInterfaceName().raw(), \170 info.getInterfaceID().raw()); \171 RTPrintf ("[!] Callee = %ls, {%RTuuid}\n", \172 info.getCalleeName().raw(), info.getCalleeIID().raw()); \173 Log (("[!] Result Code = %Rhra\n", info.getResultCode())); \174 Log (("[!] Text = %ls\n", info.getText().raw())); \175 Log (("[!] Component = %ls, Interface: %ls, {%RTuuid}\n", \176 info.getComponent().raw(), info.getInterfaceName().raw(), \177 info.getInterfaceID().raw())); \178 Log (("[!] Callee = %ls, {%RTuuid}\n", \179 info.getCalleeName().raw(), info.getCalleeIID().raw())); \180 } \181 } while (0)182 183 /**184 * Calls the given interface method and then checks if the return value185 * (COM result code) indicates a failure. If so, prints the failed186 * function/line/file and the description of the result code.187 *188 * Used by command line tools or for debugging and assumes the |HRESULT rc|189 * variable is accessible for assigning in the current scope.190 */191 #define CHECK_RC(method) \192 do { \193 rc = method; \194 if (FAILED (rc)) { \195 RTPrintf ("[!] FAILED calling " #method " at line %d!\n", __LINE__); \196 Log (("[!] FAILED calling " #method " at line %d!\n", __LINE__)); \197 PRINT_RC_MESSAGE(rc); \198 } \199 } while (0)200 201 /**202 * Does the same as CHECK_RC(), but executes the |return rc| statement on203 * failure.204 */205 #define CHECK_RC_RET(method) \206 do { CHECK_RC (method); if (FAILED (rc)) return rc; } while (0)207 208 /**209 * Does the same as CHECK_RC(), but executes the |break| statement on210 * failure.211 */212 #define CHECK_RC_BREAK(method) \213 if (1) { CHECK_RC (method); if (FAILED (rc)) break; } else do {} while (0)214 215 /**216 * Calls the given method of the given interface and then checks if the return217 * value (COM result code) indicates a failure. If so, prints the failed218 * function/line/file, the description of the result code and attempts to219 * query the extended error information on the current thread (using220 * com::ErrorInfo) if the interface reports that it supports error information.221 *222 * Used by command line tools or for debugging and assumes the |HRESULT rc|223 * variable is accessible for assigning in the current scope.224 */225 #define CHECK_ERROR(iface, method) \226 do \227 { \228 CHECK_RC(iface->method); \229 if (FAILED(rc)) { \230 com::ErrorInfo info (iface); \231 PRINT_ERROR_INFO (info); \232 } \233 } while (0)234 235 /**236 * Does the same as CHECK_ERROR(), but executes the |return ret| statement on237 * failure.238 */239 #define CHECK_ERROR_RET(iface, method, ret) \240 do { CHECK_ERROR (iface, method); if (FAILED (rc)) return (ret); } while (0)241 242 /**243 * Does the same as CHECK_ERROR(), but executes the |break| statement on244 * failure.245 */246 #if defined(__GNUC__)247 #define CHECK_ERROR_BREAK(iface, method) \248 ({ CHECK_ERROR (iface, method); if (FAILED (rc)) break; })249 #else250 #define CHECK_ERROR_BREAK(iface, method) \251 if (1) { CHECK_ERROR (iface, method); if (FAILED (rc)) break; } else do {} while (0)252 #endif253 254 #define CHECK_ERROR_NOCALL() \255 do { \256 com::ErrorInfo info; \257 PRINT_ERROR_INFO (info); \258 } while (0)259 260 /**261 * Does the same as CHECK_ERROR(), but doesn't need the interface pointer262 * because doesn't do a check whether the interface supports error info or not.263 */264 #define CHECK_ERROR_NI(method) \265 do { \266 CHECK_RC (method); \267 if (FAILED (rc)) { \268 com::ErrorInfo info; \269 PRINT_ERROR_INFO (info); \270 } \271 } while (0)272 273 /**274 * Does the same as CHECK_ERROR_NI(), but executes the |return rc| statement275 * on failure.276 */277 #define CHECK_ERROR_NI_RET(method) \278 do { CHECK_ERROR_NI (method); if (FAILED (rc)) return rc; } while (0)279 280 /**281 * Does the same as CHECK_ERROR_NI(), but executes the |break| statement282 * on failure.283 */284 #define CHECK_ERROR_NI_BREAK(method) \285 if (1) { CHECK_ERROR_NI (method); if (FAILED (rc)) break; } else do {} while (0)286 287 288 /**289 * Asserts the given expression is true. When the expression is false, prints290 * a line containing the failed function/line/file; otherwise does nothing.291 */292 #define ASSERT(expr) \293 do { \294 if (!(expr)) \295 { \296 RTPrintf ("[!] ASSERTION FAILED at line %d: %s\n", __LINE__, #expr); \297 Log (("[!] ASSERTION FAILED at line %d: %s\n", __LINE__, #expr)); \298 } \299 } while (0)300 301 /**302 * Does the same as ASSERT(), but executes the |return ret| statement if the303 * expression to assert is false.304 */305 #define ASSERT_RET(expr, ret) \306 do { ASSERT (expr); if (!(expr)) return (ret); } while (0)307 308 /**309 * Does the same as ASSERT(), but executes the |break| statement if the310 * expression to assert is false.311 */312 #define ASSERT_BREAK(expr) \313 if (1) { ASSERT (expr); if (!(expr)) break; } else do {} while (0)314 315 139 316 140 #endif -
trunk/include/VBox/com/errorprint_legacy.h
r16526 r16530 1 1 /** @file 2 2 * MS COM / XPCOM Abstraction Layer: 3 * Assertion macros for COM/XPCOM 3 * Legacy error printing macros for COM/XPCOM (used with testcases). 4 * 5 * NOTE: to lighten the load on the compilers, please use the shared 6 * functions in errorprint2.h for new code. 4 7 */ 5 8 6 9 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.10 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 11 * 9 12 * This file is part of VirtualBox Open Source Edition (OSE), as … … 29 32 */ 30 33 31 #ifndef ___VBox_com_ assert_h32 #define ___VBox_com_ assert_h34 #ifndef ___VBox_com_errorprint_legacy_h 35 #define ___VBox_com_errorprint_legacy_h 33 36 34 37 #include <iprt/assert.h> 35 36 /**37 * Asserts that the COM result code is succeeded in strict builds.38 * In non-strict builds the result code will be NOREF'ed to kill compiler warnings.39 *40 * @param rc COM result code41 */42 #define AssertComRC(rc) \43 do { AssertMsg (SUCCEEDED (rc), ("COM RC = %Rhrc (0x%08X)\n", rc, rc)); NOREF (rc); } while (0)44 45 /**46 * A special version of AssertComRC that returns the given expression47 * if the result code is failed.48 *49 * @param rc COM result code50 * @param ret the expression to return51 */52 #define AssertComRCReturn(rc, ret) \53 AssertMsgReturn (SUCCEEDED (rc), ("COM RC = %Rhrc (0x%08X)\n", rc, rc), ret)54 55 /**56 * A special version of AssertComRC that returns the given result code57 * if it is failed.58 *59 * @param rc COM result code60 * @param ret the expression to return61 */62 #define AssertComRCReturnRC(rc) \63 AssertMsgReturn (SUCCEEDED (rc), ("COM RC = %Rhrc (0x%08X)\n", rc, rc), rc)64 65 /**66 * A special version of AssertComRC that returns if the result code is failed.67 *68 * @param rc COM result code69 * @param ret the expression to return70 */71 #define AssertComRCReturnVoid(rc) \72 AssertMsgReturnVoid (SUCCEEDED (rc), ("COM RC = %Rhrc (0x%08X)\n", rc, rc))73 74 /**75 * A special version of AssertComRC that evaluates the given expression and76 * breaks if the result code is failed.77 *78 * @param rc COM result code79 * @param eval the expression to evaluate80 */81 #define AssertComRCBreak(rc, eval) \82 if (!SUCCEEDED (rc)) { AssertComRC (rc); eval; break; } else do {} while (0)83 84 /**85 * A special version of AssertComRC that evaluates the given expression and86 * throws it if the result code is failed.87 *88 * @param rc COM result code89 * @param eval the expression to throw90 */91 #define AssertComRCThrow(rc, eval) \92 if (!SUCCEEDED (rc)) { AssertComRC (rc); throw (eval); } else do {} while (0)93 94 /**95 * A special version of AssertComRC that just breaks if the result code is96 * failed.97 *98 * @param rc COM result code99 */100 #define AssertComRCBreakRC(rc) \101 if (!SUCCEEDED (rc)) { AssertComRC (rc); break; } else do {} while (0)102 103 /**104 * A special version of AssertComRC that just throws @a rc if the result code is105 * failed.106 *107 * @param rc COM result code108 */109 #define AssertComRCThrowRC(rc) \110 if (!SUCCEEDED (rc)) { AssertComRC (rc); throw rc; } else do {} while (0)111 112 /**113 * Checks whether the given COM result code is successful.114 * If not, executes the return statement with this result code.115 *116 * @param rc COM result code117 */118 #define CheckComRCReturnRC(rc) \119 if (!SUCCEEDED (rc)) { return (rc); } else do {} while (0)120 121 /**122 * Checks whether the given COM result code is successful.123 * If not, executes the break statement.124 *125 * @param rc COM result code126 */127 #define CheckComRCBreakRC(rc) \128 if (!SUCCEEDED (rc)) { break; } else do {} while (0)129 130 /**131 * Checks whether the given COM result code is successful.132 * If not, throws the given COM result.133 *134 * @param rc COM result code135 */136 #define CheckComRCThrowRC(rc) \137 if (!SUCCEEDED (rc)) { throw rc; } else do {} while (0)138 38 139 39 /*
Note:
See TracChangeset
for help on using the changeset viewer.