util/qos/StatusQosData.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      StatusQosData.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00026 #include <util/qos/StatusQosData.h>
00027 #include <util/Global.h>
00028 // #include <lexical_cast.hpp>
00029 // 
00030 
00031 using namespace org::xmlBlaster::util;
00032 using namespace std;
00033 
00034 namespace org { namespace xmlBlaster { namespace util { namespace qos {
00035 
00036 void StatusQosData::copy(const StatusQosData& data)
00037 {
00038    state_          = data.state_;
00039    stateInfo_      = data.stateInfo_;
00040    subscriptionId_ = data.subscriptionId_;
00041    keyOid_         = data.keyOid_;
00042    rcvTimestamp_   = data.rcvTimestamp_;
00043    persistent_     = data.persistent_;
00044 }
00045 
00046 StatusQosData::StatusQosData(Global& global)
00047    : ME("StatusQosData"), global_(global)
00048 {
00049    state_ = Constants::STATE_OK;
00050    rcvTimestamp_ = 0;
00051    persistent_ = false;
00052 }
00053 
00054 StatusQosData::StatusQosData(const StatusQosData& data)
00055   : ME(data.ME), global_(data.global_)
00056 {
00057    copy(data);
00058 }
00059 
00060 StatusQosData StatusQosData::operator =(const StatusQosData& data)
00061 {
00062    copy(data);
00063    return *this;
00064 }
00065 
00066 void StatusQosData::setState(const string& state)
00067 {
00068    state_ = state;
00069 }
00070 
00071 string StatusQosData::getState() const
00072 {
00073    return state_;
00074 }
00075 
00076 bool StatusQosData::isOk() const
00077 {
00078    return Constants::STATE_OK == state_;
00079 }
00080 
00081 bool StatusQosData::isErased() const
00082 {
00083    return Constants::STATE_ERASED == state_;
00084 }
00085 
00086 bool StatusQosData::isTimeout() const
00087 {
00088    return Constants::STATE_TIMEOUT == state_;
00089 }
00090 
00091 bool StatusQosData::isForwardError() const
00092 {
00093    return Constants::STATE_FORWARD_ERROR == state_;
00094 }
00095 
00096 void StatusQosData::setStateInfo(const string& stateInfo)
00097 {
00098    stateInfo_ = stateInfo;
00099 }
00100 
00101 string StatusQosData::getStateInfo() const
00102 {
00103    return stateInfo_;
00104 }
00105 
00106 void StatusQosData::setSubscriptionId(const string& subscriptionId)
00107 {
00108    subscriptionId_ = subscriptionId;
00109 }
00110 
00111 string StatusQosData::getSubscriptionId() const
00112 {
00113    return subscriptionId_;
00114 }
00115 
00116 string StatusQosData::getKeyOid() const
00117 {
00118    return keyOid_;
00119 }
00120 
00121 void StatusQosData::setKeyOid(const string& oid)
00122 {
00123    keyOid_ = oid;
00124 }
00125 
00126 int StatusQosData::size() const
00127 {
00128    return (int)toXml().length();
00129 }
00130 
00131 string StatusQosData::toXml(const string& extraOffset) const
00132 {
00133    string ret;
00134    string offset = Constants::OFFSET + extraOffset;
00135 
00136    ret += offset + "<qos>"; // <!-- SubscribeRetQos -->");
00137    if (!isOk() || !getStateInfo().empty()) {
00138       ret += offset + " <state id='" + getState();
00139       if (!getStateInfo().empty())
00140          ret += "' info='" + getStateInfo();
00141       ret += "'/>";
00142    }
00143    if (!getSubscriptionId().empty())
00144       ret += offset + " <subscribe id='" + getSubscriptionId() + "'/>";
00145    if (!getKeyOid().empty())
00146       ret += offset + " <key oid='" + getKeyOid() + "'/>";
00147    ret += offset + "</qos>";
00148    if (isPersistent())
00149       ret += offset + " <persistent/>";
00150 
00151    if (ret.length() < 16)
00152       return "<qos/>";  // minimal footprint
00153 
00154    return ret;
00155 }
00156 
00157 void StatusQosData::setRcvTimestamp(Timestamp rcvTimestamp)
00158 {
00159    rcvTimestamp_ = rcvTimestamp;
00160 }
00161 
00162 Timestamp StatusQosData::getRcvTimestamp() const
00163 {
00164    return rcvTimestamp_;
00165 }
00166 
00167 void StatusQosData::touchRcvTimestamp()
00168 {
00169    rcvTimestamp_ = TimestampFactory::getInstance().getTimestamp();
00170 }
00171 
00175 void StatusQosData::setPersistent(bool persistent)
00176 {
00177    persistent_ = persistent;
00178 }
00179 
00183 bool StatusQosData::isPersistent() const
00184 {
00185    return persistent_;
00186 }
00187 
00188 }}}} // namespace