MqttMsgContext.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. Copyright (c) 2013, 2014 Paolo Patierno
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License v1.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. http://www.eclipse.org/legal/epl-v10.html
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. Contributors:
  11. Paolo Patierno - initial API and implementation and/or initial documentation
  12. */
  13. using System;
  14. using System.Text;
  15. namespace uPLibrary.Networking.M2Mqtt.Messages
  16. {
  17. /// <summary>
  18. /// Context for MQTT message
  19. /// </summary>
  20. public class MqttMsgContext
  21. {
  22. /// <summary>
  23. /// MQTT message
  24. /// </summary>
  25. public MqttMsgBase Message { get; set; }
  26. /// <summary>
  27. /// MQTT message state
  28. /// </summary>
  29. public MqttMsgState State { get; set; }
  30. /// <summary>
  31. /// Flow of the message
  32. /// </summary>
  33. public MqttMsgFlow Flow { get; set; }
  34. /// <summary>
  35. /// Timestamp in ticks (for retry)
  36. /// </summary>
  37. public int Timestamp { get; set; }
  38. /// <summary>
  39. /// Attempt (for retry)
  40. /// </summary>
  41. public int Attempt { get; set; }
  42. /// <summary>
  43. /// Unique key
  44. /// </summary>
  45. public string Key
  46. {
  47. get { return this.Flow + "_" + this.Message.MessageId; }
  48. }
  49. }
  50. /// <summary>
  51. /// Flow of the message
  52. /// </summary>
  53. public enum MqttMsgFlow
  54. {
  55. /// <summary>
  56. /// To publish to subscribers
  57. /// </summary>
  58. ToPublish,
  59. /// <summary>
  60. /// To acknowledge to publisher
  61. /// </summary>
  62. ToAcknowledge
  63. }
  64. /// <summary>
  65. /// MQTT message state
  66. /// </summary>
  67. public enum MqttMsgState
  68. {
  69. /// <summary>
  70. /// QOS = 0, Message queued
  71. /// </summary>
  72. QueuedQos0,
  73. /// <summary>
  74. /// QOS = 1, Message queued
  75. /// </summary>
  76. QueuedQos1,
  77. /// <summary>
  78. /// QOS = 2, Message queued
  79. /// </summary>
  80. QueuedQos2,
  81. /// <summary>
  82. /// QOS = 1, PUBLISH sent, wait for PUBACK
  83. /// </summary>
  84. WaitForPuback,
  85. /// <summary>
  86. /// QOS = 2, PUBLISH sent, wait for PUBREC
  87. /// </summary>
  88. WaitForPubrec,
  89. /// <summary>
  90. /// QOS = 2, PUBREC sent, wait for PUBREL
  91. /// </summary>
  92. WaitForPubrel,
  93. /// <summary>
  94. /// QOS = 2, PUBREL sent, wait for PUBCOMP
  95. /// </summary>
  96. WaitForPubcomp,
  97. /// <summary>
  98. /// QOS = 2, start first phase handshake send PUBREC
  99. /// </summary>
  100. SendPubrec,
  101. /// <summary>
  102. /// QOS = 2, start second phase handshake send PUBREL
  103. /// </summary>
  104. SendPubrel,
  105. /// <summary>
  106. /// QOS = 2, end second phase handshake send PUBCOMP
  107. /// </summary>
  108. SendPubcomp,
  109. /// <summary>
  110. /// QOS = 1, PUBLISH received, send PUBACK
  111. /// </summary>
  112. SendPuback,
  113. // [v3.1.1] SUBSCRIBE isn't "officially" QOS = 1
  114. /// <summary>
  115. /// Send SUBSCRIBE message
  116. /// </summary>
  117. SendSubscribe,
  118. // [v3.1.1] UNSUBSCRIBE isn't "officially" QOS = 1
  119. /// <summary>
  120. /// Send UNSUBSCRIBE message
  121. /// </summary>
  122. SendUnsubscribe,
  123. /// <summary>
  124. /// (QOS = 1), SUBSCRIBE sent, wait for SUBACK
  125. /// </summary>
  126. WaitForSuback,
  127. /// <summary>
  128. /// (QOS = 1), UNSUBSCRIBE sent, wait for UNSUBACK
  129. /// </summary>
  130. WaitForUnsuback
  131. }
  132. }