1 /*-----------------------------------------------------------------------------
  2 Name:      MessageUnit.h
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   Holding a message
  6 -----------------------------------------------------------------------------*/
  7 
  8 #ifndef _UTIL_MESSAGEUNIT_H
  9 #define _UTIL_MESSAGEUNIT_H
 10  
 11 #include <string>
 12 #include <vector>
 13 #include <client/qos/PublishQos.h>
 14 #include <client/key/PublishKey.h>
 15 #include <util/qos/QosData.h>
 16 #include <util/key/KeyData.h>
 17 
 18 
 19 
 20 
 21 namespace org { namespace xmlBlaster { namespace util {
 22    
 23 /**
 24  * Holding a message. 
 25  * <p />
 26  * This class corresponds to the CORBA serverIdl::MessageUnit struct
 27  * but uses standard STL only.
 28  * @since 0.79e
 29  * @author xmlBlaster@marcelruff.info
 30  * @author laghi@swissinfo.org
 31  */
 32 class Dll_Export MessageUnit 
 33 {
 34 
 35    private:
 36       std::string me() {
 37          return "MessageUnit";
 38       }
 39 
 40       org::xmlBlaster::util::key::KeyDataRef key_;
 41 
 42       //std::vector<unsigned char> contentVec_;
 43       unsigned long len_;
 44       unsigned char *content_;
 45 
 46       org::xmlBlaster::util::qos::QosDataRef qos_;
 47 
 48       /** Remembers the size of this message, needed e.g. for persistent storage calculation */
 49       mutable size_t immutableSizeInBytes_;
 50 
 51    public:
 52       /**
 53        * Constructs with a 'char *' and its length 'len'. 
 54        */
 55       MessageUnit(const org::xmlBlaster::util::key::KeyData &key,
 56                   unsigned long len,
 57                   const unsigned char * content, 
 58                   const org::xmlBlaster::util::qos::QosData &qos);
 59 
 60       /**
 61        * Constructs a MessageUnit with a std::string. 
 62        */
 63       MessageUnit(const org::xmlBlaster::util::key::KeyData &key,
 64                   const std::string &content, 
 65                   const org::xmlBlaster::util::qos::QosData &qos);
 66 
 67       /**
 68        * Constructs a MessageUnit with a std::string and a org::xmlBlaster::client::qos::PublishQos object
 69        */
 70       MessageUnit(const org::xmlBlaster::client::key::PublishKey& xmlKey,
 71                   const std::string &content, 
 72                   org::xmlBlaster::client::qos::PublishQos& publishQos);
 73 
 74       /**
 75        * Constructs the message unit. 
 76        */
 77       MessageUnit(const org::xmlBlaster::util::key::KeyData &xmlKey,
 78                   const std::vector<unsigned char> &contentVec, 
 79                   const org::xmlBlaster::util::qos::QosData &qos);
 80 
 81       /**
 82        * Constructs the message unit by taking a org::xmlBlaster::client::qos::PublishQos object.
 83        */
 84       MessageUnit(const org::xmlBlaster::client::key::PublishKey &xmlKey,
 85                   const std::vector<unsigned char> &contentVec, 
 86                   org::xmlBlaster::client::qos::PublishQos& publishQos);
 87 
 88       /**
 89        * Copy constructor. 
 90        * <p />
 91        * The content is cloned but the KeyData and QosData is referenced.
 92        */
 93       MessageUnit(const MessageUnit& rhs);
 94 
 95       /**
 96        * Assignment constructor
 97        * <p />
 98        * The content is cloned but the KeyData and QosData is referenced.
 99        */
100       MessageUnit& operator=(const MessageUnit& rhs);
101 
102       /**
103        * Destructor
104        */
105       virtual ~MessageUnit();
106 
107       /**
108        * @return The xml based key, reference counted
109        */
110       const org::xmlBlaster::util::key::KeyDataRef getKeyRef() const;
111 
112       /**
113        * The life cycle of the returned object is limited to this MessageUnit. 
114        * @return The xml based key
115        */
116       const org::xmlBlaster::util::key::KeyData& getKey() const;
117 
118       /**
119        * @return The user data carried with this message
120        *         This is created for each invocation so 
121        *         use it sparingly
122        */
123       std::vector<unsigned char> getContentVec() const;
124 
125       /**
126        * Access the raw user data,
127        * use getContentLen() to access the length
128        */
129       const unsigned char *getContent() const {
130          return content_;
131       }
132 
133       /**
134        * Access the length of the raw user data
135        */
136       unsigned long getContentLen() const {
137          return len_;
138       }
139 
140       /**
141        * @return The user data carried with this message as a std::string
142        */
143       std::string getContentStr() const;
144 
145       /**
146        * @return The xml based QoS, reference counted
147        */
148       const org::xmlBlaster::util::qos::QosDataRef getQosRef() const;
149 
150       /**
151        * The life cycle of the returned object is limited to this MessageUnit. 
152        * @return The quality of service of this message. 
153        */
154       const org::xmlBlaster::util::qos::QosData& getQos() const;
155 
156       /**
157        * Get the immutable size of this message. 
158        */
159       size_t getSizeInBytes() const;
160 
161       /**
162        * Dump state of this object into a XML ASCII std::string.
163        * <br>
164        * @param extraOffset indenting of tags for nice output
165        * @return The MessageUnit as a XML ASCII std::string
166        */
167       std::string toXml(const std::string &extraOffset="") const;
168 };
169 }}} // namespace
170 
171 #endif


syntax highlighted by Code2HTML, v. 0.9.1