00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #ifndef _PROTLIB__TP_ERROR_H_
00035 #define _PROTLIB__TP_ERROR_H_
00036
00037 #include <string.h>
00038
00039 #include "protlib_types.h"
00040
00041 namespace protlib {
00042
00048
00049
00050 class TPError : public ProtLibException {
00051 public:
00053 enum tp_error_t {
00054 TPERR_OK,
00055 TPERR_BAD_ADDRESS,
00056 TPERR_BAD_NETMSG,
00057 TPERR_ARGS_NOT_INIT,
00058 TPERR_UNREACHABLE,
00059 TPERR_INTERNAL,
00060 TPERR_PAYLOAD,
00061 TPERR_INITFAILED,
00062 TPERR_SENDFAILED,
00063 TPERR_CONNSETUPFAIL,
00064 TPERR_CLOSEIND,
00065 TPERR_ABORTIND
00066 };
00067
00069 TPError(tp_error_t e) : errtype(e) {};
00070
00072 virtual const char* getstr() const= 0;
00073 virtual const char *what() const throw() { return getstr(); }
00075 const tp_error_t errtype;
00076 };
00077
00078
00079
00080
00081 class TPErrorBadDestAddress : public TPError
00082 {
00083 public:
00084 TPErrorBadDestAddress() : TPError(TPError::TPERR_BAD_ADDRESS) {}
00085 virtual const char* getstr() const { return "Bad Destination Address"; }
00086 };
00087
00088
00089 class TPErrorArgsNotInit : public TPError
00090 {
00091 public:
00092 TPErrorArgsNotInit() : TPError(TPError::TPERR_ARGS_NOT_INIT) {}
00093 virtual const char* getstr() const { return "arguments of TPMsg not initialized"; }
00094 };
00095
00096 class TPErrorUnreachable : public TPError
00097 {
00098 public:
00099 TPErrorUnreachable() : TPError(TPError::TPERR_UNREACHABLE) {}
00100 virtual const char* getstr() const { return "Destination unreachable"; }
00101 };
00102
00103 class TPErrorInternal : public TPError
00104 {
00105 public:
00106 TPErrorInternal() : TPError(TPError::TPERR_INTERNAL) {}
00107 virtual const char* getstr() const { return "Internal Transport Protocol Error"; }
00108 };
00109
00110
00111 class TPErrorPayload : public TPError
00112 {
00113 public:
00114 TPErrorPayload() : TPError(TPError::TPERR_PAYLOAD) {}
00115 virtual const char* getstr() const { return "Payload exceeds maximum transmission unit or empty payload given"; }
00116 };
00117
00118 class TPErrorInitFailed : public TPError
00119 {
00120 public:
00121 TPErrorInitFailed() : TPError(TPError::TPERR_INITFAILED) {}
00122 virtual const char* getstr() const { return "Initialization of protocol failed"; }
00123 };
00124
00125 class TPErrorSendFailed : public TPError
00126 {
00127 int saved_errno;
00128 public:
00129 TPErrorSendFailed(int current_errno= 0) : TPError(TPError::TPERR_SENDFAILED), saved_errno(current_errno) {}
00130 virtual const char* getstr() const { return "Failure while trying to send a protocol data unit"; }
00131 int get_reason() const { return saved_errno; }
00132 };
00133
00134 class TPErrorConnectSetupFail : public TPError
00135 {
00136 public:
00137 TPErrorConnectSetupFail() : TPError(TPError::TPERR_CONNSETUPFAIL) {}
00138 virtual const char* getstr() const { return "Connection Setup Failure"; }
00139 };
00140
00141 class TPErrorCloseInd : public TPError
00142 {
00143 public:
00144 TPErrorCloseInd() : TPError(TPError::TPERR_CLOSEIND) {}
00145 virtual const char* getstr() const { return "Other side closed connection"; }
00146 };
00147
00148 class TPErrorAbortInd : public TPError
00149 {
00150 public:
00151 TPErrorAbortInd() : TPError(TPError::TPERR_ABORTIND) {}
00152 virtual const char* getstr() const { return "Abort indication, transport protocol indicated failure/abort"; }
00153 };
00154
00155 }
00156
00157 #endif // _PROTLIB__TP_ERROR_H_