xref: /aosp_15_r20/external/intel-media-driver/cmrtlib/agnostic/share/cm_debug.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #ifndef CMRTLIB_AGNOSTIC_SHARE_CMDEBUG_H_
23 #define CMRTLIB_AGNOSTIC_SHARE_CMDEBUG_H_
24 
25 #include <cstdio>
26 #include "cm_def_os.h"
27 
CmPrintMessage(const char * str,...)28 inline void CmPrintMessage( const char *str, ... )
29 {
30 #ifdef _DEBUG
31     //iSTD::PrintMessage( str );
32 #endif
33 }
34 
CmAssertMessage(const char * message)35 inline void CmAssertMessage(const char *message) {
36   printf("%s\n", message);
37   CmAssert(0);
38   return;
39 }
40 
41 #ifdef _DEBUG
42 #define CmDebugMessage(arg) CmPrintMessage arg
43 #else
44 #define CmDebugMessage(arg)
45 #endif // _DEBUG
46 
47 #define CmReleaseMessage(arg) CmPrintMessage arg
48 
49 //*-----------------------------------------------------------------------------
50 //| Macro checks the COM Results
51 //*-----------------------------------------------------------------------------
52 #ifndef CHK_RET
53 #define CHK_RET(stmt)                                                           \
54 {                                                                               \
55     result = (stmt);                                                            \
56     if (result != CM_SUCCESS)                                                   \
57     {                                                                           \
58         CmPrintMessage("%s: hr check failed\n", __FUNCTION__);                  \
59         CmAssert(0);                                                            \
60         goto finish;                                                            \
61     }                                                                           \
62 }
63 #endif // CHK_HR
64 
65 #ifndef CHK_NULL
66 #define CHK_NULL(p)                                                           \
67 {                                                                               \
68     if ( (p) == nullptr)                                                   \
69     {                                                                           \
70         CmPrintMessage("%s: nullptr check failed\n", __FUNCTION__);                  \
71         CmAssert(0);                                                            \
72         result = CM_NULL_POINTER;                                               \
73         goto finish;                                                            \
74     }                                                                           \
75 }
76 #endif
77 
78 #ifndef CHK_NULL_RETURN
79 #define CHK_NULL_RETURN(p)                                                           \
80 {                                                                               \
81     if ( (p) == nullptr)                                                   \
82     {                                                                           \
83         CmPrintMessage("%s: nullptr check failed\n", __FUNCTION__);                  \
84         CmAssert(0);                                                            \
85         return CM_NULL_POINTER;                                               \
86     }                                                                           \
87 }
88 #endif
89 
90 #ifndef CHK_FAILURE_RETURN
91 #define CHK_FAILURE_RETURN(ret)                                                           \
92 {                                                                               \
93     if ( (ret) != CM_SUCCESS)                                                   \
94     {                                                                           \
95         CmPrintMessage("%s:%d: return check failed\n", __FUNCTION__, __LINE__);                  \
96         return ret;                                                            \
97     }                                                                           \
98 }
99 #endif
100 
101 #endif  // #ifndef CMRTLIB_AGNOSTIC_SHARE_CMDEBUG_H_
102