| 1 | /* |
| 2 | * Legal Notice |
| 3 | * |
| 4 | * This document and associated source code (the "Work") is a part of a |
| 5 | * benchmark specification maintained by the TPC. |
| 6 | * |
| 7 | * The TPC reserves all right, title, and interest to the Work as provided |
| 8 | * under U.S. and international laws, including without limitation all patent |
| 9 | * and trademark rights therein. |
| 10 | * |
| 11 | * No Warranty |
| 12 | * |
| 13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
| 14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
| 15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
| 16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
| 17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
| 18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
| 20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
| 21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
| 22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
| 23 | * WITH REGARD TO THE WORK. |
| 24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
| 25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
| 26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
| 27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
| 28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
| 29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
| 30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
| 31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
| 32 | * |
| 33 | * Contributors |
| 34 | * - Sergey Vasilevskiy, Matt Emmerton |
| 35 | */ |
| 36 | |
| 37 | #ifndef ERROR_H |
| 38 | #define ERROR_H |
| 39 | |
| 40 | #include <string> |
| 41 | |
| 42 | namespace TPCE { |
| 43 | |
| 44 | #define ERR_TYPE_LOGIC -1 // logic error in program; internal error |
| 45 | #define ERR_SUCCESS 0 // success (a non-error error) |
| 46 | #define ERR_TYPE_OS 11 // operating system error |
| 47 | #define ERR_TYPE_MEMORY 12 // memory allocation error |
| 48 | #define ERR_TYPE_FIXED_MAP 27 // Error from CFixedMap |
| 49 | #define ERR_TYPE_FIXED_ARRAY 28 // Error from CFixedArray |
| 50 | #define ERR_TYPE_CHECK 29 // Check assertion error (from DriverParamSettings) |
| 51 | |
| 52 | #define ERR_INS_MEMORY "Insufficient Memory to continue." |
| 53 | #define ERR_UNKNOWN "Unknown error." |
| 54 | #define ERR_MSG_BUF_SIZE 512 |
| 55 | #define INV_ERROR_CODE -1 |
| 56 | |
| 57 | class CBaseErr : public std::exception { |
| 58 | protected: |
| 59 | std::string m_location; |
| 60 | int m_idMsg; |
| 61 | |
| 62 | public: |
| 63 | CBaseErr() : m_location(), m_idMsg(INV_ERROR_CODE) { |
| 64 | } |
| 65 | |
| 66 | CBaseErr(char const *szLoc) : m_location(szLoc), m_idMsg(INV_ERROR_CODE) { |
| 67 | } |
| 68 | |
| 69 | CBaseErr(int idMsg) : m_location(), m_idMsg(idMsg) { |
| 70 | } |
| 71 | |
| 72 | CBaseErr(int idMsg, char const *szLoc) : m_location(szLoc), m_idMsg(idMsg) { |
| 73 | } |
| 74 | |
| 75 | ~CBaseErr() throw() { |
| 76 | } |
| 77 | |
| 78 | virtual const char *what() const throw() { |
| 79 | return ErrorText(); |
| 80 | } |
| 81 | |
| 82 | virtual int ErrorNum() { |
| 83 | return m_idMsg; |
| 84 | } |
| 85 | virtual int ErrorType() = 0; // a value which distinguishes the kind of |
| 86 | // error that occurred |
| 87 | |
| 88 | virtual const char *ErrorText() const = 0; // a string (i.e., human readable) representation of |
| 89 | // the error |
| 90 | virtual const char *ErrorLoc() { |
| 91 | return m_location.c_str(); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | class CMemoryErr : public CBaseErr { |
| 96 | public: |
| 97 | CMemoryErr() : CBaseErr() { |
| 98 | } |
| 99 | |
| 100 | CMemoryErr(char const *szLoc) : CBaseErr(szLoc) { |
| 101 | } |
| 102 | |
| 103 | int ErrorType() { |
| 104 | return ERR_TYPE_MEMORY; |
| 105 | } |
| 106 | const char *ErrorText() const { |
| 107 | return ERR_INS_MEMORY; |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | class CSystemErr : public CBaseErr { |
| 112 | public: |
| 113 | enum Action { |
| 114 | eNone = 0, |
| 115 | eTransactNamedPipe, |
| 116 | eWaitNamedPipe, |
| 117 | eSetNamedPipeHandleState, |
| 118 | eCreateFile, |
| 119 | eCreateProcess, |
| 120 | eCallNamedPipe, |
| 121 | eCreateEvent, |
| 122 | eCreateThread, |
| 123 | eVirtualAlloc, |
| 124 | eReadFile = 10, |
| 125 | eWriteFile, |
| 126 | eMapViewOfFile, |
| 127 | eCreateFileMapping, |
| 128 | eInitializeSecurityDescriptor, |
| 129 | eSetSecurityDescriptorDacl, |
| 130 | eCreateNamedPipe, |
| 131 | eConnectNamedPipe, |
| 132 | eWaitForSingleObject, |
| 133 | eRegOpenKeyEx, |
| 134 | eRegQueryValueEx = 20, |
| 135 | ebeginthread, |
| 136 | eRegEnumValue, |
| 137 | eRegSetValueEx, |
| 138 | eRegCreateKeyEx, |
| 139 | eWaitForMultipleObjects, |
| 140 | eRegisterClassEx, |
| 141 | eCreateWindow, |
| 142 | eCreateSemaphore, |
| 143 | eReleaseSemaphore, |
| 144 | eFSeek, |
| 145 | eFRead, |
| 146 | eFWrite, |
| 147 | eTmpFile, |
| 148 | eSetFilePointer, |
| 149 | eNew, |
| 150 | eCloseHandle, |
| 151 | eCreateMutex, |
| 152 | eReleaseMutex |
| 153 | }; |
| 154 | |
| 155 | CSystemErr(Action eAction, char const *szLocation); |
| 156 | CSystemErr(int iError, Action eAction, char const *szLocation); |
| 157 | int ErrorType() { |
| 158 | return ERR_TYPE_OS; |
| 159 | }; |
| 160 | const char *ErrorText(void) const; |
| 161 | |
| 162 | Action m_eAction; |
| 163 | |
| 164 | ~CSystemErr() throw() { |
| 165 | } |
| 166 | }; |
| 167 | |
| 168 | class CBaseTxnErr { |
| 169 | public: |
| 170 | enum { |
| 171 | // Expected Transaction Status Values |
| 172 | SUCCESS = 0, |
| 173 | EXPECTED_ROLLBACK = 1, // returned from Trade-Order Frame 5 to indicate |
| 174 | // transaction rollback |
| 175 | |
| 176 | // Unexpected Transaction Status Values |
| 177 | // Negative values are errors |
| 178 | // Positive values are warnings |
| 179 | |
| 180 | BVF1_ERROR1 = -111, // list_len not in [0..max_broker_list_len] |
| 181 | |
| 182 | CPF1_ERROR1 = -211, // acct_len not in [1..max_acct_len] |
| 183 | CPF2_ERROR1 = -221, // hist_len not in [min_hist_len..max_hist_len] |
| 184 | |
| 185 | MFF1_ERROR1 = -311, // num_updated < unique symbols |
| 186 | |
| 187 | MWF1_ERROR1 = -411, // invalid input |
| 188 | |
| 189 | SDF1_ERROR1 = -511, // day_len not in [min_day_len..max_day_len] |
| 190 | SDF1_ERROR2 = -512, // fin_len <> max_fin_len |
| 191 | SDF1_ERROR3 = -513, // news_len <> max_news_len |
| 192 | |
| 193 | TLF1_ERROR1 = -611, // num_found <> max_trades |
| 194 | TLF2_ERROR1 = -621, // num_found not in [0..max_trades] |
| 195 | TLF2_WARN1 = +621, // num_found == 0 |
| 196 | TLF3_ERROR1 = -631, // num_found not in [0..max_trades] |
| 197 | TLF3_WARN1 = +631, // num_found == 0 |
| 198 | TLF4_ERROR1 = -641, // num_trades_found not in [0..1] |
| 199 | TLF4_WARN1 = +641, // num_trades_found == 0 |
| 200 | TLF4_ERROR2 = -642, // num_found not in [1..20] |
| 201 | |
| 202 | TOF1_ERROR1 = -711, // num_found <> 1 |
| 203 | TOF2_ERROR1 = -721, // ap_acl[0] == '\0' |
| 204 | TOF3_ERROR1 = -731, // tax_amount == 0 (for profitable, taxable trade) |
| 205 | TOF3_ERROR2 = -732, // comm_rate == 0 |
| 206 | TOF3_ERROR3 = -733, // charge_amount == 0 |
| 207 | |
| 208 | TRF1_ERROR1 = -811, // num_found <> 1 |
| 209 | TRF3_ERROR1 = -831, // tax_amount < 0 |
| 210 | TRF4_ERROR1 = -841, // comm_rate <= 0 |
| 211 | |
| 212 | TSF1_ERROR1 = -911, // num_found <> max_trade_status_len |
| 213 | |
| 214 | TUF1_ERROR1 = -1011, // num_found <> max_trades |
| 215 | TUF1_ERROR2 = -1012, // num_updated <> max_updates |
| 216 | TUF2_ERROR1 = -1021, // num_found not in [0..max_trades] |
| 217 | TUF2_ERROR2 = -1022, // num_updated <> num_found |
| 218 | TUF2_WARN1 = +1021, // num_updated == 0 |
| 219 | TUF3_ERROR1 = -1031, // num_found not in [0..max_trades] |
| 220 | TUF3_ERROR2 = -1032, // num_updated > num_found |
| 221 | TUF3_WARN1 = +1031 // num_updated == 0 |
| 222 | } mErrCode; |
| 223 | }; |
| 224 | |
| 225 | class CCheckErr : public CBaseErr { |
| 226 | private: |
| 227 | std::string name_; |
| 228 | std::string msg_; |
| 229 | |
| 230 | public: |
| 231 | CCheckErr() : CBaseErr() { |
| 232 | } |
| 233 | |
| 234 | ~CCheckErr() throw() { |
| 235 | } |
| 236 | |
| 237 | CCheckErr(const char *name, const std::string &msg) : CBaseErr(name), msg_(msg) { |
| 238 | } |
| 239 | |
| 240 | int ErrorType() { |
| 241 | return ERR_TYPE_CHECK; |
| 242 | } |
| 243 | const char *ErrorText() const { |
| 244 | return msg_.c_str(); |
| 245 | } |
| 246 | }; |
| 247 | |
| 248 | } // namespace TPCE |
| 249 | |
| 250 | #endif // ERROR_H |
| 251 | |