[1] | 1 | /** @file
|
---|
[45125] | 2 | * MS COM / XPCOM Abstraction Layer - Assertion macros for COM/XPCOM.
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[98103] | 6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 7 | *
|
---|
[96407] | 8 | * This file is part of VirtualBox base platform packages, as
|
---|
| 9 | * available from https://www.virtualbox.org.
|
---|
[5999] | 10 | *
|
---|
[96407] | 11 | * This program is free software; you can redistribute it and/or
|
---|
| 12 | * modify it under the terms of the GNU General Public License
|
---|
| 13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 14 | * License.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful, but
|
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 19 | * General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 23 | *
|
---|
[5999] | 24 | * The contents of this file may alternatively be used under the terms
|
---|
| 25 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[5999] | 28 | * CDDL are applicable instead of those of the GPL.
|
---|
| 29 | *
|
---|
| 30 | * You may elect to license modified versions of this file under the
|
---|
| 31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 32 | *
|
---|
| 33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 34 | */
|
---|
| 35 |
|
---|
[76558] | 36 | #ifndef VBOX_INCLUDED_com_assert_h
|
---|
| 37 | #define VBOX_INCLUDED_com_assert_h
|
---|
[76507] | 38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 39 | # pragma once
|
---|
| 40 | #endif
|
---|
[1] | 41 |
|
---|
| 42 | #include <iprt/assert.h>
|
---|
| 43 |
|
---|
[58110] | 44 | /** @defgroup grp_com_assert Assertion Macros for COM/XPCOM
|
---|
| 45 | * @ingroup grp_com
|
---|
| 46 | * @{
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 |
|
---|
[1] | 50 | /**
|
---|
| 51 | * Asserts that the COM result code is succeeded in strict builds.
|
---|
| 52 | * In non-strict builds the result code will be NOREF'ed to kill compiler warnings.
|
---|
| 53 | *
|
---|
[58096] | 54 | * @param hrc The COM result code
|
---|
[1] | 55 | */
|
---|
[58096] | 56 | #define AssertComRC(hrc) \
|
---|
| 57 | do { AssertMsg(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc)); NOREF(hrc); } while (0)
|
---|
[1] | 58 |
|
---|
| 59 | /**
|
---|
[58096] | 60 | * Same as AssertComRC, except the caller already knows we failed.
|
---|
| 61 | *
|
---|
| 62 | * @param hrc The COM result code
|
---|
| 63 | */
|
---|
| 64 | #define AssertComRCFailed(hrc) \
|
---|
| 65 | do { AssertMsgFailed(("COM RC = %Rhrc (0x%08X)\n", hrc, hrc)); NOREF(hrc); } while (0)
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
[1] | 68 | * A special version of AssertComRC that returns the given expression
|
---|
| 69 | * if the result code is failed.
|
---|
| 70 | *
|
---|
[58096] | 71 | * @param hrc The COM result code
|
---|
| 72 | * @param RetExpr The expression to return
|
---|
[1] | 73 | */
|
---|
[58096] | 74 | #define AssertComRCReturn(hrc, RetExpr) \
|
---|
| 75 | AssertMsgReturn(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc), RetExpr)
|
---|
[1] | 76 |
|
---|
| 77 | /**
|
---|
| 78 | * A special version of AssertComRC that returns the given result code
|
---|
| 79 | * if it is failed.
|
---|
| 80 | *
|
---|
[58096] | 81 | * @param hrc The COM result code
|
---|
[1] | 82 | */
|
---|
[58096] | 83 | #define AssertComRCReturnRC(hrc) \
|
---|
| 84 | AssertMsgReturn(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc), hrc)
|
---|
[1] | 85 |
|
---|
| 86 | /**
|
---|
| 87 | * A special version of AssertComRC that returns if the result code is failed.
|
---|
| 88 | *
|
---|
[58096] | 89 | * @param hrc The COM result code
|
---|
[1] | 90 | */
|
---|
[58096] | 91 | #define AssertComRCReturnVoid(hrc) \
|
---|
| 92 | AssertMsgReturnVoid(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc))
|
---|
[1] | 93 |
|
---|
| 94 | /**
|
---|
| 95 | * A special version of AssertComRC that evaluates the given expression and
|
---|
| 96 | * breaks if the result code is failed.
|
---|
| 97 | *
|
---|
[58096] | 98 | * @param hrc The COM result code
|
---|
| 99 | * @param PreBreakExpr The expression to evaluate on failure.
|
---|
[1] | 100 | */
|
---|
[58096] | 101 | #define AssertComRCBreak(hrc, PreBreakExpr) \
|
---|
[58098] | 102 | if (!SUCCEEDED(hrc)) { AssertComRCFailed(hrc); PreBreakExpr; break; } else do {} while (0)
|
---|
[1] | 103 |
|
---|
| 104 | /**
|
---|
[6076] | 105 | * A special version of AssertComRC that evaluates the given expression and
|
---|
| 106 | * throws it if the result code is failed.
|
---|
| 107 | *
|
---|
[58096] | 108 | * @param hrc The COM result code
|
---|
| 109 | * @param ThrowMeExpr The expression which result to be thrown on failure.
|
---|
[6076] | 110 | */
|
---|
[58099] | 111 | #define AssertComRCThrow(hrc, ThrowMeExpr) \
|
---|
[58098] | 112 | do { if (SUCCEEDED(hrc)) { /*likely*/} else { AssertComRCFailed(hrc); throw (ThrowMeExpr); } } while (0)
|
---|
[6076] | 113 |
|
---|
| 114 | /**
|
---|
[1] | 115 | * A special version of AssertComRC that just breaks if the result code is
|
---|
| 116 | * failed.
|
---|
| 117 | *
|
---|
[58096] | 118 | * @param hrc The COM result code
|
---|
[1] | 119 | */
|
---|
[58096] | 120 | #define AssertComRCBreakRC(hrc) \
|
---|
[58098] | 121 | if (!SUCCEEDED(hrc)) { AssertComRCFailed(hrc); break; } else do {} while (0)
|
---|
[1] | 122 |
|
---|
| 123 | /**
|
---|
[58096] | 124 | * A special version of AssertComRC that just throws @a hrc if the result code
|
---|
| 125 | * is failed.
|
---|
[6076] | 126 | *
|
---|
[58096] | 127 | * @param hrc The COM result code
|
---|
[6076] | 128 | */
|
---|
[58096] | 129 | #define AssertComRCThrowRC(hrc) \
|
---|
[58098] | 130 | do { if (SUCCEEDED(hrc)) { /*likely*/ } else { AssertComRCFailed(hrc); throw hrc; } } while (0)
|
---|
[6076] | 131 |
|
---|
[58110] | 132 | /** @} */
|
---|
| 133 |
|
---|
[76585] | 134 | #endif /* !VBOX_INCLUDED_com_assert_h */
|
---|
[45125] | 135 |
|
---|