00001 #ifndef OT_EX_EXCEPTION_H
00002 #define OT_EX_EXCEPTION_H
00003
00004
00005 class ot_exception : public std::exception, public ot_obj
00006 {
00007 protected:
00008
00009 string m_errS;
00010
00011 ot_exception(OT_OBJECT_TYPE type,const string &errS) : ot_obj(type),m_errS(errS)
00012 {
00013 }
00014
00015
00016 public:
00017
00018 virtual ~ot_exception() throw()
00019 {
00020 }
00021
00022 const char *what() const throw()
00023 {
00024 return(m_errS.c_str());
00025 }
00026
00027 void asXml(ostream &s=cout,int i=0) const;
00028
00029 virtual void throwException(void) const throw() = 0;
00030 };
00031
00032
00033
00034 #define OT_EXCEPTION_BUILDER(NAME,CODE,STRING) \
00035 class ot_##NAME : public ot_exception \
00036 { \
00037 public: \
00038 ot_##NAME() : ot_exception(CODE,STRING) {} \
00039 ot_##NAME(const ot_##NAME &r) : ot_exception(r.getType(),r.m_errS) {} \
00040 \
00041 virtual ~ot_##NAME() throw() {} \
00042 \
00043 ot_obj *dup(void) const {return(new ot_##NAME(*this));}\
00044 \
00045 bool asData(ostream &s) const \
00046 { \
00047 if(!writeIntegerAsData(s,getType())) return(false); \
00048 return(true); \
00049 } \
00050 \
00051 bool operator == (const ot_##NAME &r) const \
00052 { \
00053 if(m_errS == r.m_errS) return(true); \
00054 else return(false); \
00055 } \
00056 \
00057 bool operator == (const ot_obj *o) const \
00058 { \
00059 if(o && o->getType()==getType()) return(*this==*((ot_##NAME *) o)); \
00060 else return(false); \
00061 } \
00062 \
00063 void throwException(void) const throw() {throw(*this);} \
00064 \
00065 }; \
00066 \
00067 class ot_factory##NAME : public ot_objectFactoryCallback \
00068 { \
00069 public: \
00070 \
00071 ot_factory##NAME(void) : ot_objectFactoryCallback(CODE) {} \
00072 \
00073 ot_obj * fromData(istream &s) const \
00074 { \
00075 int type; \
00076 \
00077 if(!ot_obj::readIntegerFromData(s,type)) return(0); \
00078 if(type!=CODE) return(0); \
00079 \
00080 return(new ot_##NAME()); \
00081 } \
00082 };
00083
00084 OT_EXCEPTION_BUILDER(interfaceNotFound, OT_EX_INTERFACE_NOT_EX_FOUND, "Interface not found")
00085 OT_EXCEPTION_BUILDER(codecDecodingError, OT_EX_CODEC_DECODING_ERROR, "Decoding error")
00086 OT_EXCEPTION_BUILDER(accessDeny, OT_EX_ACCESS_DENY, "Access deny")
00087 OT_EXCEPTION_BUILDER(functionNotFound, OT_EX_FUNCTION_NOT_EX_FOUND, "Function not found")
00088 OT_EXCEPTION_BUILDER(outOfMemory, OT_EX_OUT_OF_MEMORY, "Out of memory")
00089 OT_EXCEPTION_BUILDER(elementDeletionError, OT_EX_ELEMENT_DELETION_ERROR, "Element deletion error")
00090 OT_EXCEPTION_BUILDER(invalidInterfaceName, OT_EX_INVALID_INTERFACE_NAME, "Invalid interface name")
00091 OT_EXCEPTION_BUILDER(invalidFunctionName, OT_EX_INVALID_FUNCTION_NAME, "Invalid function name")
00092 OT_EXCEPTION_BUILDER(invalidAttributeName, OT_EX_INVALID_ATTRIBUTE_NAME, "Invalid attribute name")
00093 OT_EXCEPTION_BUILDER(interfaceAlreadyPresent, OT_EX_INTERFACE_ALREADY_PRESENT, "Intreface already present")
00094 OT_EXCEPTION_BUILDER(interfaceElementNotFound, OT_EX_INTERFACE_ELEMENT_NOT_FOUND, "Interface element not found")
00095 OT_EXCEPTION_BUILDER(interfaceFull, OT_EX_INTERFACE_FULL, "Interface full")
00096 OT_EXCEPTION_BUILDER(elementAlreadypresent, OT_EX_ELEMENT_ALREADY_PRESENT, "Element already present")
00097 OT_EXCEPTION_BUILDER(internalError, OT_EX_INTERNAL_ERROR, "Internal error")
00098 OT_EXCEPTION_BUILDER(attributeLocked, OT_EX_ATTRIBUTE_LOCKED, "Attribute locked")
00099 OT_EXCEPTION_BUILDER(encodingError, OT_EX_ENCODING_ERROR, "Encoding error")
00100 OT_EXCEPTION_BUILDER(decodingError, OT_EX_DECODING_ERROR, "Decoding error")
00101 OT_EXCEPTION_BUILDER(codecNotFound, OT_EX_CODEC_NOT_FOUND, "Codec not found");
00102 OT_EXCEPTION_BUILDER(codecRegistrationFailed, OT_EX_CODEC_REGISTRATION_FAILED, "Codec registration failed");
00103 OT_EXCEPTION_BUILDER(socketServerInitFailed, OT_EX_SOCKET_SERVER_INIT_FAILED, "Socket server init failed")
00104 OT_EXCEPTION_BUILDER(socketServerBindFailed, OT_EX_SOCKET_SERVER_BIND_FAILED, "Socket server bind failed")
00105 OT_EXCEPTION_BUILDER(socketServerSocketCreationError, OT_EX_SOCKET_SERVER_SOCKET_CREATION_ERROR, "Socket server socket creation error")
00106 OT_EXCEPTION_BUILDER(socketUtilityConnectionFailed, OT_EX_SOCKET_UTILITY_CONNECTION_FAILED, "Connection failed")
00107 OT_EXCEPTION_BUILDER(socketUtilityWritingError, OT_EX_SOCKET_UTILITY_WRITING_ERROR, "Socket writing error")
00108 OT_EXCEPTION_BUILDER(socketUtilityReadingError, OT_EX_SOCKET_UTILITY_READING_ERROR, "Socket reading error")
00109
00110 #endif