00001 #ifndef CASTOR_MESSAGES_H 00002 #define CASTOR_MESSAGES_H 1 00003 00004 #include <string> 00005 #include <boost/shared_ptr.hpp> 00006 00007 #include "Messages.h" 00008 #include "Encryption.h" 00009 #include "Authentication.h" 00010 #include "Encoding.h" 00011 #include "Identity.h" 00012 00013 using namespace castor::spica::security; 00014 00015 namespace castor { namespace spica { 00016 00017 class Container; 00018 class Message; 00019 00020 typedef boost::shared_ptr<Container> ContainerPtr; 00021 typedef boost::shared_ptr<Message> MessagePtr; 00022 00023 class Container { 00024 00025 protected: 00026 00027 bool modified; 00028 bool empty; 00029 00030 Identity id; 00031 00032 public: 00033 00034 Container() : modified(true), empty(true), id() { 00035 } 00036 00037 virtual ~Container() { 00038 } 00039 00040 bool isModified() { return this->modified; } 00041 void isModified(bool value) { this->modified = value; } 00042 void touch() { this->modified = true; } 00043 00044 bool isEmpty() { return this->empty; } 00045 void isEmpty(bool value) { this->empty = value; } 00046 00047 virtual std::string concept() = 0; 00048 virtual std::string rep() = 0; 00049 00050 virtual const Identity &identity() { return this->id; }; 00051 00052 virtual unsigned int messageType() = 0; 00053 virtual unsigned int messageType(castor::DecoderPtr dec) = 0; 00054 00055 virtual ContainerPtr hierarchyTop() = 0; 00056 00057 virtual void encode(castor::EncoderPtr enc) = 0; 00058 virtual void encodeHeader(castor::EncoderPtr enc) = 0; 00059 virtual void encodeBody(castor::EncoderPtr enc) = 0; 00060 00061 virtual void decode(castor::DecoderPtr dec) = 0; 00062 virtual void decodeHeader(castor::DecoderPtr dec) = 0; 00063 virtual void decodeBody(castor::DecoderPtr dec) = 0; 00064 00065 virtual ContainerPtr decodeAny(castor::DecoderPtr dec) = 0; 00066 00067 virtual ContainerPtr clone() = 0; 00068 00069 virtual void copyTo(ContainerPtr message) = 0; 00070 virtual void copyHeaderTo(ContainerPtr message) = 0; 00071 virtual void copyBodyTo(ContainerPtr message) = 0; 00072 00073 virtual std::string toString() = 0; 00074 00075 virtual void clear() = 0; 00076 00077 virtual std::string dump() = 0; 00078 00079 virtual int hashcode() const = 0; 00080 00081 virtual int compareTo(ContainerPtr other) const = 0; 00082 00083 template<typename T> 00084 bool equals(T other) { 00085 if (typeid(this) != typeid(other)) return false; 00086 return (this->compareTo(other) == 0); 00087 } 00088 }; 00089 00090 class Message : public Container { 00091 00092 protected: 00093 00094 AuthServicePtr authService; 00095 AuthResult authResult; 00096 00097 EncryptServicePtr encryptService; 00098 EncryptResult encryptResult; 00099 00100 int mtu; 00101 00102 public: 00103 00104 Message() : 00105 authService(), authResult(castor::spica::security::auth_unknown), 00106 encryptService(), encryptResult(castor::spica::security::enc_unknown), mtu(64000) 00107 { 00108 } 00109 00110 virtual ~Message() { 00111 } 00112 00113 virtual bool decodePart(castor::DecoderPtr dec) = 0; 00114 00115 virtual MessagePtr decodeAnyPart(castor::DecoderPtr dec) = 0; 00116 00117 virtual MessagePtr createInstance(unsigned int id) = 0; 00118 virtual MessagePtr createInstance(const std::string name) = 0; 00119 virtual MessagePtr createInstance(const std::string concept, const std::string rep) = 0; 00120 00121 virtual std::string typeToSemantic(unsigned int type) = 0; 00122 virtual std::vector<unsigned int> semanticToTypes(const std::string key) = 0; 00123 00124 // Authentication 00125 virtual bool isAuthSupported() = 0; 00126 virtual void authVerify() = 0; 00127 AuthResult getAuthResult() { return this->authResult; } 00128 AuthServicePtr getAuthService() { return this->authService; } 00129 void setAuthService(AuthServicePtr value) { this->authService = value; } 00130 00131 // Encryption 00132 virtual bool isEncryptSupported() = 0; 00133 EncryptResult getEncryptResult() { return this->encryptResult; } 00134 EncryptServicePtr getEncryptService() { return this->encryptService; } 00135 void setEncryptService(EncryptServicePtr value) { this->encryptService = value; } 00136 00137 // Framentation 00138 virtual bool isFragSupported() = 0; 00139 virtual int getFragmentId() = 0; 00140 virtual int getFragmentId(castor::DecoderPtr dec) = 0; 00141 int getMtu() { return this->mtu; } 00142 void setMtu(int value) { this->mtu = value; } 00143 }; 00144 00145 } } 00146 00147 #endif /* CASTOR_MESSAGES_H */ 00148