1 /***************************************************************** 2 | 3 | Neptune - Result Codes 4 | 5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC. 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of Axiomatic Systems nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY 20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 ****************************************************************/ 31 32 #ifndef _NPT_RESULTS_H_ 33 #define _NPT_RESULTS_H_ 34 35 /*---------------------------------------------------------------------- 36 | macros 37 +---------------------------------------------------------------------*/ 38 #if defined(NPT_DEBUG) 39 #include "NptDebug.h" 40 #define NPT_CHECK(_x) \ 41 do { \ 42 NPT_Result _result = (_x); \ 43 if (_result != NPT_SUCCESS) { \ 44 NPT_Debug("%s(%d): @@@ NPT_CHECK failed, result=%d (%s)\n", __FILE__, __LINE__, _result, NPT_ResultText(_result)); \ 45 return _result; \ 46 } \ 47 } while(0) 48 #define NPT_CHECK_POINTER(_p) \ 49 do { \ 50 if ((_p) == NULL) { \ 51 NPT_Debug("%s(%d): @@@ NULL pointer parameter\n", __FILE__, __LINE__); \ 52 return NPT_ERROR_INVALID_PARAMETERS; \ 53 } \ 54 } while(0) 55 #define NPT_CHECK_LABEL(_x, label) \ 56 do { \ 57 NPT_Result _result = (_x); \ 58 if (_result != NPT_SUCCESS) { \ 59 NPT_Debug("%s(%d): @@@ NPT_CHECK failed, result=%d (%s)\n", __FILE__, __LINE__, _result, NPT_ResultText(_result)); \ 60 goto label; \ 61 } \ 62 } while(0) 63 #define NPT_CHECK_POINTER_LABEL(_p, label) \ 64 do { \ 65 if (_p == NULL) { \ 66 NPT_Debug("%s(%d): @@@ NULL pointer parameter\n", __FILE__, __LINE__); \ 67 goto label; \ 68 } \ 69 } while(0) 70 #else 71 #define NPT_CHECK(_x) \ 72 do { \ 73 NPT_Result _result = (_x); \ 74 if (_result != NPT_SUCCESS) { \ 75 return _result; \ 76 } \ 77 } while(0) 78 #define NPT_CHECK_POINTER(_p) \ 79 do { \ 80 if ((_p) == NULL) return NPT_ERROR_INVALID_PARAMETERS; \ 81 } while(0) 82 #define NPT_CHECK_LABEL(_x, label) \ 83 do { \ 84 NPT_Result _result = (_x); \ 85 if (_result != NPT_SUCCESS) { \ 86 goto label; \ 87 } \ 88 } while(0) 89 #define NPT_CHECK_POINTER_LABEL(_p, label) \ 90 do { \ 91 if ((_p) == NULL) { \ 92 goto label; \ 93 } \ 94 } while(0) 95 #endif 96 97 #define NPT_FAILED(result) ((result) != NPT_SUCCESS) 98 #define NPT_SUCCEEDED(result) ((result) == NPT_SUCCESS) 99 100 /*---------------------------------------------------------------------- 101 | result codes 102 +---------------------------------------------------------------------*/ 103 /** Result indicating that the operation or call succeeded */ 104 #define NPT_SUCCESS 0 105 106 /** Result indicating an unspecififed failure condition */ 107 #define NPT_FAILURE (-1) 108 109 #if !defined(NPT_ERROR_BASE) 110 #define NPT_ERROR_BASE -20000 111 #endif 112 113 // error bases 114 #define NPT_ERROR_BASE_GENERAL (NPT_ERROR_BASE-0) 115 #define NPT_ERROR_BASE_LIST (NPT_ERROR_BASE-100) 116 #define NPT_ERROR_BASE_FILE (NPT_ERROR_BASE-200) 117 #define NPT_ERROR_BASE_IO (NPT_ERROR_BASE-300) 118 #define NPT_ERROR_BASE_SOCKET (NPT_ERROR_BASE-400) 119 #define NPT_ERROR_BASE_INTERFACES (NPT_ERROR_BASE-500) 120 #define NPT_ERROR_BASE_XML (NPT_ERROR_BASE-600) 121 #define NPT_ERROR_BASE_UNIX (NPT_ERROR_BASE-700) 122 #define NPT_ERROR_BASE_HTTP (NPT_ERROR_BASE-800) 123 #define NPT_ERROR_BASE_THREADS (NPT_ERROR_BASE-900) 124 #define NPT_ERROR_BASE_SERIAL_PORT (NPT_ERROR_BASE-1000) 125 #define NPT_ERROR_BASE_TLS (NPT_ERROR_BASE-1100) 126 127 // general errors 128 #define NPT_ERROR_INVALID_PARAMETERS (NPT_ERROR_BASE_GENERAL - 0) 129 #define NPT_ERROR_PERMISSION_DENIED (NPT_ERROR_BASE_GENERAL - 1) 130 #define NPT_ERROR_OUT_OF_MEMORY (NPT_ERROR_BASE_GENERAL - 2) 131 #define NPT_ERROR_NO_SUCH_NAME (NPT_ERROR_BASE_GENERAL - 3) 132 #define NPT_ERROR_NO_SUCH_PROPERTY (NPT_ERROR_BASE_GENERAL - 4) 133 #define NPT_ERROR_NO_SUCH_ITEM (NPT_ERROR_BASE_GENERAL - 5) 134 #define NPT_ERROR_NO_SUCH_CLASS (NPT_ERROR_BASE_GENERAL - 6) 135 #define NPT_ERROR_OVERFLOW (NPT_ERROR_BASE_GENERAL - 7) 136 #define NPT_ERROR_INTERNAL (NPT_ERROR_BASE_GENERAL - 8) 137 #define NPT_ERROR_INVALID_STATE (NPT_ERROR_BASE_GENERAL - 9) 138 #define NPT_ERROR_INVALID_FORMAT (NPT_ERROR_BASE_GENERAL - 10) 139 #define NPT_ERROR_INVALID_SYNTAX (NPT_ERROR_BASE_GENERAL - 11) 140 #define NPT_ERROR_NOT_IMPLEMENTED (NPT_ERROR_BASE_GENERAL - 12) 141 #define NPT_ERROR_NOT_SUPPORTED (NPT_ERROR_BASE_GENERAL - 13) 142 #define NPT_ERROR_TIMEOUT (NPT_ERROR_BASE_GENERAL - 14) 143 #define NPT_ERROR_WOULD_BLOCK (NPT_ERROR_BASE_GENERAL - 15) 144 #define NPT_ERROR_TERMINATED (NPT_ERROR_BASE_GENERAL - 16) 145 #define NPT_ERROR_OUT_OF_RANGE (NPT_ERROR_BASE_GENERAL - 17) 146 #define NPT_ERROR_OUT_OF_RESOURCES (NPT_ERROR_BASE_GENERAL - 18) 147 #define NPT_ERROR_NOT_ENOUGH_SPACE (NPT_ERROR_BASE_GENERAL - 19) 148 #define NPT_ERROR_INTERRUPTED (NPT_ERROR_BASE_GENERAL - 20) 149 #define NPT_ERROR_CANCELLED (NPT_ERROR_BASE_GENERAL - 21) 150 151 /* standard error codes */ 152 /* these are special codes to convey an errno */ 153 /* the error code is (SHI_ERROR_BASE_ERRNO - errno) */ 154 /* where errno is the positive integer from errno.h */ 155 #define NPT_ERROR_BASE_ERRNO (NPT_ERROR_BASE-2000) 156 #define NPT_ERROR_ERRNO(e) (NPT_ERROR_BASE_ERRNO - (e)) 157 158 /*---------------------------------------------------------------------- 159 | functions 160 +---------------------------------------------------------------------*/ 161 const char* NPT_ResultText(int result); 162 163 #endif // _NPT_RESULTS_H_ 164