1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: err_Api.h 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_ERR_CTR_ERR_API_H_ 17 #define NN_ERR_CTR_ERR_API_H_ 18 19 #include <nn/types.h> 20 #include <nn/Result.h> 21 22 #ifdef __cplusplus 23 namespace nn { 24 namespace err { 25 namespace CTR { 26 27 // Do not directly call the following function. Use the NN_ERR_THROW_* macro. 28 void ThrowFatalErr( Result result, uptr pc ); 29 void ThrowFatalErrAll( Result result, uptr pc ); 30 31 void AddToErrLog( Result result ); 32 void AddToErrLog( Result result, const char* fileName, int lineno ); 33 34 void LogAndPanic( Result result, uptr pc ); 35 void LogAndPanic( Result result, const char* fileName, int lineno, uptr pc ); 36 37 namespace detail 38 { 39 template <bool(*IsTarget)(Result), void (*TargetFunc)(Result,uptr)> CallIf(Result r,uptr pc)40 inline void CallIf(Result r, uptr pc) 41 { 42 if( IsTarget(r) ) 43 { 44 TargetFunc(r, pc); 45 } 46 } 47 48 template <bool(*IsTarget)(Result), void (*TargetFunc)(Result,const char*,int,uptr)> CallIf(Result r,const char * fileName,int lineno,uptr pc)49 inline void CallIf(Result r, const char* fileName, int lineno, uptr pc ) 50 { 51 if( IsTarget(r) ) 52 { 53 TargetFunc(r, fileName, lineno, pc); 54 } 55 } 56 IsResultFailure(Result r)57 inline bool IsResultFailure(Result r) { return r.IsFailure(); } IsResultFatal(Result r)58 inline bool IsResultFatal(Result r) { return r.GetLevel() == ::nn::Result::LEVEL_FATAL; } 59 } 60 }}} // namespace nn::err::CTR 61 62 #ifndef NN_HARDWARE_CTR_LEGACY 63 #ifdef NN_PROCESSOR_ARM11MPCORE 64 #define NN_ERR_CTR_ERR_API_H_CALL_IF(result, test, f) \ 65 ::nn::err::CTR::detail::CallIf \ 66 < ::nn::err::CTR::detail::test, \ 67 ::nn::err::CTR::f >(result, __current_pc()) 68 69 #define NN_ERR_CTR_ERR_API_H_CALL_IF2(result, test, f) \ 70 ::nn::err::CTR::detail::CallIf \ 71 < ::nn::err::CTR::detail::test, \ 72 ::nn::err::CTR::f >(result, NN_FILE_NAME, __LINE__, __current_pc()) 73 74 /* 75 Throw a fatal error and display the error screen. 76 An actual notification occurs only when the Result's LEVEL is FATAL. 77 */ 78 #define NN_ERR_THROW_FATAL_IF_FATAL_ONLY(result) \ 79 NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsResultFatal, ThrowFatalErrAll) 80 81 /* 82 Throw a fatal error and display the error screen. 83 An actual notification occurs when the Result LEVEL is not SUCCESS/STATUS/INFO (not recommended) (for fatal errors or errors that should not occur in the retail product). 84 85 86 */ 87 #define NN_ERR_THROW_FATAL(result) \ 88 NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsResultFailure, ThrowFatalErr) 89 90 /* 91 Throw a fatal error and display the error screen. 92 Notifies for all Results that are errors. 93 */ 94 #define NN_ERR_THROW_FATAL_ALL(result) \ 95 NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsResultFailure, ThrowFatalErrAll) 96 97 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT 98 #define NN_ERR_LOG_AND_PANIC_IF_FAILED(result) \ 99 NN_ERR_CTR_ERR_API_H_CALL_IF2(result, IsResultFailure, LogAndPanic) 100 #else /* NN_SWITCH_DISABLE_DEBUG_PRINT */ 101 #define NN_ERR_LOG_AND_PANIC_IF_FAILED(result) \ 102 NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsResultFailure, LogAndPanic) 103 #endif /* NN_SWITCH_DISABLE_DEBUG_PRINT */ 104 105 106 //#define NN_ERR_CTR_ERR_API_H_CALL_IF(result, test, f) \ 107 // do \ 108 // { \ 109 // ::nn::Result resultLocal = (result); \ 110 // if ( resultLocal.test ) \ 111 // { \ 112 // ::nn::err::f(resultLocal); \ 113 // } \ 114 // } while(0) 115 // 116 //#define NN_ERR_CTR_ERR_API_H_CALL_IF2(result, test, f) \ 117 // do \ 118 // { \ 119 // ::nn::Result resultLocal = (result); \ 120 // if ( resultLocal.test ) \ 121 // { \ 122 // ::nn::err::f(resultLocal, NN_FILE_NAME, __LINE__); \ 123 // } \ 124 // } while(0) 125 // 126 //#define NN_ERR_THROW_FATAL_IF_FATAL_ONLY(result) \ 127 // NN_ERR_CTR_ERR_API_H_CALL_IF(result, GetLevel() == ::nn::Result::LEVEL_FATAL, ThrowFatalErrAll) 128 //#define NN_ERR_THROW_FATAL(result) \ 129 // NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsFailure(), ThrowFatalErr) 130 //#define NN_ERR_THROW_FATAL_ALL(result) \ 131 // NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsFailure(), ThrowFatalErrAll) 132 // 133 //#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT 134 // #define NN_ERR_LOG_AND_PANIC_IF_FAILED(result) \ 135 // NN_ERR_CTR_ERR_API_H_CALL_IF2(result, IsFailure(), LogAndPanic) 136 //#else /* NN_SWITCH_DISABLE_DEBUG_PRINT */ 137 // #define NN_ERR_LOG_AND_PANIC_IF_FAILED(result) \ 138 // NN_ERR_CTR_ERR_API_H_CALL_IF(result, IsFailure(), LogAndPanic) 139 //#endif /* NN_SWITCH_DISABLE_DEBUG_PRINT */ 140 141 #else /* NN_PROCESSOR_ARM11MPCORE */ 142 143 #define NN_ERR_THROW_FATAL_IF_FATAL_ONLY(result) NN_UTIL_PANIC_IF_FAILED(result) 144 #define NN_ERR_THROW_FATAL(result) NN_UTIL_PANIC_IF_FAILED(result) 145 #define NN_ERR_THROW_FATAL_ALL(result) NN_UTIL_PANIC_IF_FAILED(result) 146 #define NN_ERR_LOG_AND_PANIC_IF_FAILED(result) NN_UTIL_PANIC_IF_FAILED(result) 147 148 #endif /* NN_PROCESSOR_ARM11MPCORE */ 149 #else /* NN_HARDWARE_CTR_LEGACY */ 150 151 #define NN_ERR_THROW_FATAL_IF_FATAL_ONLY(result) ((void)(result)) 152 #define NN_ERR_THROW_FATAL(result) ((void)(result)) 153 #define NN_ERR_THROW_FATAL_ALL(result) ((void)(result)) 154 #define NN_ERR_LOG_AND_PANIC_IF_FAILED(result) ((void)(result)) 155 156 #endif /* NN_HARDWARE_CTR_LEGACY */ 157 #endif // __cplusplus 158 159 160 #endif /* NN_ERR_CTR_ERR_API_H_ */ 161