1 /*------------------------------------------------------------------------------
  2 Name:      StatusQosData.cpp
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 
  7 /**
  8  * Data container handling of status returned by subscribe(), unSubscribe(), erase() and ping(). 
  9  * <p>
 10  * This data holder is accessible through decorators, each of them allowing a specialized view on the data:
 11  * </p>
 12  * <ul>
 13  * <li>SubscribeReturnQos Returned QoS of a subscribe() invocation (Client side)</i>
 14  * <li>UnSubscribeReturnQos Returned QoS of a unSubscribe() invocation (Client side)</i>
 15  * <li>EraseReturnQos Returned QoS of an erase() invocation (Client side)</i>
 16  * </ul>
 17  * <p>
 18  * For the xml representation see StatusQosSaxFactory.
 19  * </p>
 20  * @see org.xmlBlaster.util.qos.StatusQosSaxFactory
 21  * @see org.xmlBlaster.test.classtest.qos.StatusQosFactoryTest
 22  * @author xmlBlaster@marcelruff.info
 23  * @author michele@laghi.eu
 24  */
 25 
 26 #include <util/qos/StatusQosData.h>
 27 #include <util/Global.h>
 28 // #include <lexical_cast.hpp>
 29 // 
 30 
 31 using namespace org::xmlBlaster::util;
 32 using namespace std;
 33 
 34 namespace org { namespace xmlBlaster { namespace util { namespace qos {
 35 
 36 void StatusQosData::copy(const StatusQosData& data)
 37 {
 38    state_          = data.state_;
 39    stateInfo_      = data.stateInfo_;
 40    subscriptionId_ = data.subscriptionId_;
 41    keyOid_         = data.keyOid_;
 42    rcvTimestamp_   = data.rcvTimestamp_;
 43    persistent_     = data.persistent_;
 44 }
 45 
 46 StatusQosData::StatusQosData(Global& global)
 47    : ME("StatusQosData"), global_(global)
 48 {
 49    state_ = Constants::STATE_OK;
 50    rcvTimestamp_ = 0;
 51    persistent_ = false;
 52 }
 53 
 54 StatusQosData::StatusQosData(const StatusQosData& data)
 55   : ME(data.ME), global_(data.global_)
 56 {
 57    copy(data);
 58 }
 59 
 60 StatusQosData StatusQosData::operator =(const StatusQosData& data)
 61 {
 62    copy(data);
 63    return *this;
 64 }
 65 
 66 void StatusQosData::setState(const string& state)
 67 {
 68    state_ = state;
 69 }
 70 
 71 string StatusQosData::getState() const
 72 {
 73    return state_;
 74 }
 75 
 76 bool StatusQosData::isOk() const
 77 {
 78    return Constants::STATE_OK == state_;
 79 }
 80 
 81 bool StatusQosData::isErased() const
 82 {
 83    return Constants::STATE_ERASED == state_;
 84 }
 85 
 86 bool StatusQosData::isTimeout() const
 87 {
 88    return Constants::STATE_TIMEOUT == state_;
 89 }
 90 
 91 bool StatusQosData::isForwardError() const
 92 {
 93    return Constants::STATE_FORWARD_ERROR == state_;
 94 }
 95 
 96 void StatusQosData::setStateInfo(const string& stateInfo)
 97 {
 98    stateInfo_ = stateInfo;
 99 }
100 
101 string StatusQosData::getStateInfo() const
102 {
103    return stateInfo_;
104 }
105 
106 void StatusQosData::setSubscriptionId(const string& subscriptionId)
107 {
108    subscriptionId_ = subscriptionId;
109 }
110 
111 string StatusQosData::getSubscriptionId() const
112 {
113    return subscriptionId_;
114 }
115 
116 string StatusQosData::getKeyOid() const
117 {
118    return keyOid_;
119 }
120 
121 void StatusQosData::setKeyOid(const string& oid)
122 {
123    keyOid_ = oid;
124 }
125 
126 int StatusQosData::size() const
127 {
128    return (int)toXml().length();
129 }
130 
131 string StatusQosData::toXml(const string& extraOffset) const
132 {
133    string ret;
134    string offset = Constants::OFFSET + extraOffset;
135 
136    ret += offset + "<qos>"; // <!-- SubscribeRetQos -->");
137    if (!isOk() || !getStateInfo().empty()) {
138       ret += offset + " <state id='" + getState();
139       if (!getStateInfo().empty())
140          ret += "' info='" + getStateInfo();
141       ret += "'/>";
142    }
143    if (!getSubscriptionId().empty())
144       ret += offset + " <subscribe id='" + getSubscriptionId() + "'/>";
145    if (!getKeyOid().empty())
146       ret += offset + " <key oid='" + getKeyOid() + "'/>";
147    ret += offset + "</qos>";
148    if (isPersistent())
149       ret += offset + " <persistent/>";
150 
151    if (ret.length() < 16)
152       return "<qos/>";  // minimal footprint
153 
154    return ret;
155 }
156 
157 void StatusQosData::setRcvTimestamp(Timestamp rcvTimestamp)
158 {
159    rcvTimestamp_ = rcvTimestamp;
160 }
161 
162 Timestamp StatusQosData::getRcvTimestamp() const
163 {
164    return rcvTimestamp_;
165 }
166 
167 void StatusQosData::touchRcvTimestamp()
168 {
169    rcvTimestamp_ = TimestampFactory::getInstance().getTimestamp();
170 }
171 
172 /**
173  * @param persistent mark a message as persistent
174  */
175 void StatusQosData::setPersistent(bool persistent)
176 {
177    persistent_ = persistent;
178 }
179 
180 /**
181  * @return true/false
182  */
183 bool StatusQosData::isPersistent() const
184 {
185    return persistent_;
186 }
187 
188 }}}} // namespace


syntax highlighted by Code2HTML, v. 0.9.1