1 /*------------------------------------------------------------------------------
  2 Name:      SubscribeQueueEntry.cpp
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 
  7 #include <util/queue/SubscribeQueueEntry.h>
  8 #include <util/dispatch/I_ConnectionsHandler.h>
  9 #include <cstring> // memset()
 10 
 11 namespace org { namespace xmlBlaster { namespace util { namespace queue {
 12 
 13 using namespace std;
 14 using namespace org::xmlBlaster::util::dispatch;
 15 using namespace org::xmlBlaster::util::qos;
 16 using namespace org::xmlBlaster::util::key;
 17 using namespace org::xmlBlaster::client::qos;
 18 using namespace org::xmlBlaster::client::key;
 19 
 20 SubscribeQueueEntry::SubscribeQueueEntry(Global& global, const SubscribeKey& subscribeKey,
 21      const SubscribeQos& subscribeQos, int priority, Timestamp uniqueId)
 22    : MsgQueueEntry(global, subscribeKey.getData(), subscribeQos.getData(), 
 23      org::xmlBlaster::util::Constants::ENTRY_TYPE_MSG_RAW + "|" + org::xmlBlaster::util::MethodName::SUBSCRIBE,
 24      priority,
 25      false, // subscribeQos.getData().isPersistent(), TODO: first implement retrieval before we can put it in !!!
 26      uniqueId)
 27 {
 28    ME = "SubscribeQueueEntry";
 29 }
 30 
 31 SubscribeQueueEntry::~SubscribeQueueEntry() {
 32 }
 33 
 34 /** copy constructor */
 35 SubscribeQueueEntry::SubscribeQueueEntry(const SubscribeQueueEntry& rhs)
 36     //: MsgQueueEntry((MsgQueueEntry)rhs)
 37     : MsgQueueEntry(rhs.getGlobal(), rhs.getMsgUnit(), rhs.getEmbeddedType(), rhs.getPriority(), rhs.isPersistent(), rhs.getUniqueId())
 38 {
 39    memset(&blobHolder_, 0, sizeof(BlobHolder)); // reset cache
 40 }
 41 
 42 /** assignment constructor */
 43 SubscribeQueueEntry& SubscribeQueueEntry::operator=(const SubscribeQueueEntry& rhs)
 44 {
 45    if (this == &rhs)
 46       return *this;
 47    memset(&blobHolder_, 0, sizeof(BlobHolder)); // reset cache
 48    return *this;
 49 }
 50 
 51 MsgQueueEntry *SubscribeQueueEntry::getClone() const
 52 {
 53    return new SubscribeQueueEntry(*this);
 54 }
 55 
 56 bool SubscribeQueueEntry::isSubscribe() const {
 57         return true;
 58 }
 59 
 60 // this should actually be in another interface but since it is an only method we put it here.
 61 const MsgQueueEntry& SubscribeQueueEntry::send(I_ConnectionsHandler& connectionsHandler) const
 62 {
 63    if (log_.call()) log_.call(ME, "send");
 64    if (statusQosData_) {
 65       delete statusQosData_;
 66       statusQosData_ = NULL;
 67    }
 68    if (log_.dump()) log_.dump(ME, string("send: ") + SubscribeQueueEntry::toXml());
 69    statusQosData_ = new StatusQosData(
 70         connectionsHandler.getConnection().subscribe(
 71             getSubscribeKey(), getSubscribeQos()).getData());
 72    return *this;
 73 }
 74 
 75 SubscribeQos SubscribeQueueEntry::getSubscribeQos() const
 76 {
 77    const QueryQosData *qos = dynamic_cast<const QueryQosData *>(&msgUnit_->getQos());
 78    return SubscribeQos(global_, *qos);
 79 }
 80 
 81 SubscribeKey SubscribeQueueEntry::getSubscribeKey() const
 82 {
 83    const QueryKeyData *key = dynamic_cast<const QueryKeyData *>(&msgUnit_->getKey());
 84    return SubscribeKey(global_, *key);
 85 }
 86 
 87 SubscribeReturnQos SubscribeQueueEntry::getSubscribeReturnQos() const
 88 {
 89    return SubscribeReturnQos(global_, *statusQosData_);
 90 }
 91 
 92 string SubscribeQueueEntry::toXml(const string& indent) const
 93 {
 94    string extraOffset = "   " + indent;
 95    string ret = indent + "<subscribeQueueEntry>\n";
 96    if (msgUnit_) {
 97       ret += extraOffset + msgUnit_->toXml(indent);
 98    }
 99    ret += indent + "</subscribeQueueEntry>\n";
100    return ret;
101 }
102 
103 
104 }}}} // namespace


syntax highlighted by Code2HTML, v. 0.9.1