VirtualBox

source: vbox/trunk/include/VBox/com/errorprint.h@ 32781

Last change on this file since 32781 was 30104, checked in by vboxsync, 14 years ago

com/errorprint.h: Shot at quiteing CHECK_ERROR_BREAK.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer:
3 * Error printing macros using shared functions defined in shared glue code.
4 * Use these CHECK_* macros for efficient error checking around calling COM methods.
5 */
6
7/*
8 * Copyright (C) 2009 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * The contents of this file may alternatively be used under the terms
19 * of the Common Development and Distribution License Version 1.0
20 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21 * VirtualBox OSE distribution, in which case the provisions of the
22 * CDDL are applicable instead of those of the GPL.
23 *
24 * You may elect to license modified versions of this file under the
25 * terms and conditions of either the GPL or the CDDL or both.
26 */
27
28#ifndef ___VBox_com_errorprint_h
29#define ___VBox_com_errorprint_h
30
31namespace com
32{
33
34// shared prototypes; these are defined in shared glue code and are
35// compiled only once for all front-ends
36void GluePrintErrorInfo(com::ErrorInfo &info);
37void GluePrintErrorContext(const char *pcszContext, const char *pcszSourceFile, uint32_t ulLine);
38void GluePrintRCMessage(HRESULT rc);
39void GlueHandleComError(ComPtr<IUnknown> iface, const char *pcszContext, HRESULT rc, const char *pcszSourceFile, uint32_t ulLine);
40
41/**
42 * Calls the given method of the given interface and then checks if the return
43 * value (COM result code) indicates a failure. If so, prints the failed
44 * function/line/file, the description of the result code and attempts to
45 * query the extended error information on the current thread (using
46 * com::ErrorInfo) if the interface reports that it supports error information.
47 *
48 * Used by command line tools or for debugging and assumes the |HRESULT rc|
49 * variable is accessible for assigning in the current scope.
50 */
51#define CHECK_ERROR(iface, method) \
52 do { \
53 rc = iface->method; \
54 if (FAILED(rc)) \
55 com::GlueHandleComError(iface, #method, rc, __FILE__, __LINE__); \
56 } while (0)
57
58/**
59 * Does the same as CHECK_ERROR(), but executes the |break| statement on
60 * failure.
61 */
62#ifdef __GNUC__
63# define CHECK_ERROR_BREAK(iface, method) \
64 __extension__ \
65 ({ \
66 rc = iface->method; \
67 if (FAILED(rc)) \
68 { \
69 com::GlueHandleComError(iface, #method, rc, __FILE__, __LINE__); \
70 break; \
71 } \
72 })
73#else
74# define CHECK_ERROR_BREAK(iface, method) \
75 if (1) \
76 { \
77 rc = iface->method; \
78 if (FAILED(rc)) \
79 { \
80 com::GlueHandleComError(iface, #method, rc, __FILE__, __LINE__); \
81 break; \
82 } \
83 } \
84 else do {} while (0)
85#endif
86
87/**
88 * Does the same as CHECK_ERROR(), but executes the |return ret| statement on
89 * failure.
90 */
91#define CHECK_ERROR_RET(iface, method, ret) \
92 do { \
93 rc = iface->method; \
94 if (FAILED(rc)) \
95 { \
96 com::GlueHandleComError(iface, #method, rc, __FILE__, __LINE__); \
97 return (ret); \
98 } \
99 } while (0)
100
101/**
102 * Asserts the given expression is true. When the expression is false, prints
103 * a line containing the failed function/line/file; otherwise does nothing.
104 */
105#define ASSERT(expr) \
106 do { \
107 if (!(expr)) \
108 { \
109 RTPrintf ("[!] ASSERTION FAILED at line %d: %s\n", __LINE__, #expr); \
110 Log (("[!] ASSERTION FAILED at line %d: %s\n", __LINE__, #expr)); \
111 } \
112 } while (0)
113
114#endif
115
116/**
117 * Does the same as ASSERT(), but executes the |return ret| statement if the
118 * expression to assert is false;
119 */
120#define ASSERT_RET(expr, ret) \
121 do { ASSERT(expr); if (!(expr)) return (ret); } while (0)
122
123/**
124 * Does the same as ASSERT(), but executes the |break| statement if the
125 * expression to assert is false;
126 */
127#define ASSERT_BREAK(expr, ret) \
128 if (1) { ASSERT(expr); if (!(expr)) break; } else do {} while (0)
129
130} /* namespace com */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette