qmqtt_message.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * qmqtt_message.cpp - qmqtt message
  3. *
  4. * Copyright (c) 2013 Ery Lee <ery.lee at gmail dot com>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * * Neither the name of mqttc nor the names of its contributors may be used
  16. * to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. */
  32. #include "qmqtt_message.h"
  33. #include "qmqtt_message_p.h"
  34. namespace QMQTT {
  35. Message::Message()
  36. : d(new MessagePrivate)
  37. {
  38. }
  39. Message::Message(const quint16 id, const QString &topic, const QByteArray &payload,
  40. const quint8 qos, const bool retain, const bool dup)
  41. : d(new MessagePrivate(id, topic, payload, qos, retain, dup))
  42. {
  43. }
  44. Message::Message(const Message &other)
  45. : d(other.d)
  46. {
  47. }
  48. Message::~Message()
  49. {
  50. }
  51. Message &Message::operator=(const Message &other)
  52. {
  53. d = other.d;
  54. return *this;
  55. }
  56. bool Message::operator==(const Message &other) const
  57. {
  58. if (d == other.d)
  59. return true;
  60. return d->id == other.d->id
  61. && d->qos == other.d->qos
  62. && d->retain == other.d->retain
  63. && d->dup == other.d->dup
  64. && d->topic == other.d->topic
  65. && d->payload == other.d->payload;
  66. }
  67. quint16 Message::id() const
  68. {
  69. return d->id;
  70. }
  71. void Message::setId(const quint16 id)
  72. {
  73. d->id = id;
  74. }
  75. quint8 Message::qos() const
  76. {
  77. return d->qos;
  78. }
  79. void Message::setQos(const quint8 qos)
  80. {
  81. d->qos = qos;
  82. }
  83. bool Message::retain() const
  84. {
  85. return d->retain;
  86. }
  87. void Message::setRetain(const bool retain)
  88. {
  89. d->retain = retain;
  90. }
  91. bool Message::dup() const
  92. {
  93. return d->dup;
  94. }
  95. void Message::setDup(const bool dup)
  96. {
  97. d->dup = dup;
  98. }
  99. QString Message::topic() const
  100. {
  101. return d->topic;
  102. }
  103. void Message::setTopic(const QString &topic)
  104. {
  105. d->topic = topic;
  106. }
  107. QByteArray Message::payload() const
  108. {
  109. return d->payload;
  110. }
  111. void Message::setPayload(const QByteArray &payload)
  112. {
  113. d->payload = payload;
  114. }
  115. } // namespace QMQTT