00001 #ifndef __ARC_MESSAGE_H__
00002 #define __ARC_MESSAGE_H__
00003
00004 #include <stdlib.h>
00005
00006 #include "MessageAttributes.h"
00007 #include "MessageAuth.h"
00008
00009 namespace Arc {
00010
00012
00014 class MessagePayload {
00015 public:
00016 virtual ~MessagePayload(void) { };
00017 };
00018
00020
00022 class MessageContextElement {
00023 public:
00024 MessageContextElement(void) { };
00025 virtual ~MessageContextElement(void) { };
00026 };
00027
00029
00032 class MessageContext {
00033 private:
00034 std::map<std::string,MessageContextElement*> elements_;
00035 public:
00036 MessageContext(void);
00037 ~MessageContext(void);
00040 void Add(const std::string& name,MessageContextElement* element);
00041 MessageContextElement* operator[](const std::string& id);
00042 };
00043
00045
00048 class MessageAuthContext: public MessageAuth {
00049 public:
00050 MessageAuthContext(void) { };
00051 ~MessageAuthContext(void) { };
00052 };
00053
00055
00088 class Message {
00089 private:
00090 MessagePayload* payload_;
00091 MessageAuth* auth_;
00092 bool auth_created_;
00093 MessageAttributes* attr_;
00094 bool attr_created_;
00101 MessageContext* ctx_;
00102 bool ctx_created_;
00103 MessageAuthContext* auth_ctx_;
00104 bool auth_ctx_created_;
00105 public:
00107 Message(void):payload_(NULL),auth_(NULL),auth_created_(false),attr_(NULL),attr_created_(false),ctx_(NULL),ctx_created_(false),auth_ctx_(NULL),auth_ctx_created_(false) { };
00109 Message(Message& msg):payload_(msg.payload_),auth_(msg.auth_),auth_created_(false),attr_(msg.attr_),attr_created_(false),ctx_(msg.ctx_),ctx_created_(false),auth_ctx_(msg.auth_ctx_),auth_ctx_created_(false) { };
00111 Message(long msg_ptr_addr);
00113 ~Message(void) {
00114 if(attr_created_) delete attr_;
00115 if(auth_created_) delete auth_;
00116 if(ctx_created_) delete ctx_;
00117 if(auth_ctx_created_) delete auth_ctx_;
00118 };
00120 Message& operator=(Message& msg) {
00121 payload_=msg.payload_;
00122 if(msg.auth_) Auth(msg.auth_);
00123 if(msg.attr_) Attributes(msg.attr_);
00124 if(msg.ctx_) Context(msg.ctx_);
00125 if(msg.auth_ctx_) AuthContext(msg.auth_ctx_);
00126 return *this;
00127 };
00129 MessagePayload* Payload(void) { return payload_; };
00131 MessagePayload* Payload(MessagePayload* payload) {
00132 MessagePayload* p = payload_;
00133 payload_=payload;
00134 return p;
00135 };
00138 MessageAttributes* Attributes(void) {
00139 if(attr_ == NULL) {
00140 attr_created_=true; attr_=new MessageAttributes;
00141 };
00142 return attr_;
00143 };
00144 void Attributes(MessageAttributes* attr) {
00145 if(attr_created_) {
00146 attr_created_=false; delete attr_;
00147 };
00148 attr_=attr;
00149 };
00152 MessageAuth* Auth(void) {
00153 if(auth_ == NULL) {
00154 auth_created_=true; auth_=new MessageAuth;
00155 };
00156 return auth_;
00157 };
00158 void Auth(MessageAuth* auth) {
00159 if(auth_created_) {
00160 auth_created_=false; delete auth_;
00161 };
00162 auth_=auth;
00163 };
00167 MessageContext* Context(void) {
00168 if(ctx_ == NULL) {
00169 ctx_created_=true; ctx_=new MessageContext;
00170 };
00171 return ctx_;
00172 };
00175 MessageAuthContext* AuthContext(void) {
00176 if(auth_ctx_ == NULL) {
00177 auth_ctx_created_=true; auth_ctx_=new MessageAuthContext;
00178 };
00179 return auth_ctx_;
00180 };
00182 void Context(MessageContext* ctx) {
00183 if(ctx_created_) {
00184 ctx_created_=false; delete ctx_;
00185 };
00186 ctx_=ctx;
00187 };
00189 void AuthContext(MessageAuthContext* auth_ctx) {
00190 if(auth_ctx_created_) {
00191 auth_ctx_created_=false; delete auth_ctx_;
00192 };
00193 auth_ctx_=auth_ctx;
00194 };
00195 };
00196
00197 }
00198
00199 #endif
00200